Skip to content

Commit

Permalink
Merge bitcoin#29356: test: make v2transport arg in addconnection mand…
Browse files Browse the repository at this point in the history
…atory 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
  • Loading branch information
glozow committed Feb 6, 2024
2 parents 4572f48 + e7fd70f commit 4de8455
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
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)

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 @@ -242,7 +242,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 @@ -298,7 +298,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 @@ -595,9 +595,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

0 comments on commit 4de8455

Please sign in to comment.