Skip to content

Commit a6cc299

Browse files
committed
Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs
1 parent 304eff3 commit a6cc299

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,22 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
351351
/** Apply the effects of this transaction on the UTXO set represented by view */
352352
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
353353

354+
/** Transaction validation functions */
355+
354356
/** Context-independent validity checks */
355357
bool CheckTransaction(const CTransaction& tx, CValidationState& state);
356358

359+
namespace Consensus {
360+
361+
/**
362+
* Check whether all inputs of this transaction are valid (no double spends and amounts)
363+
* This does not modify the UTXO set. This does not check scripts and sigs.
364+
* Preconditions: tx.IsCoinBase() is false.
365+
*/
366+
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight);
367+
368+
} // namespace Consensus
369+
357370
/**
358371
* Check if transaction is final and can be included in a block with the
359372
* specified height and time. Consensus critical.

src/txmempool.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
657657
uint64_t innerUsage = 0;
658658

659659
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
660+
const int64_t nSpendHeight = GetSpendHeight(mempoolDuplicate);
660661

661662
LOCK(cs);
662663
list<const CTxMemPoolEntry*> waitingOnDependants;
@@ -737,7 +738,9 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
737738
waitingOnDependants.push_back(&(*it));
738739
else {
739740
CValidationState state;
740-
assert(CheckInputs(tx, state, mempoolDuplicate, false, 0, false, NULL));
741+
bool fCheckResult = tx.IsCoinBase() ||
742+
Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight);
743+
assert(fCheckResult);
741744
UpdateCoins(tx, mempoolDuplicate, 1000000);
742745
}
743746
}
@@ -751,7 +754,9 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
751754
stepsSinceLastRemove++;
752755
assert(stepsSinceLastRemove < waitingOnDependants.size());
753756
} else {
754-
assert(CheckInputs(entry->GetTx(), state, mempoolDuplicate, false, 0, false, NULL));
757+
bool fCheckResult = entry->GetTx().IsCoinBase() ||
758+
Consensus::CheckTxInputs(entry->GetTx(), state, mempoolDuplicate, nSpendHeight);
759+
assert(fCheckResult);
755760
UpdateCoins(entry->GetTx(), mempoolDuplicate, 1000000);
756761
stepsSinceLastRemove = 0;
757762
}

0 commit comments

Comments
 (0)