Skip to content

Commit 1b5cbf7

Browse files
committed
Merge bitcoin/bitcoin#28144: test: fix intermittent failure in p2p_getaddr_caching.py
8a20f76 test: drop duplicate getaddrs from p2p_getaddr_caching (Martin Zumsande) feb0096 test: fix intermittent failure in p2p_getaddr_caching (Martin Zumsande) Pull request description: Fixes #28133 In the consistency check, it's not enough to check that our address/port is unique, only the combination of source and target must be unique. Otherwise, the OS may reuse ports for connections to different `-addrbind`, which was happening in the failed runs. While at it, the second commit cleans up duplicate `getaddr` messages in `p2p_getaddr_caching.py` that do nothing but generate `Ignoring repeated "getaddr"` log messages (and cleans up some whitespace the python linter complains about). ACKs for top commit: vasild: ACK 8a20f76 Tree-SHA512: eabe4727d7887f729074076f6333a918bba8cb34b8e3baaa83f167b441b0daa24f7c4824abcf03a9538a2ef14b2d826ff19aeffcb93a6c20735253a9678aac9c
2 parents eb95368 + 8a20f76 commit 1b5cbf7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

test/functional/p2p_getaddr_caching.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import time
88

9-
from test_framework.messages import msg_getaddr
109
from test_framework.p2p import (
1110
P2PInterface,
1211
p2p_lock
@@ -21,6 +20,7 @@
2120
MAX_ADDR_TO_SEND = 1000
2221
MAX_PCT_ADDR_TO_SEND = 23
2322

23+
2424
class AddrReceiver(P2PInterface):
2525

2626
def __init__(self):
@@ -70,11 +70,8 @@ def run_test(self):
7070
cur_mock_time = int(time.time())
7171
for i in range(N):
7272
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
73-
addr_receiver_local.send_and_ping(msg_getaddr())
7473
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
75-
addr_receiver_onion1.send_and_ping(msg_getaddr())
7674
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
77-
addr_receiver_onion2.send_and_ping(msg_getaddr())
7875

7976
# Trigger response
8077
cur_mock_time += 5 * 60
@@ -105,11 +102,8 @@ def run_test(self):
105102

106103
self.log.info('After time passed, see a new response to addr request')
107104
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
108-
addr_receiver_local.send_and_ping(msg_getaddr())
109105
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
110-
addr_receiver_onion1.send_and_ping(msg_getaddr())
111106
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
112-
addr_receiver_onion2.send_and_ping(msg_getaddr())
113107

114108
# Trigger response
115109
cur_mock_time += 5 * 60
@@ -123,5 +117,6 @@ def run_test(self):
123117
assert set(last_response_on_onion_bind1) != set(addr_receiver_onion1.get_received_addrs())
124118
assert set(last_response_on_onion_bind2) != set(addr_receiver_onion2.get_received_addrs())
125119

120+
126121
if __name__ == '__main__':
127122
AddrTest().main()

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,11 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
649649
p2p_conn.sync_with_ping()
650650

651651
# Consistency check that the node received our user agent string.
652-
# Find our connection in getpeerinfo by our address:port, as it is unique.
652+
# Find our connection in getpeerinfo by our address:port and theirs, as this combination is unique.
653653
sockname = p2p_conn._transport.get_extra_info("socket").getsockname()
654654
our_addr_and_port = f"{sockname[0]}:{sockname[1]}"
655-
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port]
655+
dst_addr_and_port = f"{p2p_conn.dstaddr}:{p2p_conn.dstport}"
656+
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port and peer["addrbind"] == dst_addr_and_port]
656657
assert_equal(len(info), 1)
657658
assert_equal(info[0]["subver"], P2P_SUBVERSION)
658659

0 commit comments

Comments
 (0)