test: fix addr relay test silent pass and wrong peerinfo index
What changed, and why it matters
This commit fixes bugs in a Bitcoin Core functional test script, not in the actual Bitcoin network node software. The test was checking address relay behavior using the wrong peer index and was silently passing because a setup step was missing. The fix moves an empty address message earlier and corrects which peer's statistics are checked. There is no change to production code and no security risk to running nodes.
No security action required. This is a test-only fix. Reviewers may optionally verify the corrected test now fails appropriately when address relay behavior regresses.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies test/functional/p2p_addr_relay.py only. It moves inbound_peer.send_and_ping(msg_addr()) before the outbound peer sends addresses, so address relay is initialized on the inbound connection before the relay check. It also updates peerinfo index references from [1] to [2] to match the actual peer list after adding the blackhole peer, and adds an extra assertion (addr_received() == False). These are test-harness corrections; no consensus, networking, or wallet code is touched.
Changed components
test/functional/p2p_addr_relay.pyInspect captured patch +7 / −5
diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py
index f89ac701..33052fa2 100755
--- a/test/functional/p2p_addr_relay.py
+++ b/test/functional/p2p_addr_relay.py
@@ -178,6 +178,9 @@ class AddrTest(BitcoinTestFramework):
self.log.info('Check relay of addresses received from outbound peers')
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True, send_getaddr=False))
+ # Send an empty ADDR message to initialize address relay on this connection.
+ inbound_peer.send_and_ping(msg_addr())
+
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay")
msg = self.setup_addr_msg(2)
self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
@@ -188,9 +191,6 @@ class AddrTest(BitcoinTestFramework):
# of the outbound peer which is often sent before the GETADDR response.
assert_equal(inbound_peer.num_ipv4_received, 0)
- # Send an empty ADDR message to initialize address relay on this connection.
- inbound_peer.send_and_ping(msg_addr())
-
self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
msg2 = self.setup_addr_msg(2)
self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
@@ -248,8 +248,9 @@ class AddrTest(BitcoinTestFramework):
blackhole_peer.send_and_ping(msg_addr())
# Confirm node has now received addr-related messages from blackhole peer
- assert_greater_than(self.sum_addr_messages(peerinfo[1]['bytesrecv_per_msg']), 0)
- assert_equal(self.nodes[0].getpeerinfo()[2]['addr_relay_enabled'], True)
+ peerinfo = self.nodes[0].getpeerinfo()
+ assert_greater_than(self.sum_addr_messages(peerinfo[2]['bytesrecv_per_msg']), 0)
+ assert_equal(peerinfo[2]['addr_relay_enabled'], True)
msg = self.setup_addr_msg(2)
self.send_addr_msg(addr_source, msg, [receiver_peer, blackhole_peer])
@@ -280,6 +281,7 @@ class AddrTest(BitcoinTestFramework):
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
inbound_peer.sync_with_ping()
assert_equal(inbound_peer.getaddr_received(), False)
+ assert_equal(inbound_peer.addr_received(), False)
self.log.info('Check that we answer getaddr messages only from inbound peers')
# Add some addresses to addrman
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.