Increment sapling note witnesses

This commit is contained in:
Eirik Ogilvie-Wigley 2018-07-17 12:02:27 -06:00 committed by Simon
parent f86ee1c252
commit 45de2eda07
2 changed files with 26 additions and 1 deletions

View File

@ -853,6 +853,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& 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<const uint256, CWalletTx>& 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<const uint256, CWalletTx>& 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

View File

@ -266,7 +266,13 @@ public:
class SaplingNoteData
{
public:
std::list<ZCIncrementalWitness> 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<ZCSaplingIncrementalWitness> witnesses;
int witnessHeight;
};