mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
[refactor] pass coinsview and height to check()
Removes check's dependency on validation.h
This commit is contained in:
parent
ed6115f1ea
commit
082c5bf099
6 changed files with 11 additions and 10 deletions
|
@ -107,10 +107,11 @@ static void MempoolCheck(benchmark::Bench& bench)
|
||||||
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
|
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
|
||||||
CTxMemPool pool;
|
CTxMemPool pool;
|
||||||
LOCK2(cs_main, pool.cs);
|
LOCK2(cs_main, pool.cs);
|
||||||
|
const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
|
||||||
for (auto& tx : ordered_coins) AddTx(tx, pool);
|
for (auto& tx : ordered_coins) AddTx(tx, pool);
|
||||||
|
|
||||||
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
|
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
|
||||||
pool.check(testing_setup.get()->m_node.chainman->ActiveChainstate());
|
pool.check(coins_tip, /* spendheight */ 2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2298,7 +2298,8 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_mempool.check(m_chainman.ActiveChainstate());
|
CChainState& active_chainstate = m_chainman.ActiveChainstate();
|
||||||
|
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
|
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
|
||||||
|
@ -3260,7 +3261,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
const TxValidationState& state = result.m_state;
|
const TxValidationState& state = result.m_state;
|
||||||
|
|
||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
m_mempool.check(m_chainman.ActiveChainstate());
|
CChainState& active_chainstate = m_chainman.ActiveChainstate();
|
||||||
|
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
|
||||||
// As this version of the transaction was acceptable, we can forget about any
|
// As this version of the transaction was acceptable, we can forget about any
|
||||||
// requests for it.
|
// requests for it.
|
||||||
m_txrequest.ForgetTxHash(tx.GetHash());
|
m_txrequest.ForgetTxHash(tx.GetHash());
|
||||||
|
|
|
@ -81,7 +81,7 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
|
||||||
|
|
||||||
void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CChainState& chainstate)
|
void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CChainState& chainstate)
|
||||||
{
|
{
|
||||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
|
||||||
{
|
{
|
||||||
BlockAssembler::Options options;
|
BlockAssembler::Options options;
|
||||||
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
|
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
|
||||||
|
@ -97,7 +97,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CCh
|
||||||
std::vector<uint256> all_txids;
|
std::vector<uint256> all_txids;
|
||||||
tx_pool.queryHashes(all_txids);
|
tx_pool.queryHashes(all_txids);
|
||||||
assert(all_txids.size() < info_all.size());
|
assert(all_txids.size() < info_all.size());
|
||||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
|
||||||
}
|
}
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -672,7 +672,7 @@ void CTxMemPool::clear()
|
||||||
_clear();
|
_clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::check(CChainState& active_chainstate) const
|
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
|
||||||
{
|
{
|
||||||
if (m_check_ratio == 0) return;
|
if (m_check_ratio == 0) return;
|
||||||
|
|
||||||
|
@ -687,9 +687,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
|
||||||
uint64_t innerUsage = 0;
|
uint64_t innerUsage = 0;
|
||||||
uint64_t prev_ancestor_count{0};
|
uint64_t prev_ancestor_count{0};
|
||||||
|
|
||||||
CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
|
|
||||||
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
|
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
|
||||||
const int64_t spendheight = active_chainstate.m_chain.Height() + 1;
|
|
||||||
|
|
||||||
for (const auto& it : GetSortedDepthAndScore()) {
|
for (const auto& it : GetSortedDepthAndScore()) {
|
||||||
checkTotal += it->GetTxSize();
|
checkTotal += it->GetTxSize();
|
||||||
|
|
|
@ -622,7 +622,7 @@ public:
|
||||||
* all inputs are in the mapNextTx array). If sanity-checking is turned off,
|
* all inputs are in the mapNextTx array). If sanity-checking is turned off,
|
||||||
* check does nothing.
|
* check does nothing.
|
||||||
*/
|
*/
|
||||||
void check(CChainState& active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
void check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
// addUnchecked must updated state for all ancestors of a given transaction,
|
// addUnchecked must updated state for all ancestors of a given transaction,
|
||||||
// to track size/count of descendant transactions. First version of
|
// to track size/count of descendant transactions. First version of
|
||||||
|
|
|
@ -2486,7 +2486,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, CBlockIndex
|
||||||
// any disconnected transactions back to the mempool.
|
// any disconnected transactions back to the mempool.
|
||||||
MaybeUpdateMempoolForReorg(disconnectpool, true);
|
MaybeUpdateMempoolForReorg(disconnectpool, true);
|
||||||
}
|
}
|
||||||
if (m_mempool) m_mempool->check(*this);
|
if (m_mempool) m_mempool->check(this->CoinsTip(), this->m_chain.Height() + 1);
|
||||||
|
|
||||||
CheckForkWarningConditions();
|
CheckForkWarningConditions();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue