aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgzhao408 <gzhao408@berkeley.edu>2021-01-06 13:38:32 -0800
committergzhao408 <gzhao408@berkeley.edu>2021-01-12 02:27:09 -0800
commit2f463f57e3a9797236142a525703359a98fe19ea (patch)
tree472a5ee745a73a408e2d644d5b8da0697301f7a1 /src
parent85cc6bed64dc17e3b091af9e14bc2f4d4e9bcaf1 (diff)
downloadbitcoin-2f463f57e3a9797236142a525703359a98fe19ea.tar.xz
[doc] for CheckInputsFromMempoolAndCache
Diffstat (limited to 'src')
-rw-r--r--src/validation.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index a27bbd78ee..a22c75a686 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -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)});
}
-// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
-// were somehow broken and returning the wrong scriptPubKeys
-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) {
+/**
+* Checks to avoid mempool polluting consensus critical paths since cached
+* signature and script validity results will be reused if we validate this
+* 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(pool.cs);
@@ -420,16 +426,19 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
Assume(!coin.IsSpent());
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);
if (txFrom) {
assert(txFrom->GetHash() == txin.prevout.hash);
assert(txFrom->vout.size() > txin.prevout.n);
assert(txFrom->vout[txin.prevout.n] == coin.out);
} else {
- const Coin& coinFromDisk = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
- assert(!coinFromDisk.IsSpent());
- assert(coinFromDisk.out == coin.out);
+ const Coin& coinFromUTXOSet = ::ChainstateActive().CoinsTip().AccessCoin(txin.prevout);
+ assert(!coinFromUTXOSet.IsSpent());
+ assert(coinFromUTXOSet.out == coin.out);
}
}