diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f26c8bba7..9218c1ace 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -853,6 +853,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, LOCK(cs_wallet); for (std::pair& wtxItem : mapWallet) { ::CopyPreviousWitnesses(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize); + ::CopyPreviousWitnesses(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize); } if (nWitnessCacheSize < WITNESS_CACHE_SIZE) { @@ -869,6 +870,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, for (const CTransaction& tx : pblock->vtx) { auto hash = tx.GetHash(); bool txIsOurs = mapWallet.count(hash); + // Sprout for (size_t i = 0; i < tx.vjoinsplit.size(); i++) { const JSDescription& jsdesc = tx.vjoinsplit[i]; for (uint8_t j = 0; j < jsdesc.commitments.size(); j++) { @@ -887,11 +889,28 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, } } } + // Sapling + for (uint32_t i = 0; i < tx.vShieldedOutput.size(); i++) { + const uint256& note_commitment = tx.vShieldedOutput[i].cm; + saplingTree.append(note_commitment); + + // Increment existing witnesses + for (std::pair& wtxItem : mapWallet) { + ::AppendNoteCommitment(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize, note_commitment); + } + + // If this is our note, witness it + if (txIsOurs) { + SaplingOutPoint outPoint {hash, i}; + ::WitnessNoteIfMine(mapWallet[hash].mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize, outPoint, saplingTree.witness()); + } + } } // Update witness heights for (std::pair& wtxItem : mapWallet) { ::UpdateWitnessHeights(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize); + ::UpdateWitnessHeights(wtxItem.second.mapSaplingNoteData, pindex->nHeight, nWitnessCacheSize); } // For performance reasons, we write out the witness cache in diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 87f49b4e7..25c5704ce 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -266,7 +266,13 @@ public: class SaplingNoteData { public: - std::list witnesses; + /** + * We initialize the hight to -1 for the same reason as we do in SproutNoteData. + * See the comment in that class for a full description. + */ + SaplingNoteData() : witnessHeight {-1} { } + + std::list witnesses; int witnessHeight; };