test: Cover getprivatebroadcastinfo in p2p_private_broadcast
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 an RPC command called getprivatebroadcastinfo correctly reports private transaction broadcasts. There is no change to production code, no bug fix, and no security-relevant behavior change.
No action needed; this is a test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds coverage in test/functional/p2p_private_broadcast.py for the getprivatebroadcastinfo RPC. It verifies that a privately broadcast transaction appears in the RPC output with the expected txid, wtxid, hex, and peer metadata, and that the entry is removed once the transaction is received back via normal broadcast. No consensus, networking, or wallet code is modified.
Changed components
test/functional/p2p_private_broadcast.pyInspect captured patch +16 / −0
diff --git a/test/functional/p2p_private_broadcast.py b/test/functional/p2p_private_broadcast.py
index 49438417..97c90bf4 100755
--- a/test/functional/p2p_private_broadcast.py
+++ b/test/functional/p2p_private_broadcast.py
@@ -36,6 +36,7 @@ from test_framework.test_framework import (
)
from test_framework.util import (
assert_equal,
+ assert_greater_than_or_equal,
assert_not_equal,
assert_raises_rpc_error,
p2p_port,
@@ -301,6 +302,16 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
self.log.info(f"{label}: ok: outbound connection i={i} is private broadcast of txid={tx['txid']}")
broadcasts_done += 1
+ # Verify the tx we just observed is tracked in getprivatebroadcastinfo.
+ pbinfo = self.nodes[0].getprivatebroadcastinfo()
+ pending = [t for t in pbinfo["transactions"] if t["txid"] == tx["txid"] and t["wtxid"] == tx["wtxid"]]
+ assert_equal(len(pending), 1)
+ assert_equal(pending[0]["hex"].lower(), tx["hex"].lower())
+ peers = pending[0]["peers"]
+ assert len(peers) >= NUM_PRIVATE_BROADCAST_PER_TX
+ assert all("address" in p and "sent" in p for p in peers)
+ assert_greater_than_or_equal(sum(1 for p in peers if "received" in p), NUM_PRIVATE_BROADCAST_PER_TX)
+
def run_test(self):
tx_originator = self.nodes[0]
tx_receiver = self.nodes[1]
@@ -366,6 +377,11 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
self.log.info("Waiting for normal broadcast to another peer")
self.destinations[1]["node"].wait_for_inv([inv])
+ self.log.info("Checking getprivatebroadcastinfo no longer reports the transaction after it is received back")
+ pbinfo = tx_originator.getprivatebroadcastinfo()
+ pending = [t for t in pbinfo["transactions"] if t["txid"] == txs[0]["txid"] and t["wtxid"] == txs[0]["wtxid"]]
+ assert_equal(len(pending), 0)
+
self.log.info("Sending a transaction that is already in the mempool")
skip_destinations = len(self.destinations)
tx_originator.sendrawtransaction(hexstring=txs[0]["hex"], maxfeerate=0)
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.