mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
![MarcoFalke](/assets/img/avatar_default.png)
eaf6be0114
[net processing] Do not request transaction relay from feeler connections (John Newbery)0220b834b1
[test] Add testing for outbound feeler connections (John Newbery) Pull request description: Feelers are short-lived connections used to test the viability of peers. The bitcoind node will periodically open feeler connections to addresses in its addrman, wait for a `version` message from the peer, and then close the connection. Currently, we set `fRelay` to `1` in the `version` message for feeler connections, indicating that we want the peer to relay transactions to us. However, we close the connection immediately on receipt of the `version` message, and so never process any incoming transaction announcements. This PR changes that behaviour to instead set `fRelay` to `0` indicating that we do not wish to receive transaction announcements from the peer. This PR also extends the `addconnection` RPC to allow creating outbound feeler connections from the node to the test framework, and a test to verify that the node sets `fRelay` to `0` in the `version` message to feeler connections. ACKs for top commit: naumenkogs: ACKeaf6be0114
MarcoFalke: review ACKeaf6be0114
🏃 Tree-SHA512: 1c56837dbd0a396fe404a5e39f7459864d15f666664d6b35ad109628b13158e077e417e586bf48946a23bd5cbe63716cb4bf22cdf8781b74dfce6047b87b465a
107 lines
4.8 KiB
Python
Executable file
107 lines
4.8 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# Copyright (c) 2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test add_outbound_p2p_connection test framework functionality"""
|
|
|
|
from test_framework.p2p import P2PInterface
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import check_node_connections
|
|
|
|
class P2PFeelerReceiver(P2PInterface):
|
|
def on_version(self, message):
|
|
# The bitcoind node closes feeler connections as soon as a version
|
|
# message is received from the test framework. Don't send any responses
|
|
# to the node's version message since the connection will already be
|
|
# closed.
|
|
pass
|
|
|
|
class P2PAddConnections(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 2
|
|
|
|
def setup_network(self):
|
|
self.setup_nodes()
|
|
# Don't connect the nodes
|
|
|
|
def run_test(self):
|
|
self.log.info("Add 8 outbounds to node 0")
|
|
for i in range(8):
|
|
self.log.info(f"outbound: {i}")
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i, connection_type="outbound-full-relay")
|
|
|
|
self.log.info("Add 2 block-relay-only connections to node 0")
|
|
for i in range(2):
|
|
self.log.info(f"block-relay-only: {i}")
|
|
# set p2p_idx based on the outbound connections already open to the
|
|
# node, so add 8 to account for the previous full-relay connections
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i + 8, connection_type="block-relay-only")
|
|
|
|
self.log.info("Add 2 block-relay-only connections to node 1")
|
|
for i in range(2):
|
|
self.log.info(f"block-relay-only: {i}")
|
|
self.nodes[1].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i, connection_type="block-relay-only")
|
|
|
|
self.log.info("Add 5 inbound connections to node 1")
|
|
for i in range(5):
|
|
self.log.info(f"inbound: {i}")
|
|
self.nodes[1].add_p2p_connection(P2PInterface())
|
|
|
|
self.log.info("Add 8 outbounds to node 1")
|
|
for i in range(8):
|
|
self.log.info(f"outbound: {i}")
|
|
# bump p2p_idx to account for the 2 existing outbounds on node 1
|
|
self.nodes[1].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i + 2)
|
|
|
|
self.log.info("Check the connections opened as expected")
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=10)
|
|
check_node_connections(node=self.nodes[1], num_in=5, num_out=10)
|
|
|
|
self.log.info("Disconnect p2p connections & try to re-open")
|
|
self.nodes[0].disconnect_p2ps()
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=0)
|
|
|
|
self.log.info("Add 8 outbounds to node 0")
|
|
for i in range(8):
|
|
self.log.info(f"outbound: {i}")
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i)
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=8)
|
|
|
|
self.log.info("Add 2 block-relay-only connections to node 0")
|
|
for i in range(2):
|
|
self.log.info(f"block-relay-only: {i}")
|
|
# bump p2p_idx to account for the 8 existing outbounds on node 0
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i + 8, connection_type="block-relay-only")
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=10)
|
|
|
|
self.log.info("Restart node 0 and try to reconnect to p2ps")
|
|
self.restart_node(0)
|
|
|
|
self.log.info("Add 4 outbounds to node 0")
|
|
for i in range(4):
|
|
self.log.info(f"outbound: {i}")
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i)
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=4)
|
|
|
|
self.log.info("Add 2 block-relay-only connections to node 0")
|
|
for i in range(2):
|
|
self.log.info(f"block-relay-only: {i}")
|
|
# bump p2p_idx to account for the 4 existing outbounds on node 0
|
|
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i + 4, connection_type="block-relay-only")
|
|
check_node_connections(node=self.nodes[0], num_in=0, num_out=6)
|
|
|
|
check_node_connections(node=self.nodes[1], num_in=5, num_out=10)
|
|
|
|
self.log.info("Add 1 feeler connection to node 0")
|
|
feeler_conn = self.nodes[0].add_outbound_p2p_connection(P2PFeelerReceiver(), p2p_idx=6, connection_type="feeler")
|
|
|
|
# Feeler connection is closed
|
|
assert not feeler_conn.is_connected
|
|
|
|
# Verify version message received
|
|
assert_equal(feeler_conn.message_count["version"], 1)
|
|
# Feeler connections do not request tx relay
|
|
assert_equal(feeler_conn.last_message["version"].relay, 0)
|
|
|
|
if __name__ == '__main__':
|
|
P2PAddConnections().main()
|