mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
validation: Pass in chainstate to UpdateMempoolForReorg
This commit is contained in:
parent
7142018812
commit
0a9a24d8c7
@ -373,10 +373,11 @@ static bool IsCurrentForFeeEstimation(CChainState& active_chainstate) EXCLUSIVE_
|
|||||||
* and instead just erase from the mempool as needed.
|
* 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(cs_main);
|
||||||
AssertLockHeld(mempool.cs);
|
AssertLockHeld(mempool.cs);
|
||||||
|
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||||
std::vector<uint256> vHashUpdate;
|
std::vector<uint256> vHashUpdate;
|
||||||
// disconnectpool's insertion_order index sorts the entries from
|
// disconnectpool's insertion_order index sorts the entries from
|
||||||
// oldest to newest, but the oldest entry will be the last tx from the
|
// 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()) {
|
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
|
||||||
// ignore validation errors in resurrected transactions
|
// ignore validation errors in resurrected transactions
|
||||||
if (!fAddToMempool || (*it)->IsCoinBase() ||
|
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
|
// If the transaction doesn't make it in to the mempool, remove any
|
||||||
// transactions that depend on it (which would now be orphans).
|
// transactions that depend on it (which would now be orphans).
|
||||||
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
|
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
|
||||||
@ -406,9 +407,9 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
|
|||||||
mempool.UpdateTransactionsFromBlock(vHashUpdate);
|
mempool.UpdateTransactionsFromBlock(vHashUpdate);
|
||||||
|
|
||||||
// We also need to remove any now-immature transactions
|
// 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
|
// 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)) {
|
if (!DisconnectTip(state, chainparams, &disconnectpool)) {
|
||||||
// This is likely a fatal error, but keep the mempool consistent,
|
// This is likely a fatal error, but keep the mempool consistent,
|
||||||
// just in case. Only remove from the mempool in this case.
|
// 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,
|
// If we're unable to disconnect a block during normal operation,
|
||||||
// then that is a failure of our local system -- we should abort
|
// 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, ...).
|
// A system error occurred (disk space, database error, ...).
|
||||||
// Make the mempool consistent with the current tip, just in case
|
// Make the mempool consistent with the current tip, just in case
|
||||||
// any observers try to use it before shutdown.
|
// any observers try to use it before shutdown.
|
||||||
UpdateMempoolForReorg(m_mempool, disconnectpool, false);
|
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2777,7 +2778,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||||||
if (fBlocksDisconnected) {
|
if (fBlocksDisconnected) {
|
||||||
// If any blocks were disconnected, disconnectpool may be non empty. Add
|
// If any blocks were disconnected, disconnectpool may be non empty. Add
|
||||||
// any disconnected transactions back to the mempool.
|
// any disconnected transactions back to the mempool.
|
||||||
UpdateMempoolForReorg(m_mempool, disconnectpool, true);
|
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, true);
|
||||||
}
|
}
|
||||||
m_mempool.check(&CoinsTip());
|
m_mempool.check(&CoinsTip());
|
||||||
|
|
||||||
@ -3014,7 +3015,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
|
|||||||
// transactions back to the mempool if disconnecting was successful,
|
// transactions back to the mempool if disconnecting was successful,
|
||||||
// and we're not doing a very deep invalidation (in which case
|
// and we're not doing a very deep invalidation (in which case
|
||||||
// keeping the mempool up to date is probably futile anyway).
|
// 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;
|
if (!ret) return false;
|
||||||
assert(invalid_walk_tip->pprev == m_chain.Tip());
|
assert(invalid_walk_tip->pprev == m_chain.Tip());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user