Extract method for incrementing witness heights

This commit is contained in:
Eirik Ogilvie-Wigley 2018-07-17 11:55:20 -06:00 committed by Simon
parent f6d0d5ec43
commit 4a0bc6047e
1 changed files with 16 additions and 9 deletions

View File

@ -827,6 +827,21 @@ void WitnessNoteIfMine(std::map<OutPoint, NoteData>& noteDataMap, int indexHeigh
}
}
template<typename NoteDataMap>
void UpdateWitnessHeights(NoteDataMap& noteDataMap, int indexHeight, int64_t nWitnessCacheSize)
{
for (auto& item : noteDataMap) {
auto* nd = &(item.second);
if (nd->witnessHeight < indexHeight) {
nd->witnessHeight = indexHeight;
// Check the validity of the cache
// See comment in CopyPreviousWitnesses about validity.
assert(nWitnessCacheSize >= nd->witnesses.size());
}
}
}
void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
const CBlock* pblockIn,
ZCIncrementalMerkleTree& tree)
@ -872,15 +887,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
// Update witness heights
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
for (mapSproutNoteData_t::value_type& item : wtxItem.second.mapSproutNoteData) {
SproutNoteData* nd = &(item.second);
if (nd->witnessHeight < pindex->nHeight) {
nd->witnessHeight = pindex->nHeight;
// Check the validity of the cache
// See earlier comment about validity.
assert(nWitnessCacheSize >= nd->witnesses.size());
}
}
::UpdateWitnessHeights(wtxItem.second.mapSproutNoteData, pindex->nHeight, nWitnessCacheSize);
}
// For performance reasons, we write out the witness cache in