Skip to content

Commit 0a9a24d

Browse files
committed
validation: Pass in chainstate to UpdateMempoolForReorg
1 parent 7142018 commit 0a9a24d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/validation.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,11 @@ static bool IsCurrentForFeeEstimation(CChainState& active_chainstate) EXCLUSIVE_
373373
* and instead just erase from the mempool as needed.
374374
*/
375375

376-
static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, mempool.cs)
376+
static void UpdateMempoolForReorg(CChainState& active_chainstate, CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, mempool.cs)
377377
{
378378
AssertLockHeld(cs_main);
379379
AssertLockHeld(mempool.cs);
380+
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
380381
std::vector<uint256> vHashUpdate;
381382
// disconnectpool's insertion_order index sorts the entries from
382383
// oldest to newest, but the oldest entry will be the last tx from the
@@ -388,7 +389,7 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
388389
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
389390
// ignore validation errors in resurrected transactions
390391
if (!fAddToMempool || (*it)->IsCoinBase() ||
391-
AcceptToMemoryPool(::ChainstateActive(), mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) {
392+
AcceptToMemoryPool(active_chainstate, mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) {
392393
// If the transaction doesn't make it in to the mempool, remove any
393394
// transactions that depend on it (which would now be orphans).
394395
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
@@ -406,9 +407,9 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
406407
mempool.UpdateTransactionsFromBlock(vHashUpdate);
407408

408409
// We also need to remove any now-immature transactions
409-
mempool.removeForReorg(::ChainstateActive(), STANDARD_LOCKTIME_VERIFY_FLAGS);
410+
mempool.removeForReorg(active_chainstate, STANDARD_LOCKTIME_VERIFY_FLAGS);
410411
// Re-limit mempool size, in case we added any transactions
411-
LimitMempoolSize(mempool, ::ChainstateActive().CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
412+
LimitMempoolSize(mempool, active_chainstate.CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
412413
}
413414

414415
/**
@@ -2716,7 +2717,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27162717
if (!DisconnectTip(state, chainparams, &disconnectpool)) {
27172718
// This is likely a fatal error, but keep the mempool consistent,
27182719
// just in case. Only remove from the mempool in this case.
2719-
UpdateMempoolForReorg(m_mempool, disconnectpool, false);
2720+
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
27202721

27212722
// If we're unable to disconnect a block during normal operation,
27222723
// then that is a failure of our local system -- we should abort
@@ -2760,7 +2761,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27602761
// A system error occurred (disk space, database error, ...).
27612762
// Make the mempool consistent with the current tip, just in case
27622763
// any observers try to use it before shutdown.
2763-
UpdateMempoolForReorg(m_mempool, disconnectpool, false);
2764+
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
27642765
return false;
27652766
}
27662767
} else {
@@ -2777,7 +2778,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27772778
if (fBlocksDisconnected) {
27782779
// If any blocks were disconnected, disconnectpool may be non empty. Add
27792780
// any disconnected transactions back to the mempool.
2780-
UpdateMempoolForReorg(m_mempool, disconnectpool, true);
2781+
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, true);
27812782
}
27822783
m_mempool.check(&CoinsTip());
27832784

@@ -3014,7 +3015,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
30143015
// transactions back to the mempool if disconnecting was successful,
30153016
// and we're not doing a very deep invalidation (in which case
30163017
// keeping the mempool up to date is probably futile anyway).
3017-
UpdateMempoolForReorg(m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
3018+
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
30183019
if (!ret) return false;
30193020
assert(invalid_walk_tip->pprev == m_chain.Tip());
30203021

0 commit comments

Comments
 (0)