aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-08-01 16:56:39 +0100
committerfanquake <fanquake@gmail.com>2023-08-01 16:59:37 +0100
commit1b5cbf71dff1f240bac0156f8800382272489f0b (patch)
treeee5affb363819dcc17b5726f236dc6ebbd59d986
parenteb95368e0c3ab3d9f5f88630c2bd81ad1b01988a (diff)
parent8a20f765cce2fc0fadf1a2b66b843b67f2d2ae12 (diff)
Merge bitcoin/bitcoin#28144: test: fix intermittent failure in p2p_getaddr_caching.py
8a20f765cce2fc0fadf1a2b66b843b67f2d2ae12 test: drop duplicate getaddrs from p2p_getaddr_caching (Martin Zumsande) feb0096139e9e864632d2826d2e213b26146fff1 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 8a20f765cce2fc0fadf1a2b66b843b67f2d2ae12 Tree-SHA512: eabe4727d7887f729074076f6333a918bba8cb34b8e3baaa83f167b441b0daa24f7c4824abcf03a9538a2ef14b2d826ff19aeffcb93a6c20735253a9678aac9c
-rwxr-xr-xtest/functional/p2p_getaddr_caching.py9
-rwxr-xr-xtest/functional/test_framework/test_node.py5
2 files changed, 5 insertions, 9 deletions
diff --git a/test/functional/p2p_getaddr_caching.py b/test/functional/p2p_getaddr_caching.py
index 1c9ad7289b..60b43c32ae 100755
--- a/test/functional/p2p_getaddr_caching.py
+++ b/test/functional/p2p_getaddr_caching.py
@@ -6,7 +6,6 @@
import time
-from test_framework.messages import msg_getaddr
from test_framework.p2p import (
P2PInterface,
p2p_lock
@@ -21,6 +20,7 @@ from test_framework.util import (
MAX_ADDR_TO_SEND = 1000
MAX_PCT_ADDR_TO_SEND = 23
+
class AddrReceiver(P2PInterface):
def __init__(self):
@@ -70,11 +70,8 @@ class AddrTest(BitcoinTestFramework):
cur_mock_time = int(time.time())
for i in range(N):
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
- addr_receiver_local.send_and_ping(msg_getaddr())
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
- addr_receiver_onion1.send_and_ping(msg_getaddr())
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
- addr_receiver_onion2.send_and_ping(msg_getaddr())
# Trigger response
cur_mock_time += 5 * 60
@@ -105,11 +102,8 @@ class AddrTest(BitcoinTestFramework):
self.log.info('After time passed, see a new response to addr request')
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
- addr_receiver_local.send_and_ping(msg_getaddr())
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
- addr_receiver_onion1.send_and_ping(msg_getaddr())
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
- addr_receiver_onion2.send_and_ping(msg_getaddr())
# Trigger response
cur_mock_time += 5 * 60
@@ -123,5 +117,6 @@ class AddrTest(BitcoinTestFramework):
assert set(last_response_on_onion_bind1) != set(addr_receiver_onion1.get_received_addrs())
assert set(last_response_on_onion_bind2) != set(addr_receiver_onion2.get_received_addrs())
+
if __name__ == '__main__':
AddrTest().main()
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 2fc3da55fa..544a81602e 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -649,10 +649,11 @@ class TestNode():
p2p_conn.sync_with_ping()
# Consistency check that the node received our user agent string.
- # Find our connection in getpeerinfo by our address:port, as it is unique.
+ # Find our connection in getpeerinfo by our address:port and theirs, as this combination is unique.
sockname = p2p_conn._transport.get_extra_info("socket").getsockname()
our_addr_and_port = f"{sockname[0]}:{sockname[1]}"
- info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port]
+ dst_addr_and_port = f"{p2p_conn.dstaddr}:{p2p_conn.dstport}"
+ info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port and peer["addrbind"] == dst_addr_and_port]
assert_equal(len(info), 1)
assert_equal(info[0]["subver"], P2P_SUBVERSION)