0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

test: Avoid race after connect_nodes

This commit is contained in:
MarcoFalke 2021-08-27 10:24:37 +02:00
parent 0492b56e38
commit fa04f26aa7
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -560,18 +560,19 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
self.nodes[i].process.wait(timeout) self.nodes[i].process.wait(timeout)
def connect_nodes(self, a, b): def connect_nodes(self, a, b):
def connect_nodes_helper(from_connection, node_num): from_connection = self.nodes[a]
ip_port = "127.0.0.1:" + str(p2p_port(node_num)) to_connection = self.nodes[b]
from_connection.addnode(ip_port, "onetry") ip_port = "127.0.0.1:" + str(p2p_port(b))
# poll until version handshake complete to avoid race conditions from_connection.addnode(ip_port, "onetry")
# with transaction relaying # poll until version handshake complete to avoid race conditions
# See comments in net_processing: # with transaction relaying
# * Must have a version message before anything else # See comments in net_processing:
# * Must have a verack message before anything else # * Must have a version message before anything else
wait_until_helper(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo())) # * Must have a verack message before anything else
wait_until_helper(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo())) wait_until_helper(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
wait_until_helper(lambda: all(peer['version'] != 0 for peer in to_connection.getpeerinfo()))
connect_nodes_helper(self.nodes[a], b) wait_until_helper(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
wait_until_helper(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in to_connection.getpeerinfo()))
def disconnect_nodes(self, a, b): def disconnect_nodes(self, a, b):
def disconnect_nodes_helper(from_connection, node_num): def disconnect_nodes_helper(from_connection, node_num):