mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
validation: Pass in chainstate to UpdateMempoolForReorg
This commit is contained in:
parent
7142018812
commit
0a9a24d8c7
1 changed files with 9 additions and 8 deletions
|
@ -373,10 +373,11 @@ static bool IsCurrentForFeeEstimation(CChainState& active_chainstate) EXCLUSIVE_
|
|||
* and instead just erase from the mempool as needed.
|
||||
*/
|
||||
|
||||
static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, mempool.cs)
|
||||
static void UpdateMempoolForReorg(CChainState& active_chainstate, CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, mempool.cs)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
AssertLockHeld(mempool.cs);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||
std::vector<uint256> vHashUpdate;
|
||||
// disconnectpool's insertion_order index sorts the entries from
|
||||
// oldest to newest, but the oldest entry will be the last tx from the
|
||||
|
@ -388,7 +389,7 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
|
|||
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
|
||||
// ignore validation errors in resurrected transactions
|
||||
if (!fAddToMempool || (*it)->IsCoinBase() ||
|
||||
AcceptToMemoryPool(::ChainstateActive(), mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||
AcceptToMemoryPool(active_chainstate, mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||
// If the transaction doesn't make it in to the mempool, remove any
|
||||
// transactions that depend on it (which would now be orphans).
|
||||
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
|
||||
|
@ -406,9 +407,9 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
|
|||
mempool.UpdateTransactionsFromBlock(vHashUpdate);
|
||||
|
||||
// We also need to remove any now-immature transactions
|
||||
mempool.removeForReorg(::ChainstateActive(), STANDARD_LOCKTIME_VERIFY_FLAGS);
|
||||
mempool.removeForReorg(active_chainstate, STANDARD_LOCKTIME_VERIFY_FLAGS);
|
||||
// Re-limit mempool size, in case we added any transactions
|
||||
LimitMempoolSize(mempool, ::ChainstateActive().CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
||||
LimitMempoolSize(mempool, active_chainstate.CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2716,7 +2717,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
if (!DisconnectTip(state, chainparams, &disconnectpool)) {
|
||||
// This is likely a fatal error, but keep the mempool consistent,
|
||||
// just in case. Only remove from the mempool in this case.
|
||||
UpdateMempoolForReorg(m_mempool, disconnectpool, false);
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
|
||||
|
||||
// If we're unable to disconnect a block during normal operation,
|
||||
// then that is a failure of our local system -- we should abort
|
||||
|
@ -2760,7 +2761,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
// A system error occurred (disk space, database error, ...).
|
||||
// Make the mempool consistent with the current tip, just in case
|
||||
// any observers try to use it before shutdown.
|
||||
UpdateMempoolForReorg(m_mempool, disconnectpool, false);
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -2777,7 +2778,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
if (fBlocksDisconnected) {
|
||||
// If any blocks were disconnected, disconnectpool may be non empty. Add
|
||||
// any disconnected transactions back to the mempool.
|
||||
UpdateMempoolForReorg(m_mempool, disconnectpool, true);
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, true);
|
||||
}
|
||||
m_mempool.check(&CoinsTip());
|
||||
|
||||
|
@ -3014,7 +3015,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
|
|||
// transactions back to the mempool if disconnecting was successful,
|
||||
// and we're not doing a very deep invalidation (in which case
|
||||
// keeping the mempool up to date is probably futile anyway).
|
||||
UpdateMempoolForReorg(m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
|
||||
if (!ret) return false;
|
||||
assert(invalid_walk_tip->pprev == m_chain.Tip());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue