Skip to content

Commit

Permalink
test: enable v2 for python p2p depending on global --v2transport flag
Browse files Browse the repository at this point in the history
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 connection 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 test).
This is done in the same commit so that there isn't an
intermediate commit in which the CI fails.
  • Loading branch information
mzumsande committed Feb 7, 2024
1 parent 6e9e39d commit b9912e2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
3 changes: 2 additions & 1 deletion test/functional/p2p_ibd_stalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def run_test(self):

# 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
Expand Down
29 changes: 16 additions & 13 deletions test/functional/p2p_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ def run_test(self):
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())
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())

self.mock_forward(1)
assert "version" in no_verack_node.last_message
Expand All @@ -83,14 +80,20 @@ def run_test(self):
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())

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",
"socket no message in first 3 seconds, 0 0 peer=2",
]
no_version_node.send_message(msg_ping())

if self.options.v2transport:
expected_timeout_logs = [
"version handshake timeout peer=0",
"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",
]

with self.nodes[0].assert_debug_log(expected_msgs=expected_timeout_logs):
self.mock_forward(2)
Expand Down
13 changes: 7 additions & 6 deletions test/functional/rpc_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def test_getpeerinfo(self):
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,
{
Expand All @@ -125,9 +128,7 @@ def test_getpeerinfo(self):
"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,
Expand All @@ -136,22 +137,22 @@ def test_getpeerinfo(self):
"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": [],
"presynced_headers": -1,
"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,
},
)
Expand Down
12 changes: 10 additions & 2 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, mat
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
Expand All @@ -684,6 +684,9 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru
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:
Expand Down Expand Up @@ -723,7 +726,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru

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.
Expand Down Expand Up @@ -751,6 +754,11 @@ def addconnection_callback(address, port):
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
Expand Down

0 comments on commit b9912e2

Please sign in to comment.