Merge #10537: Few Minor per-utxo assert-semantics re-adds and tweak
9417d7a33 Be much more agressive in AccessCoin docs. (Matt Corallo) f58349ca8 Restore some assert semantics in sigop cost calculations (Matt Corallo) 3533fb4d3 Return a bool in SpendCoin to restore pre-per-utxo assert semantics (Matt Corallo) ec1271f2b Remove useless mapNextTx lookup in CTxMemPool::TrimToSize. (Matt Corallo) Tree-SHA512: 158a4bce063eac93e1d50709500a10a7cb1fb3271f10ed445d701852fce713e2bf0da3456088e530ab005f194ef4a2adf0c7cb23226b160cecb37a79561f29ca
This commit is contained in:
parent
4f807422fa
commit
151c552c71
@ -91,9 +91,9 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight) {
|
||||
}
|
||||
}
|
||||
|
||||
void CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
|
||||
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
|
||||
CCoinsMap::iterator it = FetchCoin(outpoint);
|
||||
if (it == cacheCoins.end()) return;
|
||||
if (it == cacheCoins.end()) return false;
|
||||
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
|
||||
if (moveout) {
|
||||
*moveout = std::move(it->second.coin);
|
||||
@ -104,6 +104,7 @@ void CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
|
||||
it->second.flags |= CCoinsCacheEntry::DIRTY;
|
||||
it->second.coin.Clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const Coin coinEmpty;
|
||||
|
11
src/coins.h
11
src/coins.h
@ -225,8 +225,13 @@ public:
|
||||
|
||||
/**
|
||||
* Return a reference to Coin in the cache, or a pruned one if not found. This is
|
||||
* more efficient than GetCoin. Modifications to other cache entries are
|
||||
* allowed while accessing the returned pointer.
|
||||
* more efficient than GetCoin.
|
||||
*
|
||||
* Generally, do not hold the reference returned for more than a short scope.
|
||||
* While the current implementation allows for modifications to the contents
|
||||
* of the cache while holding the reference, this behavior should not be relied
|
||||
* on! To be safe, best to not hold the returned reference through any other
|
||||
* calls to this cache.
|
||||
*/
|
||||
const Coin& AccessCoin(const COutPoint &output) const;
|
||||
|
||||
@ -241,7 +246,7 @@ public:
|
||||
* If no unspent output exists for the passed outpoint, this call
|
||||
* has no effect.
|
||||
*/
|
||||
void SpendCoin(const COutPoint &outpoint, Coin* moveto = nullptr);
|
||||
bool SpendCoin(const COutPoint &outpoint, Coin* moveto = nullptr);
|
||||
|
||||
/**
|
||||
* Push the modifications applied to this cache to its base.
|
||||
|
@ -1143,9 +1143,7 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpends
|
||||
BOOST_FOREACH(const CTransaction& tx, txn) {
|
||||
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
|
||||
if (exists(txin.prevout.hash)) continue;
|
||||
if (!mapNextTx.count(txin.prevout)) {
|
||||
pvNoSpendsRemaining->push_back(txin.prevout);
|
||||
}
|
||||
pvNoSpendsRemaining->push_back(txin.prevout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +437,9 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
|
||||
unsigned int nSigOps = 0;
|
||||
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
||||
{
|
||||
const CTxOut &prevout = inputs.AccessCoin(tx.vin[i].prevout).out;
|
||||
const Coin& coin = inputs.AccessCoin(tx.vin[i].prevout);
|
||||
assert(!coin.IsSpent());
|
||||
const CTxOut &prevout = coin.out;
|
||||
if (prevout.scriptPubKey.IsPayToScriptHash())
|
||||
nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig);
|
||||
}
|
||||
@ -1427,7 +1429,8 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
|
||||
txundo.vprevout.reserve(tx.vin.size());
|
||||
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
||||
txundo.vprevout.emplace_back();
|
||||
inputs.SpendCoin(txin.prevout, &txundo.vprevout.back());
|
||||
bool is_spent = inputs.SpendCoin(txin.prevout, &txundo.vprevout.back());
|
||||
assert(is_spent);
|
||||
}
|
||||
}
|
||||
// add outputs
|
||||
@ -1750,8 +1753,8 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s
|
||||
if (!tx.vout[o].scriptPubKey.IsUnspendable()) {
|
||||
COutPoint out(hash, o);
|
||||
Coin coin;
|
||||
view.SpendCoin(out, &coin);
|
||||
if (tx.vout[o] != coin.out) {
|
||||
bool is_spent = view.SpendCoin(out, &coin);
|
||||
if (!is_spent || tx.vout[o] != coin.out) {
|
||||
fClean = false; // transaction output mismatch
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user