Skip to content

Commit 85cc6be

Browse files
committed
lock annotations for MemPoolAccept functions
We should already have the mempool lock when entering CheckInputsFromMempoolAndCache
1 parent 86a8b35 commit 85cc6be

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/validation.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,17 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
407407
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
408408
// were somehow broken and returning the wrong scriptPubKeys
409409
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) {
410+
unsigned int flags, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) {
411411
AssertLockHeld(cs_main);
412-
413-
// pool.cs should be locked already, but go ahead and re-take the lock here
414-
// to enforce that mempool doesn't change between when we check the view
415-
// and when we actually call through to CheckInputScripts
416-
LOCK(pool.cs);
412+
AssertLockHeld(pool.cs);
417413

418414
assert(!tx.IsCoinBase());
419415
for (const CTxIn& txin : tx.vin) {
420416
const Coin& coin = view.AccessCoin(txin.prevout);
421417

422-
// AcceptToMemoryPoolWorker has already checked that the coins are
423-
// available, so this shouldn't fail. If the inputs are not available
424-
// here then return false.
418+
// This coin was checked in PreChecks and MemPoolAccept
419+
// has been holding cs_main since then.
420+
Assume(!coin.IsSpent());
425421
if (coin.IsSpent()) return false;
426422

427423
// Check equivalence for available inputs.
@@ -502,21 +498,21 @@ class MemPoolAccept
502498

503499
// Run the script checks using our policy flags. As this can be slow, we should
504500
// only invoke this on transactions that have otherwise passed policy checks.
505-
bool PolicyScriptChecks(ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
501+
bool PolicyScriptChecks(ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
506502

507503
// Re-run the script checks, using consensus flags, and try to cache the
508504
// result in the scriptcache. This should be done after
509505
// PolicyScriptChecks(). This requires that all inputs either be in our
510506
// utxo set or in the mempool.
511-
bool ConsensusScriptChecks(ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData &txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
507+
bool ConsensusScriptChecks(ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData &txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
512508

513509
// Try to add the transaction to the mempool, removing any conflicts first.
514510
// Returns true if the transaction is in the mempool after any size
515511
// limiting is performed, false otherwise.
516512
bool Finalize(ATMPArgs& args, Workspace& ws) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
517513

518514
// Compare a package's feerate against minimum allowed.
519-
bool CheckFeeRate(size_t package_size, CAmount package_fee, TxValidationState& state)
515+
bool CheckFeeRate(size_t package_size, CAmount package_fee, TxValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs)
520516
{
521517
CAmount mempoolRejectFee = m_pool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFee(package_size);
522518
if (mempoolRejectFee > 0 && package_fee < mempoolRejectFee) {

0 commit comments

Comments
 (0)