Skip to content

Commit a6694ea

Browse files
[test] Add address relay tests involving outbound peers
Co-authored-by: Amiti Uttarwar <[email protected]>
1 parent 8188b77 commit a6694ea

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/functional/p2p_addr_relay.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def oversized_addr_test(self):
9494
self.nodes[0].disconnect_p2ps()
9595

9696
def relay_tests(self):
97+
self.log.info('Test address relay')
9798
self.log.info('Check that addr message content is relayed and added to addrman')
9899
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
99100
num_receivers = 7
@@ -122,6 +123,35 @@ def relay_tests(self):
122123

123124
self.nodes[0].disconnect_p2ps()
124125

126+
self.log.info('Check relay of addresses received from outbound peers')
127+
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver())
128+
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type="outbound-full-relay")
129+
msg = self.setup_addr_msg(2)
130+
self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
131+
self.log.info('Check that the first addr message received from an outbound peer is not relayed')
132+
# Currently, there is a flag that prevents the first addr message received
133+
# from a new outbound peer to be relayed to others. Originally meant to prevent
134+
# large GETADDR responses from being relayed, it now typically affects the self-announcement
135+
# of the outbound peer which is often sent before the GETADDR response.
136+
assert_equal(inbound_peer.num_ipv4_received, 0)
137+
138+
self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
139+
msg2 = self.setup_addr_msg(2)
140+
self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
141+
assert_equal(inbound_peer.num_ipv4_received, 2)
142+
143+
self.log.info('Check address relay to outbound peers')
144+
block_relay_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=1, connection_type="block-relay-only")
145+
msg3 = self.setup_addr_msg(2)
146+
self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer])
147+
148+
self.log.info('Check that addresses are relayed to full outbound peers')
149+
assert_equal(full_outbound_peer.num_ipv4_received, 2)
150+
self.log.info('Check that addresses are not relayed to block-relay-only outbound peers')
151+
assert_equal(block_relay_peer.num_ipv4_received, 0)
152+
153+
self.nodes[0].disconnect_p2ps()
154+
125155
def getaddr_tests(self):
126156
self.log.info('Test getaddr behavior')
127157
self.log.info('Check that we send a getaddr message upon connecting to an outbound-full-relay peer')

0 commit comments

Comments
 (0)