From 7ee8c0abc629f0658b6c36f36b5da11c51cbb39d Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Fri, 6 Mar 2026 10:25:20 +0530 Subject: [PATCH] test: protect outbound connection from eviction in getaddr_test since we're bumping mocktime more than CHAIN_SYNC_TIMEOUT = 20 * 60, it's possible for disconnections like this to happen in the test: $ test/functional/p2p_addr_relay.py --randomseed=7758649581790797022 ... TestFramework (INFO): Check that we answer getaddr messages only once per connection TestFramework.p2p (WARNING): Connection lost to 127.0.0.1:58829 due to [Errno 54] Connection reset by peer ... --- test/functional/p2p_addr_relay.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py index 33052fa25a8..eea8ee5351c 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()