Skip to content

Commit 21fa0a4

Browse files
committed
[docs] use consistent naming for possible_overwrite
And other general comment improvements for adding coins.
1 parent 2685c21 commit 21fa0a4

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/coins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
9999
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
100100
}
101101

102-
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check) {
102+
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
103103
bool fCoinbase = tx.IsCoinBase();
104104
const uint256& txid = tx.GetHash();
105105
for (size_t i = 0; i < tx.vout.size(); ++i) {
106-
bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
107-
// Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly
106+
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
107+
// Coinbase transactions can always be overwritten, in order to correctly
108108
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
109109
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
110110
}

src/coins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ class CCoinsViewCache : public CCoinsViewBacked
284284
const Coin& AccessCoin(const COutPoint &output) const;
285285

286286
/**
287-
* Add a coin. Set potential_overwrite to true if an unspent version may
287+
* Add a coin. Set possible_overwrite to true if an unspent version may
288288
* already exist in the cache.
289289
*/
290-
void AddCoin(const COutPoint& outpoint, Coin&& coin, bool potential_overwrite);
290+
void AddCoin(const COutPoint& outpoint, Coin&& coin, bool possible_overwrite);
291291

292292
/**
293293
* Spend a coin. Pass moveto in order to get the deleted data.

src/test/coins_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,9 @@ BOOST_AUTO_TEST_CASE(ccoins_add)
751751
/* Check AddCoin behavior, requesting a new coin from a cache view,
752752
* writing a modification to the coin, and then checking the resulting
753753
* entry in the cache after the modification. Verify behavior with the
754-
* with the AddCoin potential_overwrite argument set to false, and to true.
754+
* AddCoin possible_overwrite argument set to false, and to true.
755755
*
756-
* Cache Write Result Cache Result potential_overwrite
756+
* Cache Write Result Cache Result possible_overwrite
757757
* Value Value Value Flags Flags
758758
*/
759759
CheckAddCoin(ABSENT, VALUE3, VALUE3, NO_ENTRY , DIRTY|FRESH, false);

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,10 +1669,11 @@ int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out)
16691669
return DISCONNECT_FAILED; // adding output for transaction without known metadata
16701670
}
16711671
}
1672-
// The potential_overwrite parameter to AddCoin is only allowed to be false if we know for
1673-
// sure that the coin did not already exist in the cache. As we have queried for that above
1674-
// using HaveCoin, we don't need to guess. When fClean is false, a coin already existed and
1675-
// it is an overwrite.
1672+
// If the coin already exists as an unspent coin in the cache, then the
1673+
// possible_overwrite parameter to AddCoin must be set to true. We have
1674+
// already checked whether an unspent coin exists above using HaveCoin, so
1675+
// we don't need to guess. When fClean is false, an unspent coin already
1676+
// existed and it is an overwrite.
16761677
view.AddCoin(out, std::move(undo), !fClean);
16771678

16781679
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;

0 commit comments

Comments
 (0)