mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-14 20:20:43 +02:00
[docs] use consistent naming for possible_overwrite
And other general comment improvements for adding coins.
This commit is contained in:
parent
2685c214cc
commit
21fa0a44ab
@ -99,12 +99,12 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
|
|||||||
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
|
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check) {
|
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
|
||||||
bool fCoinbase = tx.IsCoinBase();
|
bool fCoinbase = tx.IsCoinBase();
|
||||||
const uint256& txid = tx.GetHash();
|
const uint256& txid = tx.GetHash();
|
||||||
for (size_t i = 0; i < tx.vout.size(); ++i) {
|
for (size_t i = 0; i < tx.vout.size(); ++i) {
|
||||||
bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
|
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
|
||||||
// Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly
|
// Coinbase transactions can always be overwritten, in order to correctly
|
||||||
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
|
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
|
||||||
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
|
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
|
||||||
}
|
}
|
||||||
|
@ -284,10 +284,10 @@ public:
|
|||||||
const Coin& AccessCoin(const COutPoint &output) const;
|
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.
|
* 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.
|
* Spend a coin. Pass moveto in order to get the deleted data.
|
||||||
|
@ -751,9 +751,9 @@ BOOST_AUTO_TEST_CASE(ccoins_add)
|
|||||||
/* Check AddCoin behavior, requesting a new coin from a cache view,
|
/* Check AddCoin behavior, requesting a new coin from a cache view,
|
||||||
* writing a modification to the coin, and then checking the resulting
|
* writing a modification to the coin, and then checking the resulting
|
||||||
* entry in the cache after the modification. Verify behavior with the
|
* entry in the cache after the modification. Verify behavior with the
|
||||||
* with the AddCoin potential_overwrite argument set to false, and to true.
|
* 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
|
* Value Value Value Flags Flags
|
||||||
*/
|
*/
|
||||||
CheckAddCoin(ABSENT, VALUE3, VALUE3, NO_ENTRY , DIRTY|FRESH, false);
|
CheckAddCoin(ABSENT, VALUE3, VALUE3, NO_ENTRY , DIRTY|FRESH, false);
|
||||||
|
@ -1669,10 +1669,11 @@ int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out)
|
|||||||
return DISCONNECT_FAILED; // adding output for transaction without known metadata
|
return DISCONNECT_FAILED; // adding output for transaction without known metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The potential_overwrite parameter to AddCoin is only allowed to be false if we know for
|
// If the coin already exists as an unspent coin in the cache, then the
|
||||||
// sure that the coin did not already exist in the cache. As we have queried for that above
|
// possible_overwrite parameter to AddCoin must be set to true. We have
|
||||||
// using HaveCoin, we don't need to guess. When fClean is false, a coin already existed and
|
// already checked whether an unspent coin exists above using HaveCoin, so
|
||||||
// it is an overwrite.
|
// 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);
|
view.AddCoin(out, std::move(undo), !fClean);
|
||||||
|
|
||||||
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
|
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
|
||||||
|
Loading…
Reference in New Issue
Block a user