Skip to content

Commit 2f463f5

Browse files
committed
[doc] for CheckInputsFromMempoolAndCache
1 parent 85cc6be commit 2f463f5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/validation.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,16 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
404404
LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
405405
}
406406

407-
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
408-
// were somehow broken and returning the wrong scriptPubKeys
409-
static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& view, const CTxMemPool& pool,
410-
unsigned int flags, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) {
407+
/**
408+
* Checks to avoid mempool polluting consensus critical paths since cached
409+
* signature and script validity results will be reused if we validate this
410+
* transaction again during block validation.
411+
* */
412+
static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationState& state,
413+
const CCoinsViewCache& view, const CTxMemPool& pool,
414+
unsigned int flags, PrecomputedTransactionData& txdata)
415+
EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
416+
{
411417
AssertLockHeld(cs_main);
412418
AssertLockHeld(pool.cs);
413419

@@ -420,16 +426,19 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
420426
Assume(!coin.IsSpent());
421427
if (coin.IsSpent()) return false;
422428

423-
// Check equivalence for available inputs.
429+
// If the Coin is available, there are 2 possibilities:
430+
// it is available in our current ChainstateActive UTXO set,
431+
// or it's a UTXO provided by a transaction in our mempool.
432+
// Ensure the scriptPubKeys in Coins from CoinsView are correct.
424433
const CTransactionRef& txFrom = pool.get(txin.prevout.hash);
425434
if (txFrom) {
426435
assert(txFrom->GetHash() == txin.prevout.hash);
427436
assert(txFrom->vout.size() > txin.prevout.n);
428437
assert(txFrom->vout[txin.prevout.n] == coin.out);
429438
} else {
430-
const Coin& coinFromDisk = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
431-
assert(!coinFromDisk.IsSpent());
432-
assert(coinFromDisk.out == coin.out);
439+
const Coin& coinFromUTXOSet = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
440+
assert(!coinFromUTXOSet.IsSpent());
441+
assert(coinFromUTXOSet.out == coin.out);
433442
}
434443
}
435444

0 commit comments

Comments
 (0)