Skip to content

Commit 9e8d7ad

Browse files
committed
[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.
1 parent 09d1891 commit 9e8d7ad

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

src/txmempool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <txmempool.h>
77

8+
#include <coins.h>
89
#include <consensus/consensus.h>
910
#include <consensus/tx_verify.h>
1011
#include <consensus/validation.h>
@@ -767,7 +768,8 @@ void CTxMemPool::check(CChainState& active_chainstate) const
767768
CAmount txfee = 0;
768769
bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee);
769770
assert(fCheckResult);
770-
UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
771+
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
772+
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
771773
}
772774
for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
773775
uint256 hash = it->second->GetHash();

src/validation.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,12 +1240,6 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
12401240
AddCoins(inputs, tx, nHeight);
12411241
}
12421242

1243-
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
1244-
{
1245-
CTxUndo txundo;
1246-
UpdateCoins(tx, inputs, txundo, nHeight);
1247-
}
1248-
12491243
bool CScriptCheck::operator()() {
12501244
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
12511245
const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness;

src/validation.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
229229
const Package& txns, bool test_accept)
230230
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
231231

232-
/** Apply the effects of this transaction on the UTXO set represented by view */
233-
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
234-
235232
/** Transaction validation functions */
236233

237234
/**

0 commit comments

Comments
 (0)