Skip to content

Commit 0220b83

Browse files
committed
[test] Add testing for outbound feeler connections
Extend the addconnection RPC method to allow creating outbound feeler connections. Extend the test framework to accept those feeler connections.
1 parent dbcb574 commit 0220b83

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

src/net.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,6 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
12171217
switch (conn_type) {
12181218
case ConnectionType::INBOUND:
12191219
case ConnectionType::MANUAL:
1220-
case ConnectionType::FEELER:
12211220
return false;
12221221
case ConnectionType::OUTBOUND_FULL_RELAY:
12231222
max_connections = m_max_outbound_full_relay;
@@ -1228,6 +1227,9 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
12281227
// no limit for ADDR_FETCH because -seednode has no limit either
12291228
case ConnectionType::ADDR_FETCH:
12301229
break;
1230+
// no limit for FEELER connections since they're short-lived
1231+
case ConnectionType::FEELER:
1232+
break;
12311233
} // no default case, so the compiler can warn about missing cases
12321234

12331235
// Count existing connections

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ class CConnman
892892
* Attempts to open a connection. Currently only used from tests.
893893
*
894894
* @param[in] address Address of node to try connecting to
895-
* @param[in] conn_type ConnectionType::OUTBOUND or ConnectionType::BLOCK_RELAY
896-
* or ConnectionType::ADDR_FETCH
895+
* @param[in] conn_type ConnectionType::OUTBOUND, ConnectionType::BLOCK_RELAY,
896+
* ConnectionType::ADDR_FETCH or ConnectionType::FEELER
897897
* @return bool Returns false if there are no available
898898
* slots for this connection:
899899
* - conn_type not a supported ConnectionType

src/rpc/net.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static RPCHelpMan addconnection()
343343
"\nOpen an outbound connection to a specified node. This RPC is for testing only.\n",
344344
{
345345
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
346-
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\" or \"addr-fetch\")."},
346+
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
347347
},
348348
RPCResult{
349349
RPCResult::Type::OBJ, "", "",
@@ -371,6 +371,8 @@ static RPCHelpMan addconnection()
371371
conn_type = ConnectionType::BLOCK_RELAY;
372372
} else if (conn_type_in == "addr-fetch") {
373373
conn_type = ConnectionType::ADDR_FETCH;
374+
} else if (conn_type_in == "feeler") {
375+
conn_type = ConnectionType::FEELER;
374376
} else {
375377
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
376378
}

test/functional/p2p_add_connections.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def check_node_connections(*, node, num_in, num_out):
1414
assert_equal(info["connections_in"], num_in)
1515
assert_equal(info["connections_out"], num_out)
1616

17+
class P2PFeelerReceiver(P2PInterface):
18+
def on_version(self, message):
19+
# The bitcoind node closes feeler connections as soon as a version
20+
# message is received from the test framework. Don't send any responses
21+
# to the node's version message since the connection will already be
22+
# closed.
23+
pass
1724

1825
class P2PAddConnections(BitcoinTestFramework):
1926
def set_test_params(self):
@@ -91,6 +98,14 @@ def run_test(self):
9198

9299
check_node_connections(node=self.nodes[1], num_in=5, num_out=10)
93100

101+
self.log.info("Add 1 feeler connection to node 0")
102+
feeler_conn = self.nodes[0].add_outbound_p2p_connection(P2PFeelerReceiver(), p2p_idx=6, connection_type="feeler")
103+
104+
# Feeler connection is closed
105+
assert not feeler_conn.is_connected
106+
107+
# Verify version message received
108+
assert_equal(feeler_conn.message_count["version"], 1)
94109

95110
if __name__ == '__main__':
96111
P2PAddConnections().main()

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
558558

559559
def add_outbound_p2p_connection(self, p2p_conn, *, p2p_idx, connection_type="outbound-full-relay", **kwargs):
560560
"""Add an outbound p2p connection from node. Must be an
561-
"outbound-full-relay", "block-relay-only" or "addr-fetch" connection.
561+
"outbound-full-relay", "block-relay-only", "addr-fetch" or "feeler" connection.
562562
563563
This method adds the p2p connection to the self.p2ps list and returns
564564
the connection to the caller.
@@ -570,11 +570,16 @@ def addconnection_callback(address, port):
570570

571571
p2p_conn.peer_accept_connection(connect_cb=addconnection_callback, connect_id=p2p_idx + 1, net=self.chain, timeout_factor=self.timeout_factor, **kwargs)()
572572

573-
p2p_conn.wait_for_connect()
574-
self.p2ps.append(p2p_conn)
573+
if connection_type == "feeler":
574+
# feeler connections are closed as soon as the node receives a `version` message
575+
p2p_conn.wait_until(lambda: p2p_conn.message_count["version"] == 1, check_connected=False)
576+
p2p_conn.wait_until(lambda: not p2p_conn.is_connected, check_connected=False)
577+
else:
578+
p2p_conn.wait_for_connect()
579+
self.p2ps.append(p2p_conn)
575580

576-
p2p_conn.wait_for_verack()
577-
p2p_conn.sync_with_ping()
581+
p2p_conn.wait_for_verack()
582+
p2p_conn.sync_with_ping()
578583

579584
return p2p_conn
580585

0 commit comments

Comments
 (0)