diff --git a/src/coins.h b/src/coins.h --- a/src/coins.h +++ b/src/coins.h @@ -280,11 +280,10 @@ const Coin &AccessCoin(const COutPoint &output) const; /** - * Add a coin. Set potential_overwrite to true if an unspent version may + * Add a coin. Set possible_overwrite to true if an unspent version may * already exist in the cache. */ - void AddCoin(const COutPoint &outpoint, Coin coin, - bool potential_overwrite); + void AddCoin(const COutPoint &outpoint, Coin coin, bool possible_overwrite); /** * Spend a coin. Pass moveto in order to get the deleted data. diff --git a/src/coins.cpp b/src/coins.cpp --- a/src/coins.cpp +++ b/src/coins.cpp @@ -142,13 +142,14 @@ } void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, - bool check) { + bool check_for_overwrite) { bool fCoinbase = tx.IsCoinBase(); const TxId txid = tx.GetId(); for (size_t i = 0; i < tx.vout.size(); ++i) { const COutPoint outpoint(txid, i); - bool overwrite = check ? cache.HaveCoin(outpoint) : fCoinbase; - // Always set the possible_overwrite flag to AddCoin for coinbase txn, + bool overwrite = + check_for_overwrite ? cache.HaveCoin(outpoint) : fCoinbase; + // Coinbase transactions can always be overwritten, // in order to correctly deal with the pre-BIP30 occurrences of // duplicate coinbase transactions. cache.AddCoin(outpoint, Coin(tx.vout[i], nHeight, fCoinbase), diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -813,10 +813,10 @@ /** * Check AddCoin behavior, requesting a new coin from a cache view, writing * a modification to the coin, and then checking the resulting entry in the - * cache after the modification. Verify behavior with the with the AddCoin - * potential_overwrite argument set to false, and to true. + * cache after the modification. Verify behavior with the AddCoin + * possible_overwrite argument set to false, and to true. * - * Cache Write Result Cache Result potential_overwrite + * Cache Write Result Cache Result possible_overwrite * Value Value Value Flags Flags */ CheckAddCoin(ABSENT, VALUE3, VALUE3, NO_ENTRY, DIRTY | FRESH, false); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1349,10 +1349,11 @@ alternate.IsCoinBase()); } - // The potential_overwrite parameter to AddCoin is only allowed to be false - // if we know for sure that the coin did not already exist in the cache. As - // we have queried for that above using HaveCoin, we don't need to guess. - // When fClean is false, a coin already existed and it is an overwrite. + // If the coin already exists as an unspent coin in the cache, then the + // possible_overwrite parameter to AddCoin must be set to true. We have + // already checked whether an unspent coin exists above using HaveCoin, so + // we don't need to guess. When fClean is false, an unspent coin already + // existed and it is an overwrite. view.AddCoin(out, std::move(undo), !fClean); return fClean ? DisconnectResult::OK : DisconnectResult::UNCLEAN;