Skip to content

Commit eca2e43

Browse files
committed
Merge bitcoin#28632: test: make python p2p not send getaddr on incoming connections
9cfc1c9 test: check that we don't send a getaddr msg to an inbound peer (Martin Zumsande) 88c33c6 test: make python p2p not send getaddr messages when it's being connected to (Martin Zumsande) Pull request description: `bitcoind` nodes send `getaddr` messages only to outbound nodes (and ignore `getaddr` received by outgoing connections). The python p2p node should mirror this behavior by not sending a `getaddr` message when it is not the initiator of the connection. This is currently causing several unnecessary messages being sent and then ignored (`Ignoring "getaddr" from outbound-full-relay connection.`) in tests like `p2p_add_connections.py`. ACKs for top commit: pinheadmz: concept ACK 9cfc1c9 pablomartin4btc: re ACK 9cfc1c9 BrandonOdiwuor: re ACK 9cfc1c9 Tree-SHA512: 812bec5d8a4828b4384d4cdd4362d6eec09acb2363e888f2b3e3bf8b925e0e17f15e13dc297d6b616c68b93ace9ede7245b07b405d3f5f8eada98350f74230dc
2 parents 4733de3 + 9cfc1c9 commit eca2e43

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

test/functional/p2p_addr_relay.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,16 @@ def getaddr_tests(self):
270270
full_outbound_peer.sync_with_ping()
271271
assert full_outbound_peer.getaddr_received()
272272

273-
self.log.info('Check that we do not send a getaddr message upon connecting to a block-relay-only peer')
273+
self.log.info('Check that we do not send a getaddr message to a block-relay-only or inbound peer')
274274
block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only")
275275
block_relay_peer.sync_with_ping()
276276
assert_equal(block_relay_peer.getaddr_received(), False)
277277

278-
self.log.info('Check that we answer getaddr messages only from inbound peers')
279278
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
280279
inbound_peer.sync_with_ping()
280+
assert_equal(inbound_peer.getaddr_received(), False)
281281

282+
self.log.info('Check that we answer getaddr messages only from inbound peers')
282283
# Add some addresses to addrman
283284
for i in range(1000):
284285
first_octet = i >> 8

test/functional/test_framework/p2p.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ def on_version(self, message):
456456
self.send_message(msg_verack())
457457
self.nServices = message.nServices
458458
self.relay = message.relay
459-
self.send_message(msg_getaddr())
459+
if self.p2p_connected_to_node:
460+
self.send_message(msg_getaddr())
460461

461462
# Connection helper methods
462463

test/functional/test_framework/test_node.py

+2
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
644644
if 'dstaddr' not in kwargs:
645645
kwargs['dstaddr'] = '127.0.0.1'
646646

647+
p2p_conn.p2p_connected_to_node = True
647648
p2p_conn.peer_connect(**kwargs, net=self.chain, timeout_factor=self.timeout_factor)()
648649
self.p2ps.append(p2p_conn)
649650
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
@@ -689,6 +690,7 @@ def addconnection_callback(address, port):
689690
self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type))
690691
self.addconnection('%s:%d' % (address, port), connection_type)
691692

693+
p2p_conn.p2p_connected_to_node = False
692694
p2p_conn.peer_accept_connection(connect_cb=addconnection_callback, connect_id=p2p_idx + 1, net=self.chain, timeout_factor=self.timeout_factor, **kwargs)()
693695

694696
if connection_type == "feeler":

0 commit comments

Comments
 (0)