From 9e8d7ad5d9cc4b013826daead9cee09aad539401 Mon Sep 17 00:00:00 2001 From: glozow Date: Mon, 4 Oct 2021 13:01:38 +0100 Subject: [PATCH] [validation/mempool] use Spend/AddCoin instead of UpdateCoins UpdateCoins is an unnecessary dependency on validation. All we need to do is add and remove coins to check inputs. We don't need the extra logic for checking coinbases and handling TxUndos. Also remove the wrapper function in validation.h which constructs a throwaway TxUndo object before calling UpdateCoins because it is now unused. --- src/txmempool.cpp | 4 +++- src/validation.cpp | 6 ------ src/validation.h | 3 --- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 40e142dc477..c1abe24af7b 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -767,7 +768,8 @@ void CTxMemPool::check(CChainState& active_chainstate) const CAmount txfee = 0; bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee); assert(fCheckResult); - UpdateCoins(tx, mempoolDuplicate, std::numeric_limits::max()); + for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout); + AddCoins(mempoolDuplicate, tx, std::numeric_limits::max()); } for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) { uint256 hash = it->second->GetHash(); diff --git a/src/validation.cpp b/src/validation.cpp index 4504d2ca0a2..863502e0d76 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1240,12 +1240,6 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund AddCoins(inputs, tx, nHeight); } -void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight) -{ - CTxUndo txundo; - UpdateCoins(tx, inputs, txundo, nHeight); -} - bool CScriptCheck::operator()() { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness; diff --git a/src/validation.h b/src/validation.h index b2282828ced..caa0832dd3a 100644 --- a/src/validation.h +++ b/src/validation.h @@ -229,9 +229,6 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx const Package& txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main); -/** Apply the effects of this transaction on the UTXO set represented by view */ -void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); - /** Transaction validation functions */ /**