Extract method for copying previous witnesses

This commit is contained in:
Eirik Ogilvie-Wigley
2018-07-17 11:54:21 -06:00
committed by Simon
parent 403b9b4e4d
commit b538024806

View File

@@ -756,16 +756,13 @@ void CWallet::ClearNoteWitnessCache()
nWitnessCacheSize = 0; nWitnessCacheSize = 0;
} }
void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, template<typename NoteDataMap>
const CBlock* pblockIn, void CopyPreviousWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t nWitnessCacheSize)
ZCIncrementalMerkleTree& tree)
{ {
LOCK(cs_wallet); for (auto& item : noteDataMap) {
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) { auto* nd = &(item.second);
for (mapSproutNoteData_t::value_type& item : wtxItem.second.mapSproutNoteData) {
SproutNoteData* nd = &(item.second);
// Only increment witnesses that are behind the current height // Only increment witnesses that are behind the current height
if (nd->witnessHeight < pindex->nHeight) { if (nd->witnessHeight < indexHeight) {
// Check the validity of the cache // Check the validity of the cache
// The only time a note witnessed above the current height // The only time a note witnessed above the current height
// would be invalid here is during a reindex when blocks // would be invalid here is during a reindex when blocks
@@ -773,9 +770,8 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
// immediately after. // immediately after.
assert(nWitnessCacheSize >= nd->witnesses.size()); assert(nWitnessCacheSize >= nd->witnesses.size());
// Witnesses being incremented should always be either -1 // Witnesses being incremented should always be either -1
// (never incremented or decremented) or one below pindex // (never incremented or decremented) or one below indexHeight
assert((nd->witnessHeight == -1) || assert((nd->witnessHeight == -1) || (nd->witnessHeight == indexHeight - 1));
(nd->witnessHeight == pindex->nHeight - 1));
// Copy the witness for the previous block if we have one // Copy the witness for the previous block if we have one
if (nd->witnesses.size() > 0) { if (nd->witnesses.size() > 0) {
nd->witnesses.push_front(nd->witnesses.front()); nd->witnesses.push_front(nd->witnesses.front());
@@ -786,6 +782,16 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
} }
} }
} }
void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
const CBlock* pblockIn,
ZCIncrementalMerkleTree& tree)
{
LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
::CopyPreviousWitnesses(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize);
}
if (nWitnessCacheSize < WITNESS_CACHE_SIZE) { if (nWitnessCacheSize < WITNESS_CACHE_SIZE) {
nWitnessCacheSize += 1; nWitnessCacheSize += 1;
} }