From 9d2cc3a78445c5256bc0d6c20884edc5cffc742f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 10 Dec 2016 00:56:32 +1300 Subject: [PATCH] Make the test pass by fixing the bug! --- src/wallet/wallet.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c9dac701d..b424b8def 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -756,16 +756,19 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) CNoteData* nd = &(item.second); // Check the validity of the cache assert(nWitnessCacheSize >= nd->witnesses.size()); - // Witnesses being decremented should always be either -1 - // (never incremented or decremented) or equal to pindex - assert((nd->witnessHeight == -1) || - (nd->witnessHeight == pindex->nHeight)); - if (nd->witnesses.size() > 0) { - nd->witnesses.pop_front(); + // Only increment witnesses that are not above the current height + if (nd->witnessHeight <= pindex->nHeight) { + // Witnesses being decremented should always be either -1 + // (never incremented or decremented) or equal to pindex + assert((nd->witnessHeight == -1) || + (nd->witnessHeight == pindex->nHeight)); + if (nd->witnesses.size() > 0) { + nd->witnesses.pop_front(); + } + // pindex is the block being removed, so the new witness cache + // height is one below it. + nd->witnessHeight = pindex->nHeight - 1; } - // pindex is the block being removed, so the new witness cache - // height is one below it. - nd->witnessHeight = pindex->nHeight - 1; } } nWitnessCacheSize -= 1;