|
1 | 1 | #!/usr/bin/env python3 |
2 | | -# Copyright (c) 2014-2020 The Bitcoin Core developers |
| 2 | +# Copyright (c) 2014-present The Bitcoin Core developers |
3 | 3 | # Copyright (c) 2014-2025 The Dash Core developers |
4 | 4 | # Distributed under the MIT software license, see the accompanying |
5 | 5 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. |
@@ -718,23 +718,19 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None): |
718 | 718 | def find_conn(node, peer_subversion, inbound): |
719 | 719 | return next(filter(lambda peer: peer['subver'] == peer_subversion and peer['inbound'] == inbound, node.getpeerinfo()), None) |
720 | 720 |
|
721 | | - # poll until version handshake complete to avoid race conditions |
722 | | - # with transaction relaying |
723 | | - # See comments in net_processing: |
724 | | - # * Must have a version message before anything else |
725 | | - # * Must have a verack message before anything else |
726 | 721 | self.wait_until(lambda: find_conn(from_connection, to_connection_subver, inbound=False) is not None) |
727 | 722 | self.wait_until(lambda: find_conn(to_connection, from_connection_subver, inbound=True) is not None) |
728 | 723 |
|
729 | 724 | def check_bytesrecv(peer, msg_type, min_bytes_recv): |
730 | 725 | assert peer is not None, "Error: peer disconnected" |
731 | 726 | return peer['bytesrecv_per_msg'].pop(msg_type, 0) >= min_bytes_recv |
732 | 727 |
|
733 | | - self.wait_until(lambda: check_bytesrecv(find_conn(from_connection, to_connection_subver, inbound=False), 'verack', 21)) |
734 | | - self.wait_until(lambda: check_bytesrecv(find_conn(to_connection, from_connection_subver, inbound=True), 'verack', 21)) |
735 | | - |
736 | | - # The message bytes are counted before processing the message, so make |
737 | | - # sure it was fully processed by waiting for a ping. |
| 728 | + # Poll until version handshake (fSuccessfullyConnected) is complete to |
| 729 | + # avoid race conditions, because some message types are blocked from |
| 730 | + # being sent or received before fSuccessfullyConnected. |
| 731 | + # |
| 732 | + # As the flag fSuccessfullyConnected is not exposed, check it by |
| 733 | + # waiting for a pong, which can only happen after the flag was set. |
738 | 734 | self.wait_until(lambda: check_bytesrecv(find_conn(from_connection, to_connection_subver, inbound=False), 'pong', 29)) |
739 | 735 | self.wait_until(lambda: check_bytesrecv(find_conn(to_connection, from_connection_subver, inbound=True), 'pong', 29)) |
740 | 736 |
|
|
0 commit comments