@@ -404,10 +404,16 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
404
404
LimitMempoolSize (mempool, gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 , std::chrono::hours{gArgs .GetArg (" -mempoolexpiry" , DEFAULT_MEMPOOL_EXPIRY)});
405
405
}
406
406
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
+ {
411
417
AssertLockHeld (cs_main);
412
418
AssertLockHeld (pool.cs );
413
419
@@ -420,16 +426,19 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
420
426
Assume (!coin.IsSpent ());
421
427
if (coin.IsSpent ()) return false ;
422
428
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.
424
433
const CTransactionRef& txFrom = pool.get (txin.prevout .hash );
425
434
if (txFrom) {
426
435
assert (txFrom->GetHash () == txin.prevout .hash );
427
436
assert (txFrom->vout .size () > txin.prevout .n );
428
437
assert (txFrom->vout [txin.prevout .n ] == coin.out );
429
438
} 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 );
433
442
}
434
443
}
435
444
0 commit comments