Skip to content

Commit e7fd70f

Browse files
committed
[test] make v2transport arg in addconnection mandatory and few cleanups
`TestNode::add_outbound_p2p_connection()` is the only place where addconnection test-only RPC is used. here, we always pass the appropriate v2transport option to addconnection RPC. currently the v2transport option for addconnection RPC is optional. so simply make the v2transport option mandatory instead.
1 parent 411ba32 commit e7fd70f

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/rpc/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static RPCHelpMan addconnection()
371371
{
372372
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
373373
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
374-
{"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol"},
374+
{"v2transport", RPCArg::Type::BOOL, RPCArg::Optional::NO, "Attempt to connect using BIP324 v2 transport protocol"},
375375
},
376376
RPCResult{
377377
RPCResult::Type::OBJ, "", "",
@@ -403,7 +403,7 @@ static RPCHelpMan addconnection()
403403
} else {
404404
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
405405
}
406-
bool use_v2transport = !request.params[2].isNull() && request.params[2].get_bool();
406+
bool use_v2transport = self.Arg<bool>(2);
407407

408408
NodeContext& node = EnsureAnyNodeContext(request.context);
409409
CConnman& connman = EnsureConnman(node);

test/functional/feature_anchors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run_test(self):
9999
self.restart_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])
100100

101101
self.log.info("Add 256-bit-address block-relay-only connections to node")
102-
self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only')
102+
self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only', v2transport=False)
103103

104104
self.log.debug("Stop node")
105105
with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):

test/functional/test_framework/p2p.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def connection_lost(self, exc):
243243
self.on_close()
244244

245245
# v2 handshake method
246-
def v2_handshake(self):
246+
def _on_data_v2_handshake(self):
247247
"""v2 handshake performed before P2P messages are exchanged (see BIP324). P2PConnection is the initiator
248248
(in inbound connections to TestNode) and the responder (in outbound connections from TestNode).
249249
Performed by:
@@ -295,7 +295,7 @@ def data_received(self, t):
295295
if len(t) > 0:
296296
self.recvbuf += t
297297
if self.supports_v2_p2p and not self.v2_state.tried_v2_handshake:
298-
self.v2_handshake()
298+
self._on_data_v2_handshake()
299299
else:
300300
self._on_data()
301301

@@ -593,9 +593,7 @@ def wait_for_disconnect(self, timeout=60):
593593

594594
def wait_for_reconnect(self, timeout=60):
595595
def test_function():
596-
if not (self.is_connected and self.last_message.get('version') and self.v2_state is None):
597-
return False
598-
return True
596+
return self.is_connected and self.last_message.get('version') and not self.supports_v2_p2p
599597
self.wait_until(test_function, timeout=timeout, check_connected=False)
600598

601599
# Message receiving helper methods

test/functional/test_framework/v2_p2p.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def authenticate_handshake(self, response):
220220
# decoy packets have contents = None. v2 handshake is complete only when version packet
221221
# (can be empty with contents = b"") with contents != None is received.
222222
if contents is not None:
223+
assert contents == b"" # currently TestNode sends an empty version packet
223224
self.tried_v2_handshake = True
224225
return processed_length, True
225226
response = response[length:]

0 commit comments

Comments
 (0)