From ed6115f1eae0eb4669601106a9aaff078a2f3a74 Mon Sep 17 00:00:00 2001 From: glozow Date: Mon, 4 Oct 2021 12:58:50 +0100 Subject: [PATCH] [mempool] simplify some check() logic No transaction in the mempool should ever be a coinbase. Since mempoolDuplicate's backend is the chainstate coins view, it should always contain the coins available. --- src/txmempool.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index c1abe24af7b..f65fb24f190 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -704,14 +704,12 @@ void CTxMemPool::check(CChainState& active_chainstate) const if (it2 != mapTx.end()) { const CTransaction& tx2 = it2->GetTx(); assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull()); - // We are iterating through the mempool entries sorted in order by ancestor count. - // All parents must have been checked before their children and their coins added to - // the mempoolDuplicate coins cache. - assert(mempoolDuplicate.HaveCoin(txin.prevout)); setParentCheck.insert(*it2); - } else { - assert(active_coins_tip.HaveCoin(txin.prevout)); } + // We are iterating through the mempool entries sorted in order by ancestor count. + // All parents must have been checked before their children and their coins added to + // the mempoolDuplicate coins cache. + assert(mempoolDuplicate.HaveCoin(txin.prevout)); // Check whether its inputs are marked in mapNextTx. auto it3 = mapNextTx.find(txin.prevout); assert(it3 != mapNextTx.end()); @@ -766,8 +764,8 @@ void CTxMemPool::check(CChainState& active_chainstate) const TxValidationState dummy_state; // Not used. CheckTxInputs() should always pass CAmount txfee = 0; - bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee); - assert(fCheckResult); + assert(!tx.IsCoinBase()); + assert(Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee)); for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout); AddCoins(mempoolDuplicate, tx, std::numeric_limits::max()); }