Skip to content

Commit 18a4355

Browse files
committed
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.
1 parent 36f170d commit 18a4355

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/net_processing.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ class PeerManagerImpl final : public PeerManager
489489
CTxMemPool& pool, node::Warnings& warnings, Options opts);
490490

491491
/** Overridden from CValidationInterface. */
492+
void ActiveTipChange(const CBlockIndex* new_tip, bool) override
493+
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
492494
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
493495
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
494496
void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override
@@ -2074,6 +2076,22 @@ void PeerManagerImpl::StartScheduledTasks(CScheduler& scheduler)
20742076
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
20752077
}
20762078

2079+
void PeerManagerImpl::ActiveTipChange(const CBlockIndex* new_tip, bool is_ibd)
2080+
{
2081+
AssertLockNotHeld(m_mempool.cs);
2082+
AssertLockNotHeld(m_tx_download_mutex);
2083+
2084+
if (!is_ibd) {
2085+
LOCK(m_tx_download_mutex);
2086+
// If the chain tip has changed, previously rejected transactions might now be valid, e.g. due
2087+
// to a timelock. Reset the rejection filters to give those transactions another chance if we
2088+
// see them again.
2089+
m_recent_rejects.reset();
2090+
m_recent_rejects_reconsiderable.reset();
2091+
hashRecentRejectsChainTip = new_tip->GetBlockHash();
2092+
}
2093+
}
2094+
20772095
/**
20782096
* Evict orphan txn pool entries based on a newly connected
20792097
* block, remember the recently confirmed transactions, and delete tracked
@@ -2277,7 +2295,11 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
22772295
AssertLockHeld(::cs_main);
22782296
AssertLockHeld(m_tx_download_mutex);
22792297

2280-
if (m_chainman.ActiveChain().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
2298+
// Since recent_rejects is updated whenever the tip changes, and hashRecentRejectsChainTip is
2299+
// not set until the first time it is called outside of IBD, hashRecentRejectsChainTip should
2300+
// always be up to date with the current chain tip.
2301+
if (!Assume(hashRecentRejectsChainTip == uint256::ZERO ||
2302+
hashRecentRejectsChainTip == m_chainman.ActiveChain().Tip()->GetBlockHash())) {
22812303
// If the chain tip has changed previously rejected transactions
22822304
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
22832305
// or a double-spend. Reset the rejects filter and give those

0 commit comments

Comments
 (0)