|
1 | 1 | #!/usr/bin/env python3
|
2 |
| -# Copyright (c) 2014-2022 The Bitcoin Core developers |
| 2 | +# Copyright (c) 2014-present The Bitcoin Core developers |
3 | 3 | # Distributed under the MIT software license, see the accompanying
|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Base class for RPC testing."""
|
@@ -636,23 +636,19 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool
|
636 | 636 | def find_conn(node, peer_subversion, inbound):
|
637 | 637 | return next(filter(lambda peer: peer['subver'] == peer_subversion and peer['inbound'] == inbound, node.getpeerinfo()), None)
|
638 | 638 |
|
639 |
| - # poll until version handshake complete to avoid race conditions |
640 |
| - # with transaction relaying |
641 |
| - # See comments in net_processing: |
642 |
| - # * Must have a version message before anything else |
643 |
| - # * Must have a verack message before anything else |
644 | 639 | self.wait_until(lambda: find_conn(from_connection, to_connection_subver, inbound=False) is not None)
|
645 | 640 | self.wait_until(lambda: find_conn(to_connection, from_connection_subver, inbound=True) is not None)
|
646 | 641 |
|
647 | 642 | def check_bytesrecv(peer, msg_type, min_bytes_recv):
|
648 | 643 | assert peer is not None, "Error: peer disconnected"
|
649 | 644 | return peer['bytesrecv_per_msg'].pop(msg_type, 0) >= min_bytes_recv
|
650 | 645 |
|
651 |
| - self.wait_until(lambda: check_bytesrecv(find_conn(from_connection, to_connection_subver, inbound=False), 'verack', 21)) |
652 |
| - self.wait_until(lambda: check_bytesrecv(find_conn(to_connection, from_connection_subver, inbound=True), 'verack', 21)) |
653 |
| - |
654 |
| - # The message bytes are counted before processing the message, so make |
655 |
| - # sure it was fully processed by waiting for a ping. |
| 646 | + # Poll until version handshake (fSuccessfullyConnected) is complete to |
| 647 | + # avoid race conditions, because some message types are blocked from |
| 648 | + # being sent or received before fSuccessfullyConnected. |
| 649 | + # |
| 650 | + # As the flag fSuccessfullyConnected is not exposed, check it by |
| 651 | + # waiting for a pong, which can only happen after the flag was set. |
656 | 652 | self.wait_until(lambda: check_bytesrecv(find_conn(from_connection, to_connection_subver, inbound=False), 'pong', 29))
|
657 | 653 | self.wait_until(lambda: check_bytesrecv(find_conn(to_connection, from_connection_subver, inbound=True), 'pong', 29))
|
658 | 654 |
|
|
0 commit comments