Skip to content

Commit 8106b26

Browse files
committed
Merge bitcoin/bitcoin#29239: rpc: Make v2transport default for addnode RPC when enabled
3ba815b Make v2transport default for addnode RPC when enabled (Pieter Wuille) Pull request description: Since #29058, several types of manually configured connections will attempt v2 connections when `-v2transport` is enabled, except for the `addnode` RPC, as that one has an explicit argument to enable or disable. Make the default for that RPC match the `-v2transport` setting so the behavior matches that of other manual connections from a user perspective. ACKs for top commit: achow101: ACK 3ba815b kristapsk: ACK 3ba815b theStack: Code-review ACK 3ba815b Tree-SHA512: 31ef48cf1e533abb17866020378c004df929e626074dc98b3229fb60a66de58435e95c8fda8d1b463e1208aa39d1f42d239818e7e58595a3738089920598befc
2 parents a3fb1f8 + 3ba815b commit 8106b26

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/rpc/net.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static RPCHelpMan addnode()
313313
{
314314
{"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The address of the peer to connect to"},
315315
{"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"},
316-
{"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
316+
{"v2transport", RPCArg::Type::BOOL, RPCArg::DefaultHint{"set by -v2transport"}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
317317
},
318318
RPCResult{RPCResult::Type::NONE, "", ""},
319319
RPCExamples{
@@ -332,9 +332,10 @@ static RPCHelpMan addnode()
332332
CConnman& connman = EnsureConnman(node);
333333

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

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

test/functional/test_framework/test_framework.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool
602602
if peer_advertises_v2 is None:
603603
peer_advertises_v2 = from_connection.use_v2transport
604604

605-
if peer_advertises_v2:
606-
from_connection.addnode(node=ip_port, command="onetry", v2transport=True)
605+
if peer_advertises_v2 != from_connection.use_v2transport:
606+
from_connection.addnode(node=ip_port, command="onetry", v2transport=peer_advertises_v2)
607607
else:
608-
# skip the optional third argument (default false) for
608+
# skip the optional third argument if it matches the default, for
609609
# compatibility with older clients
610610
from_connection.addnode(ip_port, "onetry")
611611

0 commit comments

Comments
 (0)