Skip to content

Commit 4744efc

Browse files
committed
validation: Pass in chainstate to CTxMemPool::check
This is the only instance where validation reaches for something outside of it.
1 parent 1fb7b2c commit 4744efc

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
23012301
break;
23022302
}
23032303
}
2304-
m_mempool.check(&::ChainstateActive().CoinsTip());
2304+
m_mempool.check(m_chainman.ActiveChainstate());
23052305
}
23062306

23072307
/**
@@ -3262,7 +3262,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32623262
const TxValidationState& state = result.m_state;
32633263

32643264
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
3265-
m_mempool.check(&::ChainstateActive().CoinsTip());
3265+
m_mempool.check(m_chainman.ActiveChainstate());
32663266
// As this version of the transaction was acceptable, we can forget about any
32673267
// requests for it.
32683268
m_txrequest.ForgetTxHash(tx.GetHash());

src/txmempool.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& m
619619
UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
620620
}
621621

622-
void CTxMemPool::check(const CCoinsViewCache *pcoins) const
622+
void CTxMemPool::check(CChainState& active_chainstate) const
623623
{
624624
if (m_check_ratio == 0) return;
625625

@@ -633,8 +633,11 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
633633
CAmount check_total_fee{0};
634634
uint64_t innerUsage = 0;
635635

636-
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
637-
const int64_t spendheight = g_chainman.m_blockman.GetSpendHeight(mempoolDuplicate);
636+
CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
637+
assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(active_coins_tip)); // TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT
638+
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
639+
const int64_t spendheight = active_chainstate.m_chain.Height() + 1;
640+
assert(g_chainman.m_blockman.GetSpendHeight(mempoolDuplicate) == spendheight); // TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT
638641

639642
std::list<const CTxMemPoolEntry*> waitingOnDependants;
640643
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
@@ -655,7 +658,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
655658
fDependsWait = true;
656659
setParentCheck.insert(*it2);
657660
} else {
658-
assert(pcoins->HaveCoin(txin.prevout));
661+
assert(active_coins_tip.HaveCoin(txin.prevout));
659662
}
660663
// Check whether its inputs are marked in mapNextTx.
661664
auto it3 = mapNextTx.find(txin.prevout);

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ class CTxMemPool
604604
* all inputs are in the mapNextTx array). If sanity-checking is turned off,
605605
* check does nothing.
606606
*/
607-
void check(const CCoinsViewCache *pcoins) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
607+
void check(CChainState& active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
608608

609609
// addUnchecked must updated state for all ancestors of a given transaction,
610610
// to track size/count of descendant transactions. First version of

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27992799
// any disconnected transactions back to the mempool.
28002800
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, true);
28012801
}
2802-
m_mempool.check(&CoinsTip());
2802+
m_mempool.check(*this);
28032803

28042804
CheckForkWarningConditions();
28052805

0 commit comments

Comments
 (0)