Skip to content

Commit bf5d74b

Browse files
fanquakevijaydasmp
authored andcommitted
Merge 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 bitcoin#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 Fixing Linting error - 'time' module imported but not used
1 parent d167e7d commit bf5d74b

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

test/functional/p2p_getaddr_caching.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test addr response caching"""
66

7-
from test_framework.messages import msg_getaddr
87
from test_framework.p2p import (
98
P2PInterface,
109
p2p_lock
@@ -19,6 +18,7 @@
1918
MAX_ADDR_TO_SEND = 1000
2019
MAX_PCT_ADDR_TO_SEND = 23
2120

21+
2222
class AddrReceiver(P2PInterface):
2323

2424
def __init__(self):
@@ -68,11 +68,8 @@ def run_test(self):
6868
cur_mock_time = self.mocktime
6969
for i in range(N):
7070
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
71-
addr_receiver_local.send_and_ping(msg_getaddr())
7271
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
73-
addr_receiver_onion1.send_and_ping(msg_getaddr())
7472
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
75-
addr_receiver_onion2.send_and_ping(msg_getaddr())
7673

7774
# Trigger response
7875
cur_mock_time += 5 * 60
@@ -103,11 +100,8 @@ def run_test(self):
103100

104101
self.log.info('After time passed, see a new response to addr request')
105102
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
106-
addr_receiver_local.send_and_ping(msg_getaddr())
107103
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
108-
addr_receiver_onion1.send_and_ping(msg_getaddr())
109104
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
110-
addr_receiver_onion2.send_and_ping(msg_getaddr())
111105

112106
# Trigger response
113107
cur_mock_time += 5 * 60
@@ -121,5 +115,6 @@ def run_test(self):
121115
assert(set(last_response_on_onion_bind1) != set(addr_receiver_onion1.get_received_addrs()))
122116
assert(set(last_response_on_onion_bind2) != set(addr_receiver_onion2.get_received_addrs()))
123117

118+
124119
if __name__ == '__main__':
125120
AddrTest().main()

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,11 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru
713713
p2p_conn.sync_with_ping()
714714

715715
# Consistency check that the node received our user agent string.
716-
# Find our connection in getpeerinfo by our address:port, as it is unique.
716+
# Find our connection in getpeerinfo by our address:port and theirs, as this combination is unique.
717717
sockname = p2p_conn._transport.get_extra_info("socket").getsockname()
718718
our_addr_and_port = f"{sockname[0]}:{sockname[1]}"
719-
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port]
719+
dst_addr_and_port = f"{p2p_conn.dstaddr}:{p2p_conn.dstport}"
720+
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port and peer["addrbind"] == dst_addr_and_port]
720721
assert_equal(len(info), 1)
721722
assert_equal(info[0]["subver"], p2p_conn.strSubVer)
722723

0 commit comments

Comments
 (0)