Rename Witnesses to include sprout or sapling

This commit is contained in:
Eirik Ogilvie-Wigley
2018-08-01 10:41:36 -06:00
parent 4fc309f0f5
commit 8ea8ef9850
14 changed files with 66 additions and 66 deletions

View File

@@ -342,7 +342,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
JSOutPoint jso = std::get<0>(t);
std::vector<JSOutPoint> vOutPoints = {jso};
uint256 inputAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor};
}
@@ -406,7 +406,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
CAmount jsInputValue = 0;
uint256 jsAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
JSDescription prevJoinSplit;
@@ -437,7 +437,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
}
assert(changeOutputIndex != -1);
boost::optional<ZCIncrementalWitness> changeWitness;
boost::optional<SproutWitness> changeWitness;
int n = 0;
for (const uint256& commitment : prevJoinSplit.commitments) {
tree.append(commitment);
@@ -487,7 +487,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
std::vector<SproutNote> vInputNotes;
std::vector<SproutSpendingKey> vInputZKeys;
std::vector<JSOutPoint> vOutPoints;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
uint256 inputAnchor;
int numInputsNeeded = (jsChange > 0) ? 1 : 0;
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
@@ -544,7 +544,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
}
ZCIncrementalWitness w = *optionalWitness; // could use .get();
SproutWitness w = *optionalWitness; // could use .get();
if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) {
w.append(commitment);
@@ -695,7 +695,7 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj)
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info)
{
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor;
{
LOCK(cs_main);
@@ -707,7 +707,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& outPoints)
{
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor;
{
LOCK(cs_main);
@@ -718,7 +718,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor)
{
if (anchor.IsNull()) {

View File

@@ -45,7 +45,7 @@ struct MergeToAddressJSInfo {
// A struct to help us track the witness and anchor for a given JSOutPoint
struct MergeToAddressWitnessAnchorData {
boost::optional<ZCIncrementalWitness> witness;
boost::optional<SproutWitness> witness;
uint256 anchor;
};
@@ -112,7 +112,7 @@ private:
// JoinSplit where you have the witnesses and anchor
UniValue perform_joinsplit(
MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor);
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
@@ -172,7 +172,7 @@ public:
UniValue perform_joinsplit(
MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor)
{
return delegate->perform_joinsplit(info, witnesses, anchor);

View File

@@ -419,7 +419,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
JSOutPoint jso = std::get<0>(t);
std::vector<JSOutPoint> vOutPoints = { jso };
uint256 inputAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor };
}
@@ -526,7 +526,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
CAmount jsInputValue = 0;
uint256 jsAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
JSDescription prevJoinSplit;
@@ -557,7 +557,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
}
assert(changeOutputIndex != -1);
boost::optional<ZCIncrementalWitness> changeWitness;
boost::optional<SproutWitness> changeWitness;
int n = 0;
for (const uint256& commitment : prevJoinSplit.commitments) {
tree.append(commitment);
@@ -606,7 +606,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
//
std::vector<SproutNote> vInputNotes;
std::vector<JSOutPoint> vOutPoints;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
uint256 inputAnchor;
int numInputsNeeded = (jsChange>0) ? 1 : 0;
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
@@ -663,7 +663,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
}
ZCIncrementalWitness w = *optionalWitness; // could use .get();
SproutWitness w = *optionalWitness; // could use .get();
if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) {
w.append(commitment);
@@ -920,7 +920,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
}
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor;
{
LOCK(cs_main);
@@ -931,7 +931,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor;
{
LOCK(cs_main);
@@ -942,7 +942,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor)
{
if (anchor.IsNull()) {

View File

@@ -45,7 +45,7 @@ struct AsyncJoinSplitInfo
// A struct to help us track the witness and anchor for a given JSOutPoint
struct WitnessAnchorData {
boost::optional<ZCIncrementalWitness> witness;
boost::optional<SproutWitness> witness;
uint256 anchor;
};
@@ -112,7 +112,7 @@ private:
// JoinSplit where you have the witnesses and anchor
UniValue perform_joinsplit(
AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor);
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
@@ -173,7 +173,7 @@ public:
UniValue perform_joinsplit(
AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor)
{
return delegate->perform_joinsplit(info, witnesses, anchor);

View File

@@ -120,8 +120,8 @@ std::pair<JSOutPoint, SaplingOutPoint> CreateValidBlock(TestWallet& wallet,
std::pair<uint256, uint256> GetWitnessesAndAnchors(TestWallet& wallet,
std::vector<JSOutPoint>& sproutNotes,
std::vector<SaplingOutPoint>& saplingNotes,
std::vector<boost::optional<ZCIncrementalWitness>>& sproutWitnesses,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& saplingWitnesses) {
std::vector<boost::optional<SproutWitness>>& sproutWitnesses,
std::vector<boost::optional<SaplingWitness>>& saplingWitnesses) {
sproutWitnesses.clear();
saplingWitnesses.clear();
uint256 sproutAnchor;
@@ -585,8 +585,8 @@ TEST(wallet_tests, cached_witnesses_empty_chain) {
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
@@ -639,8 +639,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
// Called to fetch anchor
std::vector<JSOutPoint> sproutNotes {outpts.first};
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
EXPECT_NE(anchors1.first, anchors1.second);
@@ -661,8 +661,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
@@ -709,8 +709,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
// Incrementing with the same block again should not change the cache
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree);
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses5;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses5;
std::vector<boost::optional<SproutWitness>> sproutWitnesses5;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses5;
auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5);
EXPECT_NE(anchors5.first, anchors5.second);
@@ -750,8 +750,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
// Called to fetch anchor
std::vector<JSOutPoint> sproutNotes {outpts.first};
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
}
@@ -770,8 +770,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
@@ -814,8 +814,8 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) {
SproutMerkleTree sproutRiTree = sproutTree;
SaplingMerkleTree saplingTree;
SaplingMerkleTree saplingRiTree = saplingTree;
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
@@ -922,8 +922,8 @@ TEST(wallet_tests, ClearNoteWitnessCache) {
wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
// Before clearing, we should have a witness for one note
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);

View File

@@ -2843,7 +2843,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
SproutNote decrypted_note = npt.note(payment_addr);
assert(pwalletMain != NULL);
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor;
uint256 commitment = decrypted_note.cm();
pwalletMain->WitnessNoteCommitment(
@@ -2944,7 +2944,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
}
uint256 anchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
std::vector<boost::optional<SproutWitness>> witnesses;
pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor);
assert(witnesses.size() == notes.size());

View File

@@ -1470,7 +1470,7 @@ bool CWallet::IsFromMe(const uint256& nullifier) const
}
void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor)
{
LOCK(cs_wallet);
@@ -1497,7 +1497,7 @@ void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
}
void CWallet::GetSaplingNoteWitnesses(std::vector<SaplingOutPoint> notes,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses,
std::vector<boost::optional<SaplingWitness>>& witnesses,
uint256 &final_anchor)
{
LOCK(cs_wallet);
@@ -1888,7 +1888,7 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
}
void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor)
{
witnesses.resize(commitments.size());
@@ -1907,7 +1907,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
{
tree.append(note_commitment);
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) {
BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
if (wit) {
wit->append(note_commitment);
}
@@ -1937,7 +1937,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
// TODO: #93; Select a root via some heuristic.
final_anchor = tree.root();
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) {
BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
if (wit) {
assert(final_anchor == wit->root());
}

View File

@@ -220,7 +220,7 @@ public:
* Cached incremental witnesses for spendable Notes.
* Beginning of the list is the most recent witness.
*/
std::list<ZCIncrementalWitness> witnesses;
std::list<SproutWitness> witnesses;
/**
* Block height corresponding to the most current witness.
@@ -272,7 +272,7 @@ public:
*/
SaplingNoteData() : witnessHeight {-1} { }
std::list<ZCSaplingIncrementalWitness> witnesses;
std::list<SaplingWitness> witnesses;
int witnessHeight;
};
@@ -1033,7 +1033,7 @@ public:
void EraseFromWallet(const uint256 &hash);
void WitnessNoteCommitment(
std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor);
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions();
@@ -1077,11 +1077,11 @@ public:
bool IsFromMe(const uint256& nullifier) const;
void GetSproutNoteWitnesses(
std::vector<JSOutPoint> notes,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor);
void GetSaplingNoteWitnesses(
std::vector<SaplingOutPoint> notes,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses,
std::vector<boost::optional<SaplingWitness>>& witnesses,
uint256 &final_anchor);
isminetype IsMine(const CTxIn& txin) const;