Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make v2transport arg in addconnection mandatory and few cleanups #29356

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static RPCHelpMan addconnection()
{
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
{"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol"},
{"v2transport", RPCArg::Type::BOOL, RPCArg::Optional::NO, "Attempt to connect using BIP324 v2 transport protocol"},
},
RPCResult{
RPCResult::Type::OBJ, "", "",
Expand Down Expand Up @@ -403,7 +403,7 @@ static RPCHelpMan addconnection()
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
}
bool use_v2transport = !request.params[2].isNull() && request.params[2].get_bool();
bool use_v2transport = self.Arg<bool>(2);

NodeContext& node = EnsureAnyNodeContext(request.context);
CConnman& connman = EnsureConnman(node);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def run_test(self):
self.restart_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but it could be changed from False to self.options.v2transport in the future (e.g. in #29358)

Copy link
Contributor

@mzumsande mzumsande Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, after looking what the tests does it doesn't matter either way, since we don't actually make a real connection here...


self.log.debug("Stop node")
with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
Expand Down
8 changes: 3 additions & 5 deletions test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def connection_lost(self, exc):
self.on_close()

# v2 handshake method
def v2_handshake(self):
def _on_data_v2_handshake(self):
"""v2 handshake performed before P2P messages are exchanged (see BIP324). P2PConnection is the initiator
(in inbound connections to TestNode) and the responder (in outbound connections from TestNode).
Performed by:
Expand Down Expand Up @@ -295,7 +295,7 @@ def data_received(self, t):
if len(t) > 0:
self.recvbuf += t
if self.supports_v2_p2p and not self.v2_state.tried_v2_handshake:
self.v2_handshake()
self._on_data_v2_handshake()
else:
self._on_data()

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

def wait_for_reconnect(self, timeout=60):
def test_function():
if not (self.is_connected and self.last_message.get('version') and self.v2_state is None):
return False
return True
return self.is_connected and self.last_message.get('version') and not self.supports_v2_p2p
self.wait_until(test_function, timeout=timeout, check_connected=False)

# Message receiving helper methods
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_framework/v2_p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def authenticate_handshake(self, response):
# decoy packets have contents = None. v2 handshake is complete only when version packet
# (can be empty with contents = b"") with contents != None is received.
if contents is not None:
assert contents == b"" # currently TestNode sends an empty version packet
self.tried_v2_handshake = True
return processed_length, True
response = response[length:]
Expand Down