From ce8b692897f6aacbe936fe2220e85f23cd83cbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Fri, 20 Feb 2026 17:16:49 +0100 Subject: [PATCH 1/2] Add functional test exercising tx downloadman recently confirmed filter This documents existing behaviour before the change in the following commit: The bloom filter maintained by the txdownload manager tracks recently confirmed transasctions even during ibd. If a peer sends an INV once IBD is over it does not re-request them. Co-authored-by: sedited --- test/functional/p2p_ibd_txrelay.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/functional/p2p_ibd_txrelay.py b/test/functional/p2p_ibd_txrelay.py index 423c2a07a7ec..a622554a0c31 100755 --- a/test/functional/p2p_ibd_txrelay.py +++ b/test/functional/p2p_ibd_txrelay.py @@ -11,6 +11,7 @@ from decimal import Decimal import time +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( CInv, COIN, @@ -48,6 +49,12 @@ def run_test(self): self.wait_until(lambda: all(peer['minfeefilter'] == MAX_FEE_FILTER for peer in node.getpeerinfo())) self.nodes[0].setmocktime(int(time.time())) + self.log.info("Mine one old block so we stay in IBD, then remember its coinbase wtxid") + block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(1), int(time.time()) - 2 * 24 * 60 * 60) + block.solve() + self.nodes[0].submitblock(block.serialize().hex()) + assert self.nodes[0].getblockchaininfo()['initialblockdownload'] + ibd_wtxid = int(self.nodes[0].getblock(f"{block.hash_int:064x}", 2)["tx"][0]["hash"], 16) self.log.info("Check that nodes don't send getdatas for transactions while still in IBD") peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore()) @@ -82,6 +89,15 @@ def run_test(self): assert not node.getblockchaininfo()['initialblockdownload'] self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo())) + self.log.info("Check that txs confirmed during IBD are in the recently-confirmed filter once out of ibd") + peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore()) + peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=ibd_wtxid)])) + self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY) + peer_inver.sync_with_ping() + with p2p_lock: + assert ibd_wtxid not in peer_inver.getdata_requests + self.nodes[0].disconnect_p2ps() + self.log.info("Check that nodes process the same transaction, even when unsolicited, when no longer in IBD") peer_txer = self.nodes[0].add_p2p_connection(P2PInterface()) with self.nodes[0].assert_debug_log(expected_msgs=["was not accepted"]): From e5f0613503b6973dbc886eba8e999f208d84853b Mon Sep 17 00:00:00 2001 From: sedited Date: Fri, 28 Nov 2025 23:05:17 +0100 Subject: [PATCH 2/2] net processing: Check if we are in ibd before processing block for txdownloadman MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids wasting work on calculating bloom filters that aren't consumed during ibd and continuously re-calculated as now blocks get validated. Also update the functional test to document that transactions would now be requested again once out of IBD. Co-authored-by: Lőrinc --- src/net_processing.cpp | 10 +++++----- test/functional/p2p_ibd_txrelay.py | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 16b4735e5ef6..0ec1103e5a05 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2054,12 +2054,12 @@ void PeerManagerImpl::BlockConnected( } // The following task can be skipped since we don't maintain a mempool for - // the historical chainstate. - if (role.historical) { - return; + // the historical chainstate, or during ibd since we don't receive incoming + // transactions from peers into the mempool. + if (!role.historical && !m_chainman.IsInitialBlockDownload()) { + LOCK(m_tx_download_mutex); + m_txdownloadman.BlockConnected(pblock); } - LOCK(m_tx_download_mutex); - m_txdownloadman.BlockConnected(pblock); } void PeerManagerImpl::BlockDisconnected(const std::shared_ptr &block, const CBlockIndex* pindex) diff --git a/test/functional/p2p_ibd_txrelay.py b/test/functional/p2p_ibd_txrelay.py index a622554a0c31..fe70d04626e7 100755 --- a/test/functional/p2p_ibd_txrelay.py +++ b/test/functional/p2p_ibd_txrelay.py @@ -89,13 +89,11 @@ def run_test(self): assert not node.getblockchaininfo()['initialblockdownload'] self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo())) - self.log.info("Check that txs confirmed during IBD are in the recently-confirmed filter once out of ibd") + self.log.info("Check that txs confirmed during IBD are not in the recently-confirmed filter once out of ibd") peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore()) peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=ibd_wtxid)])) self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY) - peer_inver.sync_with_ping() - with p2p_lock: - assert ibd_wtxid not in peer_inver.getdata_requests + peer_inver.wait_for_getdata([ibd_wtxid]) self.nodes[0].disconnect_p2ps() self.log.info("Check that nodes process the same transaction, even when unsolicited, when no longer in IBD")