@@ -1473,6 +1473,10 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
14731473 }
14741474
14751475 hashPrevBestCoinbase = pblock->vtx [0 ]->GetHash ();
1476+
1477+ // reset cache to make sure no longer immature coins are included
1478+ fAnonymizableTallyCached = false ;
1479+ fAnonymizableTallyCachedNonDenom = false ;
14761480}
14771481
14781482void CWallet::BlockDisconnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) {
@@ -1482,6 +1486,10 @@ void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, con
14821486 // NOTE: do NOT pass pindex here
14831487 SyncTransaction (ptx);
14841488 }
1489+
1490+ // reset cache to make sure no longer mature coins are excluded
1491+ fAnonymizableTallyCached = false ;
1492+ fAnonymizableTallyCachedNonDenom = false ;
14851493}
14861494
14871495
@@ -3277,8 +3285,9 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
32773285
32783286 isminefilter filter = ISMINE_SPENDABLE;
32793287
3280- // try to use cache for already confirmed anonymizable inputs, no cache should be used when the limit is specified
3281- if (nMaxOupointsPerAddress != -1 && fAnonymizable && fSkipUnconfirmed ) {
3288+ // Try using the cache for already confirmed anonymizable inputs.
3289+ // This should only be used if nMaxOupointsPerAddress was NOT specified.
3290+ if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
32823291 if (fSkipDenominated && fAnonymizableTallyCachedNonDenom ) {
32833292 vecTallyRet = vecAnonymizableTallyCachedNonDenom;
32843293 LogPrint (BCLog::SELECTCOINS, " SelectCoinsGroupedByAddresses - using cache for non-denom inputs %d\n " , vecTallyRet.size ());
@@ -3350,8 +3359,9 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
33503359 vecTallyRet.push_back (item.second );
33513360 }
33523361
3353- // cache already confirmed anonymizable entries for later use, no cache should be saved when the limit is specified
3354- if (nMaxOupointsPerAddress != -1 && fAnonymizable && fSkipUnconfirmed ) {
3362+ // Cache already confirmed anonymizable entries for later use.
3363+ // This should only be used if nMaxOupointsPerAddress was NOT specified.
3364+ if (nMaxOupointsPerAddress == -1 && fAnonymizable && fSkipUnconfirmed ) {
33553365 if (fSkipDenominated ) {
33563366 vecAnonymizableTallyCachedNonDenom = vecTallyRet;
33573367 fAnonymizableTallyCachedNonDenom = true ;
0 commit comments