Skip to content

Commit af99643

Browse files
committed
Merge bitcoin#34054: net processing: Add ibd check before processing block for txdownloadman
e5f0613 net processing: Check if we are in ibd before processing block for txdownloadman (sedited) ce8b692 Add functional test exercising tx downloadman recently confirmed filter (Lőrinc) Pull request description: Calculating the rolling bloom filters for the txorphanage takes some CPU time from the scheduler thread. This can be observed for example in [this flamegraph](https://bitcoin-dev-tools.github.io/benchcoin/results/pr-172/20066462508/mainnet-default-instrumented-base-flamegraph.svg?x=920203898521&y=780), where handling the filter takes about 2.6% of total time (and most of the scheduler thread's time). During ibd the entries in the tx download bloom filter are just continuously rolled over and aren't consumed, since no mempool entries are created by incoming transactions from peers during ibd. The mempool does accept transactions via RPC, or the wallet at the time, however these don't interact with the orphanage and the txdownloadman, because adding anything to those is guarded by IsInitialBlockDownload() checks as well. We're usually latching ibd to false a few blocks before catching up to the tip, so this should also not significantly degrade the performance of the filter once fully caught up. ACKs for top commit: l0rinc: ACK e5f0613 instagibbs: ACK e5f0613 fjahr: Code review ACK e5f0613 Tree-SHA512: d667e677f5723c438cdf5b34f0f9c1ade7cc1b2e98530c23f14384514daa38217c4e7c3b756194b6831b590a487449c4514b52bf0fb461ae8083061722824270
2 parents 707ad46 + e5f0613 commit af99643

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/net_processing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,12 +2084,12 @@ void PeerManagerImpl::BlockConnected(
20842084
}
20852085

20862086
// The following task can be skipped since we don't maintain a mempool for
2087-
// the historical chainstate.
2088-
if (role.historical) {
2089-
return;
2087+
// the historical chainstate, or during ibd since we don't receive incoming
2088+
// transactions from peers into the mempool.
2089+
if (!role.historical && !m_chainman.IsInitialBlockDownload()) {
2090+
LOCK(m_tx_download_mutex);
2091+
m_txdownloadman.BlockConnected(pblock);
20902092
}
2091-
LOCK(m_tx_download_mutex);
2092-
m_txdownloadman.BlockConnected(pblock);
20932093
}
20942094

20952095
void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex)

test/functional/p2p_ibd_txrelay.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from decimal import Decimal
1212
import time
1313

14+
from test_framework.blocktools import create_block, create_coinbase
1415
from test_framework.messages import (
1516
CInv,
1617
COIN,
@@ -48,6 +49,12 @@ def run_test(self):
4849
self.wait_until(lambda: all(peer['minfeefilter'] == MAX_FEE_FILTER for peer in node.getpeerinfo()))
4950

5051
self.nodes[0].setmocktime(int(time.time()))
52+
self.log.info("Mine one old block so we stay in IBD, then remember its coinbase wtxid")
53+
block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(1), int(time.time()) - 2 * 24 * 60 * 60)
54+
block.solve()
55+
self.nodes[0].submitblock(block.serialize().hex())
56+
assert self.nodes[0].getblockchaininfo()['initialblockdownload']
57+
ibd_wtxid = int(self.nodes[0].getblock(f"{block.hash_int:064x}", 2)["tx"][0]["hash"], 16)
5158

5259
self.log.info("Check that nodes don't send getdatas for transactions while still in IBD")
5360
peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore())
@@ -82,6 +89,13 @@ def run_test(self):
8289
assert not node.getblockchaininfo()['initialblockdownload']
8390
self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo()))
8491

92+
self.log.info("Check that txs confirmed during IBD are not in the recently-confirmed filter once out of ibd")
93+
peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore())
94+
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=ibd_wtxid)]))
95+
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY)
96+
peer_inver.wait_for_getdata([ibd_wtxid])
97+
self.nodes[0].disconnect_p2ps()
98+
8599
self.log.info("Check that nodes process the same transaction, even when unsolicited, when no longer in IBD")
86100
peer_txer = self.nodes[0].add_p2p_connection(P2PInterface())
87101
with self.nodes[0].assert_debug_log(expected_msgs=["was not accepted"]):

0 commit comments

Comments
 (0)