test: validate behaviour of getpeerinfo last_inv_sequence and inv_to_send
What changed, and why it matters
This commit only adds new test code to Bitcoin Core. It extends an existing functional test to check that internal peer state fields (last_inv_sequence and inv_to_send) behave correctly when a transaction is announced. There is no change to production code, no bug fix, and no security-relevant behavior change.
No action needed; this is a benign test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds assertions to test/functional/p2p_leak_tx.py that pause mock time, send a self-transfer transaction, and verify getpeerinfo fields (last_inv_sequence, inv_to_send) and getrawmempool mempool_sequence before and after the INV announcement. It is purely a test-coverage addition.
Changed components
test/functional/p2p_leak_tx.pyInspect captured patch +17 / −0
diff --git a/test/functional/p2p_leak_tx.py b/test/functional/p2p_leak_tx.py
index a1a00751..42e586fc 100755
--- a/test/functional/p2p_leak_tx.py
+++ b/test/functional/p2p_leak_tx.py
@@ -12,6 +12,7 @@ from test_framework.util import (
)
from test_framework.wallet import MiniWallet
+import time
class P2PNode(P2PDataStore):
def on_inv(self, msg):
@@ -36,8 +37,24 @@ class P2PLeakTxTest(BitcoinTestFramework):
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)
+
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)
+ pi = self.gen_node.getpeerinfo()[0]
+ assert_equal(rawmp["mempool_sequence"], 2) # no mempool update
+ assert_equal(pi["last_inv_sequence"], 2) # announced the current mempool
+ assert_equal(pi["inv_to_send"], 0) # nothing left in the queue
+
want_tx = msg_getdata(inv=inbound_peer.last_message.get("inv").inv)
self.generate(self.gen_node, 1)
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.