Skip to content

Commit

Permalink
Make v2transport default for addnode RPC when enabled
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#29239
Rebased-From: 3ba815b
  • Loading branch information
sipa authored and luke-jr committed Jan 27, 2024
1 parent 96ec3b6 commit 7caf2a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/rpc/net.cpp
Expand Up @@ -300,7 +300,7 @@ static RPCHelpMan addnode()
{
{"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The address of the peer to connect to"},
{"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once"},
{"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
{"v2transport", RPCArg::Type::BOOL, RPCArg::DefaultHint{"set by -v2transport"}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
},
RPCResult{RPCResult::Type::NONE, "", ""},
RPCExamples{
Expand All @@ -319,9 +319,10 @@ static RPCHelpMan addnode()
CConnman& connman = EnsureConnman(node);

const std::string node_arg{request.params[0].get_str()};
bool use_v2transport = self.Arg<bool>(2);
bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
bool use_v2transport = self.MaybeArg<bool>(2).value_or(node_v2transport);

if (use_v2transport && !(node.connman->GetLocalServices() & NODE_P2P_V2)) {
if (use_v2transport && !node_v2transport) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
}

Expand Down
6 changes: 3 additions & 3 deletions test/functional/test_framework/test_framework.py
Expand Up @@ -603,10 +603,10 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool
if peer_advertises_v2 is None:
peer_advertises_v2 = self.options.v2transport

if peer_advertises_v2:
from_connection.addnode(node=ip_port, command="onetry", v2transport=True)
if peer_advertises_v2 != from_connection.use_v2transport:
from_connection.addnode(node=ip_port, command="onetry", v2transport=peer_advertises_v2)
else:
# skip the optional third argument (default false) for
# skip the optional third argument if it matches the default, for
# compatibility with older clients
from_connection.addnode(ip_port, "onetry")

Expand Down

0 comments on commit 7caf2a8

Please sign in to comment.