test: increase timeout in p2p_leak_tx.py
What changed, and why it matters
This commit only changes a test script used during Bitcoin Core's automated testing. It makes the test more reliable by increasing a timeout, using mock time to run faster, and fixing a minor method signature mismatch. There is no change to the actual Bitcoin network software that users run, so it has no security impact on real Bitcoin nodes or users.
No security action needed. This is a routine test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies test/functional/p2p_leak_tx.py. It increases the effective wait time for an inventory announcement by advancing mocktime in 120-second increments, and fixes the P2PNode.on_inv signature from ‘msg’ to ‘message’ to match the framework’s expected callback signature. The commit message explains the change as preventing a rare (~1e-6 probability) test flake caused by the exponential NextInvToInBounds timer exceeding 60 seconds. No production code is touched.
Changed components
test/functional/p2p_leak_tx.pyInspect captured patch +10 / −4
diff --git a/test/functional/p2p_leak_tx.py b/test/functional/p2p_leak_tx.py
index 42e586fc..29b00397 100755
--- a/test/functional/p2p_leak_tx.py
+++ b/test/functional/p2p_leak_tx.py
@@ -15,7 +15,7 @@ from test_framework.wallet import MiniWallet
import time
class P2PNode(P2PDataStore):
- def on_inv(self, msg):
+ def on_inv(self, message):
pass
@@ -26,6 +26,7 @@ class P2PLeakTxTest(BitcoinTestFramework):
def run_test(self):
self.gen_node = self.nodes[0] # The block and tx generating node
self.miniwallet = MiniWallet(self.gen_node)
+ self.mocktime = int(time.time())
self.test_tx_in_block()
self.test_notfound_on_replaced_tx()
@@ -33,20 +34,20 @@ class P2PLeakTxTest(BitcoinTestFramework):
def test_tx_in_block(self):
self.log.info("Check that a transaction in the last block is uploaded (beneficial for compact block relay)")
+ self.gen_node.setmocktime(self.mocktime)
inbound_peer = self.gen_node.add_p2p_connection(P2PNode())
self.log.debug("Generate transaction and block")
inbound_peer.last_message.pop("inv", None)
- self.gen_node.setmocktime(int(time.time())) # pause time based activities
wtxid = self.miniwallet.send_self_transfer(from_node=self.gen_node)["wtxid"]
rawmp = self.gen_node.getrawmempool(False, True)
pi = self.gen_node.getpeerinfo()[0]
assert_equal(rawmp["mempool_sequence"], 2) # our tx cause mempool activity
assert_equal(pi["last_inv_sequence"], 1) # that is after the last inv
assert_equal(pi["inv_to_send"], 1) # and our tx has been queued
- self.gen_node.setmocktime(0)
-
+ self.mocktime += 120
+ self.gen_node.setmocktime(self.mocktime)
inbound_peer.wait_until(lambda: "inv" in inbound_peer.last_message and inbound_peer.last_message.get("inv").inv[0].hash == int(wtxid, 16))
rawmp = self.gen_node.getrawmempool(False, True)
@@ -65,15 +66,20 @@ class P2PLeakTxTest(BitcoinTestFramework):
def test_notfound_on_replaced_tx(self):
self.gen_node.disconnect_p2ps()
+ self.gen_node.setmocktime(self.mocktime)
inbound_peer = self.gen_node.add_p2p_connection(P2PTxInvStore())
self.log.info("Transaction tx_a is broadcast")
tx_a = self.miniwallet.send_self_transfer(from_node=self.gen_node)
+ self.mocktime += 120
+ self.gen_node.setmocktime(self.mocktime)
inbound_peer.wait_for_broadcast(txns=[tx_a["wtxid"]])
tx_b = tx_a["tx"]
tx_b.vout[0].nValue -= 9000
self.gen_node.sendrawtransaction(tx_b.serialize().hex())
+ self.mocktime += 120
+ self.gen_node.setmocktime(self.mocktime)
inbound_peer.wait_until(lambda: "tx" in inbound_peer.last_message and inbound_peer.last_message.get("tx").tx.wtxid_hex == tx_b.wtxid_hex)
self.log.info("Re-request of tx_a after replacement is answered with notfound")
Why this scored 15/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.