[doc] for CheckInputsFromMempoolAndCache

This commit is contained in:
gzhao408 2021-01-06 13:38:32 -08:00
parent 85cc6bed64
commit 2f463f57e3

View File

@ -404,10 +404,16 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}); LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
} }
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool /**
// were somehow broken and returning the wrong scriptPubKeys * Checks to avoid mempool polluting consensus critical paths since cached
static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& view, const CTxMemPool& pool, * signature and script validity results will be reused if we validate this
unsigned int flags, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) { * transaction again during block validation.
* */
static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationState& state,
const CCoinsViewCache& view, const CTxMemPool& pool,
unsigned int flags, PrecomputedTransactionData& txdata)
EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
{
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
AssertLockHeld(pool.cs); AssertLockHeld(pool.cs);
@ -420,16 +426,19 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
Assume(!coin.IsSpent()); Assume(!coin.IsSpent());
if (coin.IsSpent()) return false; if (coin.IsSpent()) return false;
// Check equivalence for available inputs. // If the Coin is available, there are 2 possibilities:
// it is available in our current ChainstateActive UTXO set,
// or it's a UTXO provided by a transaction in our mempool.
// Ensure the scriptPubKeys in Coins from CoinsView are correct.
const CTransactionRef& txFrom = pool.get(txin.prevout.hash); const CTransactionRef& txFrom = pool.get(txin.prevout.hash);
if (txFrom) { if (txFrom) {
assert(txFrom->GetHash() == txin.prevout.hash); assert(txFrom->GetHash() == txin.prevout.hash);
assert(txFrom->vout.size() > txin.prevout.n); assert(txFrom->vout.size() > txin.prevout.n);
assert(txFrom->vout[txin.prevout.n] == coin.out); assert(txFrom->vout[txin.prevout.n] == coin.out);
} else { } else {
const Coin& coinFromDisk = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout); const Coin& coinFromUTXOSet = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
assert(!coinFromDisk.IsSpent()); assert(!coinFromUTXOSet.IsSpent());
assert(coinFromDisk.out == coin.out); assert(coinFromUTXOSet.out == coin.out);
} }
} }