Skip to content

Commit 252b489

Browse files
committed
validation: Pass in coins tip to CheckInputsFromMempoolAndCache
1 parent 73a6d2b commit 252b489

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/validation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
415415
* */
416416
static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationState& state,
417417
const CCoinsViewCache& view, const CTxMemPool& pool,
418-
unsigned int flags, PrecomputedTransactionData& txdata)
418+
unsigned int flags, PrecomputedTransactionData& txdata, CCoinsViewCache& coins_tip)
419419
EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
420420
{
421421
AssertLockHeld(cs_main);
@@ -440,7 +440,8 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
440440
assert(txFrom->vout.size() > txin.prevout.n);
441441
assert(txFrom->vout[txin.prevout.n] == coin.out);
442442
} else {
443-
const Coin& coinFromUTXOSet = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
443+
assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(coins_tip));
444+
const Coin& coinFromUTXOSet = coins_tip.AccessCoin(txin.prevout);
444445
assert(!coinFromUTXOSet.IsSpent());
445446
assert(coinFromUTXOSet.out == coin.out);
446447
}
@@ -970,7 +971,7 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws, P
970971
// invalid blocks (using TestBlockValidity), however allowing such
971972
// transactions into the mempool can be exploited as a DoS attack.
972973
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(::ChainActive().Tip(), chainparams.GetConsensus());
973-
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags, txdata)) {
974+
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags, txdata, ::ChainstateActive().CoinsTip())) {
974975
return error("%s: BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s",
975976
__func__, hash.ToString(), state.ToString());
976977
}

0 commit comments

Comments
 (0)