diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7fb1dc3d5..3f08002d9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -827,6 +827,21 @@ void WitnessNoteIfMine(std::map& noteDataMap, int indexHeigh } } + +template +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& 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