Skip to content

Commit 0be2f54

Browse files
committed
Merge bitcoin/bitcoin#27986: test: remove race in the user-agent reception check
20b4946 test: remove race in the user-agent reception check (Vasil Dimov) Pull request description: In `add_p2p_connection()` we connect to `bitcoind` from the Python client and check that it has received our version string. This check looked up the last/newest entry from `getpeerinfo` RPC, assuming that it must be the connection we have just opened. But this will not be the case if a new inbound or outbound connection is made to/from `bitcoind` in the meantime. Instead of the last entry in `getpeerinfo`, check all and find the one which corresponds to our connection using our outgoing address:port tuple which is unique. ACKs for top commit: jonatack: re-ACK 20b4946 MarcoFalke: Concept ACK 20b4946 Tree-SHA512: 61fd3359ef11ea830021ede0e745497a7b60690c32d21c47cd12ff79f78907bb45e922c9d01e5d7ff614a8cd5e4560d39a3fc86b01b200429773a23ace3917e4
2 parents 3648a9b + 20b4946 commit 0be2f54

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/functional/test_framework/test_node.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,13 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
644644
# in comparison to the upside of making tests less fragile and unexpected intermittent errors less likely.
645645
p2p_conn.sync_with_ping()
646646

647-
# Consistency check that the Bitcoin Core has received our user agent string. This checks the
648-
# node's newest peer. It could be racy if another Bitcoin Core node has connected since we opened
649-
# our connection, but we don't expect that to happen.
650-
assert_equal(self.getpeerinfo()[-1]['subver'], P2P_SUBVERSION)
647+
# Consistency check that the node received our user agent string.
648+
# Find our connection in getpeerinfo by our address:port, as it is unique.
649+
sockname = p2p_conn._transport.get_extra_info("socket").getsockname()
650+
our_addr_and_port = f"{sockname[0]}:{sockname[1]}"
651+
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port]
652+
assert_equal(len(info), 1)
653+
assert_equal(info[0]["subver"], P2P_SUBVERSION)
651654

652655
return p2p_conn
653656

0 commit comments

Comments
 (0)