diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0ba5df8dd..852e47b73 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3375,13 +3375,16 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) auto tmp = wtxIn.mapSproutNoteData; // Ensure we keep any cached witnesses we may already have for (const std::pair nd : wtx.mapSproutNoteData) { - if (tmp.count(nd.first)) { - if (nd.second.witnesses.size() > 0) { - tmp.at(nd.first).witnesses.assign( - nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); - } - tmp.at(nd.first).witnessHeight = nd.second.witnessHeight; + // Require that wtxIn's data is a superset of wtx's data. This holds + // because viewing keys are _never_ deleted from the wallet, so the + // number of detected notes can only increase. + assert(tmp.count(nd.first) == 1); + + if (nd.second.witnesses.size() > 0) { + tmp.at(nd.first).witnesses.assign( + nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); } + tmp.at(nd.first).witnessHeight = nd.second.witnessHeight; } // Now copy over the updated note data wtx.mapSproutNoteData = tmp; @@ -3393,13 +3396,16 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) // Ensure we keep any cached witnesses we may already have for (const std::pair nd : wtx.mapSaplingNoteData) { - if (tmp.count(nd.first)) { - if (nd.second.witnesses.size() > 0) { - tmp.at(nd.first).witnesses.assign( - nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); - } - tmp.at(nd.first).witnessHeight = nd.second.witnessHeight; + // Require that wtxIn's data is a superset of wtx's data. This holds + // because viewing keys are _never_ deleted from the wallet, so the + // number of detected notes can only increase. + assert(tmp.count(nd.first) == 1); + + if (nd.second.witnesses.size() > 0) { + tmp.at(nd.first).witnesses.assign( + nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); } + tmp.at(nd.first).witnessHeight = nd.second.witnessHeight; } // Now copy over the updated note data