Skip to content

Commit 4de8455

Browse files
committed
Merge bitcoin#29356: test: make v2transport arg in addconnection mandatory and few cleanups
e7fd70f [test] make v2transport arg in addconnection mandatory and few cleanups (stratospher) Pull request description: - make `v2transport` argument in `addconnection` regression-testing only RPC mandatory. bitcoin#24748 (comment) - previously it was an optional arg with default `false` value. - only place this RPC is used is in the [functional tests](https://github.com/bitcoin/bitcoin/blob/11b436a66af3ceaebb0f907878715f331516a0bc/test/functional/test_framework/test_node.py#L742) where we always pass the appropriate `v2transport` option to the RPC anyways. (and that too just for python dummy peer(`P2PInterface`) and bitcoind(`TestNode`) interactions) - rename `v2_handshake()` to `_on_data_v2_handshake()` bitcoin#24748 (comment) - more compact return statement in `wait_for_reconnect()` bitcoin#24748 (comment) - assertion to check that empty version packets are received from `TestNode`. ACKs for top commit: glozow: ACK e7fd70f theStack: Code-review ACK e7fd70f mzumsande: Code Review ACK e7fd70f Tree-SHA512: e66e29baccd91e1e4398b91f7d45c5fc7c2841d77d8a6178734586017bf2be63496721649da91848dec71da605ee31664352407d5bb896e624cc693767c61a1f
2 parents 4572f48 + e7fd70f commit 4de8455

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

Diff for: src/rpc/net.cpp

+2-2
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);

Diff for: test/functional/feature_anchors.py

+1-1
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"]):

Diff for: test/functional/test_framework/p2p.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def connection_lost(self, exc):
242242
self.on_close()
243243

244244
# v2 handshake method
245-
def v2_handshake(self):
245+
def _on_data_v2_handshake(self):
246246
"""v2 handshake performed before P2P messages are exchanged (see BIP324). P2PConnection is the initiator
247247
(in inbound connections to TestNode) and the responder (in outbound connections from TestNode).
248248
Performed by:
@@ -298,7 +298,7 @@ def data_received(self, t):
298298
if len(t) > 0:
299299
self.recvbuf += t
300300
if self.supports_v2_p2p and not self.v2_state.tried_v2_handshake:
301-
self.v2_handshake()
301+
self._on_data_v2_handshake()
302302
else:
303303
self._on_data()
304304

@@ -595,9 +595,7 @@ def wait_for_disconnect(self, timeout=60):
595595

596596
def wait_for_reconnect(self, timeout=60):
597597
def test_function():
598-
if not (self.is_connected and self.last_message.get('version') and self.v2_state is None):
599-
return False
600-
return True
598+
return self.is_connected and self.last_message.get('version') and not self.supports_v2_p2p
601599
self.wait_until(test_function, timeout=timeout, check_connected=False)
602600

603601
# Message receiving helper methods

Diff for: test/functional/test_framework/v2_p2p.py

+1
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)