test: Document rare failure in test_inv_block better
What changed, and why it matters
This commit only updates comments and test-only assertions in a Bitcoin Core functional test file. It documents why a test can rarely fail and adds checks to make the test more robust. There is no change to production code, no security fix, and no vulnerability.
No security action needed. Treat as a normal test-maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies test/functional/p2p_tx_download.py. It improves the comment explaining that node 0 views the connection as inbound and may not announce the transaction within the timeout. It adds assertions about inbound flag and inv_to_send count, forces a SendMessages call via sync_with_ping(), and fixes an indentation issue in an unrelated assertion block. No consensus, networking, or wallet code is changed.
Changed components
test/functional/p2p_tx_download.pyInspect captured patch +9 / −3
diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py
index a46b6a6b..b910bda3 100755
--- a/test/functional/p2p_tx_download.py
+++ b/test/functional/p2p_tx_download.py
@@ -116,17 +116,23 @@ class TxDownloadTest(BitcoinTestFramework):
self.nodes[0].sendrawtransaction(tx['hex'])
# Since node 1 is connected outbound to an honest peer (node 0), it
- # should get the tx within a timeout. (Assuming that node 0
- # announced the tx within the timeout)
+ # should get the tx within a timeout.
+ # However, node 0 sees the same connection as inbound, so it may not
+ # announce the tx within the timeout.
# The timeout is the sum of
# * the worst case until the tx is first requested from an inbound
# peer, plus
# * the first time it is re-requested from the outbound peer, plus
# * 2 seconds to avoid races
+ assert_equal(self.nodes[0].getpeerinfo()[0]["inbound"], True)
+ assert_equal(self.nodes[0].getpeerinfo()[0]["inv_to_send"], 1)
assert_equal(self.nodes[1].getpeerinfo()[0]['inbound'], False)
timeout = 2 + NONPREF_PEER_TX_DELAY + GETDATA_TX_INTERVAL
self.log.info("Tx should be received at node 1 after {} seconds".format(timeout))
self.nodes[0].bumpmocktime(timeout)
+ # Use an unrelated peer to ensure node 0 calls `SendMessages` at least once
+ self.nodes[0].p2ps[0].sync_with_ping()
+ assert_equal(self.nodes[0].getpeerinfo()[0]['inv_to_send'], 0) # May fail rarely, retry the test
self.sync_mempools()
self.nodes[0].setmocktime(0)
@@ -263,7 +269,7 @@ class TxDownloadTest(BitcoinTestFramework):
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY)
with p2p_lock:
for peer in non_pref_peers:
- assert_equal(peer.tx_getdata_count, 0)
+ assert_equal(peer.tx_getdata_count, 0)
# Now add another outbound (preferred) which is immediately ready for consideration
# upon advertisement
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.