Skip to content

Commit 17c065d

Browse files
MarcoFalkepanleone
authored andcommitted
test: Avoid race after connect_nodes
1 parent d73ac82 commit 17c065d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,19 @@ def wait_for_node_exit(self, i, timeout):
342342
self.nodes[i].process.wait(timeout)
343343

344344
def connect_nodes(self, a, b):
345-
def connect_nodes_helper(from_connection, node_num):
346-
ip_port = "127.0.0.1:" + str(p2p_port(node_num))
347-
from_connection.addnode(ip_port, "onetry")
348-
# poll until version handshake complete to avoid race conditions
349-
# with transaction relaying
350-
# See comments in net_processing:
351-
# * Must have a version message before anything else
352-
# * Must have a verack message before anything else
353-
wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
354-
wait_until(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
355-
connect_nodes_helper(self.nodes[a], b)
345+
from_connection = self.nodes[a]
346+
to_connection = self.nodes[b]
347+
ip_port = "127.0.0.1:" + str(p2p_port(b))
348+
from_connection.addnode(ip_port, "onetry")
349+
# poll until version handshake complete to avoid race conditions
350+
# with transaction relaying
351+
# See comments in net_processing:
352+
# * Must have a version message before anything else
353+
# * Must have a verack message before anything else
354+
wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
355+
wait_until(lambda: all(peer['version'] != 0 for peer in to_connection.getpeerinfo()))
356+
wait_until(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
357+
wait_until(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in to_connection.getpeerinfo()))
356358

357359
def disconnect_nodes(self, a, b):
358360
def disconnect_nodes_helper(from_connection, node_num):

0 commit comments

Comments
 (0)