Merge bitcoin/bitcoin#33448: net/rpc: Report inv information for debugging

2738b63e02 test: validate behaviour of getpeerinfo last_inv_sequence and inv_to_send (Anthony Towns)
77b2ebb811 rpc/net: report per-peer last_inv_sequence (Anthony Towns)
adefb51c54 rpc/net: add per-peer inv_to_send sizes (Anthony Towns)

Pull request description:

  Adds per-peer entries to `getpeerinfo` for the size of the inv_to_send queue and the mempool sequence number as at the last INV. Can be helpful for debugging tx relay performance and privacy/fingerprinting issues.

ACKs for top commit:
  sipa:
    utACK 2738b63e02
  instagibbs:
    ACK 2738b63e02

Tree-SHA512: e3c9c52e8e38b099d405a177ffba6783c5821cc5ce1432b98218843e00906986ce2141dcd5b04a67006c328211a672e519fa3390e012688499bfc9ac99767599
This commit is contained in:
merge-script
2025-09-23 10:29:23 -04:00
5 changed files with 33 additions and 4 deletions

View File

@@ -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)

View File

@@ -166,6 +166,8 @@ class NetTest(BitcoinTestFramework):
"permissions": [],
"presynced_headers": -1,
"relaytxes": False,
"inv_to_send": 0,
"last_inv_sequence": 0,
"services": "0000000000000000",
"servicesnames": [],
"session_id": "" if not self.options.v2transport else no_version_peer.v2_state.peer['session_id'].hex(),