Skip to content

Commit 082c5bf

Browse files
committed
[refactor] pass coinsview and height to check()
Removes check's dependency on validation.h
1 parent ed6115f commit 082c5bf

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

src/bench/mempool_stress.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ static void MempoolCheck(benchmark::Bench& bench)
107107
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
108108
CTxMemPool pool;
109109
LOCK2(cs_main, pool.cs);
110+
const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
110111
for (auto& tx : ordered_coins) AddTx(tx, pool);
111112

112113
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
113-
pool.check(testing_setup.get()->m_node.chainman->ActiveChainstate());
114+
pool.check(coins_tip, /* spendheight */ 2);
114115
});
115116
}
116117

src/net_processing.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,8 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
22982298
break;
22992299
}
23002300
}
2301-
m_mempool.check(m_chainman.ActiveChainstate());
2301+
CChainState& active_chainstate = m_chainman.ActiveChainstate();
2302+
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
23022303
}
23032304

23042305
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
@@ -3260,7 +3261,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32603261
const TxValidationState& state = result.m_state;
32613262

32623263
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
3263-
m_mempool.check(m_chainman.ActiveChainstate());
3264+
CChainState& active_chainstate = m_chainman.ActiveChainstate();
3265+
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
32643266
// As this version of the transaction was acceptable, we can forget about any
32653267
// requests for it.
32663268
m_txrequest.ForgetTxHash(tx.GetHash());

src/test/fuzz/tx_pool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
8181

8282
void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CChainState& chainstate)
8383
{
84-
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
84+
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
8585
{
8686
BlockAssembler::Options options;
8787
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
@@ -97,7 +97,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CCh
9797
std::vector<uint256> all_txids;
9898
tx_pool.queryHashes(all_txids);
9999
assert(all_txids.size() < info_all.size());
100-
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
100+
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
101101
}
102102
SyncWithValidationInterfaceQueue();
103103
}

src/txmempool.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void CTxMemPool::clear()
672672
_clear();
673673
}
674674

675-
void CTxMemPool::check(CChainState& active_chainstate) const
675+
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
676676
{
677677
if (m_check_ratio == 0) return;
678678

@@ -687,9 +687,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
687687
uint64_t innerUsage = 0;
688688
uint64_t prev_ancestor_count{0};
689689

690-
CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
691690
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
692-
const int64_t spendheight = active_chainstate.m_chain.Height() + 1;
693691

694692
for (const auto& it : GetSortedDepthAndScore()) {
695693
checkTotal += it->GetTxSize();

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class CTxMemPool
622622
* all inputs are in the mapNextTx array). If sanity-checking is turned off,
623623
* check does nothing.
624624
*/
625-
void check(CChainState& active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
625+
void check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
626626

627627
// addUnchecked must updated state for all ancestors of a given transaction,
628628
// 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
@@ -2486,7 +2486,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, CBlockIndex
24862486
// any disconnected transactions back to the mempool.
24872487
MaybeUpdateMempoolForReorg(disconnectpool, true);
24882488
}
2489-
if (m_mempool) m_mempool->check(*this);
2489+
if (m_mempool) m_mempool->check(this->CoinsTip(), this->m_chain.Height() + 1);
24902490

24912491
CheckForkWarningConditions();
24922492

0 commit comments

Comments
 (0)