mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: enable v2 for python p2p depending on global --v2transport flag
This changes the default behavior, individual tests can overwrite this option. As a result, it is possible to run the entire test suite with --v2transport, and all connections to the python p2p will then use it. Also adjust several tests that are already running with --v2transport in the test runner (although they actually made v1 connection before this change). This is done in the same commit so that there isn't an intermediate commit in which the CI fails.
This commit is contained in:
parent
6e9e39da43
commit
bf5662c678
4 changed files with 34 additions and 21 deletions
|
@ -80,7 +80,8 @@ class P2PIBDStallingTest(BitcoinTestFramework):
|
|||
|
||||
# Need to wait until 1023 blocks are received - the magic total bytes number is a workaround in lack of an rpc
|
||||
# returning the number of downloaded (but not connected) blocks.
|
||||
self.wait_until(lambda: self.total_bytes_recv_for_blocks() == 172761)
|
||||
bytes_recv = 172761 if not self.options.v2transport else 169692
|
||||
self.wait_until(lambda: self.total_bytes_recv_for_blocks() == bytes_recv)
|
||||
|
||||
self.all_sync_send_with_ping(peers)
|
||||
# If there was a peer marked for stalling, it would get disconnected
|
||||
|
|
|
@ -69,9 +69,6 @@ class TimeoutsTest(BitcoinTestFramework):
|
|||
with self.nodes[0].assert_debug_log(['Unsupported message "ping" prior to verack from peer=0']):
|
||||
no_verack_node.send_message(msg_ping())
|
||||
|
||||
# With v2, non-version messages before the handshake would be interpreted as part of the key exchange.
|
||||
# Therefore, don't execute this part of the test if v2transport is chosen.
|
||||
if not self.options.v2transport:
|
||||
with self.nodes[0].assert_debug_log(['non-version message before version handshake. Message "ping" from peer=1']):
|
||||
no_version_node.send_message(msg_ping())
|
||||
|
||||
|
@ -83,12 +80,18 @@ class TimeoutsTest(BitcoinTestFramework):
|
|||
assert no_send_node.is_connected
|
||||
|
||||
no_verack_node.send_message(msg_ping())
|
||||
if not self.options.v2transport:
|
||||
no_version_node.send_message(msg_ping())
|
||||
|
||||
if self.options.v2transport:
|
||||
expected_timeout_logs = [
|
||||
"version handshake timeout peer=0",
|
||||
f"socket no message in first 3 seconds, {'0' if self.options.v2transport else '1'} 0 peer=1",
|
||||
"version handshake timeout peer=1",
|
||||
"version handshake timeout peer=2",
|
||||
]
|
||||
else:
|
||||
expected_timeout_logs = [
|
||||
"version handshake timeout peer=0",
|
||||
"socket no message in first 3 seconds, 1 0 peer=1",
|
||||
"socket no message in first 3 seconds, 0 0 peer=2",
|
||||
]
|
||||
|
||||
|
|
|
@ -117,6 +117,9 @@ class NetTest(BitcoinTestFramework):
|
|||
peer_info = self.nodes[0].getpeerinfo()[no_version_peer_id]
|
||||
peer_info.pop("addr")
|
||||
peer_info.pop("addrbind")
|
||||
# The next two fields will vary for v2 connections because we send a rng-based number of decoy messages
|
||||
peer_info.pop("bytesrecv")
|
||||
peer_info.pop("bytessent")
|
||||
assert_equal(
|
||||
peer_info,
|
||||
{
|
||||
|
@ -125,9 +128,7 @@ class NetTest(BitcoinTestFramework):
|
|||
"addr_relay_enabled": False,
|
||||
"bip152_hb_from": False,
|
||||
"bip152_hb_to": False,
|
||||
"bytesrecv": 0,
|
||||
"bytesrecv_per_msg": {},
|
||||
"bytessent": 0,
|
||||
"bytessent_per_msg": {},
|
||||
"connection_type": "inbound",
|
||||
"conntime": no_version_peer_conntime,
|
||||
|
@ -136,8 +137,8 @@ class NetTest(BitcoinTestFramework):
|
|||
"inflight": [],
|
||||
"last_block": 0,
|
||||
"last_transaction": 0,
|
||||
"lastrecv": 0,
|
||||
"lastsend": 0,
|
||||
"lastrecv": 0 if not self.options.v2transport else no_version_peer_conntime,
|
||||
"lastsend": 0 if not self.options.v2transport else no_version_peer_conntime,
|
||||
"minfeefilter": Decimal("0E-8"),
|
||||
"network": "not_publicly_routable",
|
||||
"permissions": [],
|
||||
|
@ -145,13 +146,13 @@ class NetTest(BitcoinTestFramework):
|
|||
"relaytxes": False,
|
||||
"services": "0000000000000000",
|
||||
"servicesnames": [],
|
||||
"session_id": "",
|
||||
"session_id": "" if not self.options.v2transport else no_version_peer.v2_state.peer['session_id'].hex(),
|
||||
"startingheight": -1,
|
||||
"subver": "",
|
||||
"synced_blocks": -1,
|
||||
"synced_headers": -1,
|
||||
"timeoffset": 0,
|
||||
"transport_protocol_type": "v1" if not self.options.v2transport else "detecting",
|
||||
"transport_protocol_type": "v1" if not self.options.v2transport else "v2",
|
||||
"version": 0,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -667,7 +667,7 @@ class TestNode():
|
|||
assert_msg += "with expected error " + expected_msg
|
||||
self._raise_assertion_error(assert_msg)
|
||||
|
||||
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=False, wait_for_v2_handshake=True, **kwargs):
|
||||
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=None, wait_for_v2_handshake=True, **kwargs):
|
||||
"""Add an inbound p2p connection to the node.
|
||||
|
||||
This method adds the p2p connection to the self.p2ps list and also
|
||||
|
@ -684,6 +684,9 @@ class TestNode():
|
|||
kwargs['dstport'] = p2p_port(self.index)
|
||||
if 'dstaddr' not in kwargs:
|
||||
kwargs['dstaddr'] = '127.0.0.1'
|
||||
if supports_v2_p2p is None:
|
||||
supports_v2_p2p = self.use_v2transport
|
||||
|
||||
|
||||
p2p_conn.p2p_connected_to_node = True
|
||||
if self.use_v2transport:
|
||||
|
@ -723,7 +726,7 @@ class TestNode():
|
|||
|
||||
return p2p_conn
|
||||
|
||||
def add_outbound_p2p_connection(self, p2p_conn, *, wait_for_verack=True, p2p_idx, connection_type="outbound-full-relay", supports_v2_p2p=False, advertise_v2_p2p=False, **kwargs):
|
||||
def add_outbound_p2p_connection(self, p2p_conn, *, wait_for_verack=True, p2p_idx, connection_type="outbound-full-relay", supports_v2_p2p=None, advertise_v2_p2p=None, **kwargs):
|
||||
"""Add an outbound p2p connection from node. Must be an
|
||||
"outbound-full-relay", "block-relay-only", "addr-fetch" or "feeler" connection.
|
||||
|
||||
|
@ -751,6 +754,11 @@ class TestNode():
|
|||
self.addconnection('%s:%d' % (address, port), connection_type, advertise_v2_p2p)
|
||||
|
||||
p2p_conn.p2p_connected_to_node = False
|
||||
if supports_v2_p2p is None:
|
||||
supports_v2_p2p = self.use_v2transport
|
||||
if advertise_v2_p2p is None:
|
||||
advertise_v2_p2p = self.use_v2transport
|
||||
|
||||
if advertise_v2_p2p:
|
||||
kwargs['services'] = kwargs.get('services', P2P_SERVICES) | NODE_P2P_V2
|
||||
assert self.use_v2transport # only a v2 TestNode could make a v2 outbound connection
|
||||
|
|
Loading…
Add table
Reference in a new issue