test: protect outbound connection from eviction in getaddr_test
What changed, and why it matters
This commit fixes a flaky Bitcoin Core functional test. The test was sometimes failing because the node would disconnect an outbound peer after the test advanced its internal clock too far. The fix makes the test announce the latest block header to the peer, which tells the node to protect that peer from disconnection. It is purely a test change and does not affect real network behavior or user funds.
No security action needed. This is a test-only reliability improvement. Reviewers can verify the test passes deterministically with the referenced random seed and others.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In test/functional/p2p_addr_relay.py, the test advances mocktime by more than CHAIN_SYNC_TIMEOUT (20 minutes). Under Bitcoin Core’s eviction logic, an outbound peer that appears out of sync can be disconnected. The patch prevents spurious disconnections during the test by having the outbound peers announce the current best block header via a headers message, which marks them as protected from eviction. Imports for CBlockHeader, msg_headers, and from_hex are added to support this.
Changed components
test/functional/p2p_addr_relay.pyInspect captured patch +8 / −0
diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py
index 33052fa2..eea8ee53 100755
--- a/test/functional/p2p_addr_relay.py
+++ b/test/functional/p2p_addr_relay.py
@@ -11,9 +11,12 @@ import time
from test_framework.messages import (
CAddress,
+ CBlockHeader,
msg_addr,
msg_getaddr,
+ msg_headers,
msg_verack,
+ from_hex,
)
from test_framework.p2p import (
P2PInterface,
@@ -273,10 +276,15 @@ class AddrTest(BitcoinTestFramework):
full_outbound_peer.sync_with_ping()
assert full_outbound_peer.getaddr_received()
+ # to avoid the node evicting the outbound peer, protect it by announcing the most recent header to it
+ tip_header = from_hex(CBlockHeader(), self.nodes[0].getblockheader(self.nodes[0].getbestblockhash(), False))
+ full_outbound_peer.send_and_ping(msg_headers([tip_header]))
+
self.log.info('Check that we do not send a getaddr message to a block-relay-only or inbound peer')
block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only")
block_relay_peer.sync_with_ping()
assert_equal(block_relay_peer.getaddr_received(), False)
+ block_relay_peer.send_and_ping(msg_headers([tip_header]))
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
inbound_peer.sync_with_ping()
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.