Skip to content

Commit f798b89

Browse files
committed
Merge #8346: Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs
a6cc299 Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs (Jorge Timón)
2 parents cf2cecb + a6cc299 commit f798b89

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
@@ -352,9 +352,22 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
352352
/** Apply the effects of this transaction on the UTXO set represented by view */
353353
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
354354

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

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