mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
update recent_rejects filters on ActiveTipChange
Resetting m_recent_rejects once per block is more efficient than comparing hashRecentRejectsChainTip with the chain tip every time we call AlreadyHaveTx. We keep hashRecentRejectsChainTip for now to assert that updates happen correctly; it is removed in the next commit.
This commit is contained in:
parent
36f170d879
commit
18a4355250
1 changed files with 23 additions and 1 deletions
|
@ -489,6 +489,8 @@ public:
|
|||
CTxMemPool& pool, node::Warnings& warnings, Options opts);
|
||||
|
||||
/** Overridden from CValidationInterface. */
|
||||
void ActiveTipChange(const CBlockIndex* new_tip, bool) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
|
||||
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
|
||||
void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override
|
||||
|
@ -2074,6 +2076,22 @@ void PeerManagerImpl::StartScheduledTasks(CScheduler& scheduler)
|
|||
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
|
||||
}
|
||||
|
||||
void PeerManagerImpl::ActiveTipChange(const CBlockIndex* new_tip, bool is_ibd)
|
||||
{
|
||||
AssertLockNotHeld(m_mempool.cs);
|
||||
AssertLockNotHeld(m_tx_download_mutex);
|
||||
|
||||
if (!is_ibd) {
|
||||
LOCK(m_tx_download_mutex);
|
||||
// If the chain tip has changed, previously rejected transactions might now be valid, e.g. due
|
||||
// to a timelock. Reset the rejection filters to give those transactions another chance if we
|
||||
// see them again.
|
||||
m_recent_rejects.reset();
|
||||
m_recent_rejects_reconsiderable.reset();
|
||||
hashRecentRejectsChainTip = new_tip->GetBlockHash();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evict orphan txn pool entries based on a newly connected
|
||||
* block, remember the recently confirmed transactions, and delete tracked
|
||||
|
@ -2277,7 +2295,11 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
|
|||
AssertLockHeld(::cs_main);
|
||||
AssertLockHeld(m_tx_download_mutex);
|
||||
|
||||
if (m_chainman.ActiveChain().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
|
||||
// Since recent_rejects is updated whenever the tip changes, and hashRecentRejectsChainTip is
|
||||
// not set until the first time it is called outside of IBD, hashRecentRejectsChainTip should
|
||||
// always be up to date with the current chain tip.
|
||||
if (!Assume(hashRecentRejectsChainTip == uint256::ZERO ||
|
||||
hashRecentRejectsChainTip == m_chainman.ActiveChain().Tip()->GetBlockHash())) {
|
||||
// If the chain tip has changed previously rejected transactions
|
||||
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
|
||||
// or a double-spend. Reset the rejects filter and give those
|
||||
|
|
Loading…
Add table
Reference in a new issue