MCPcopy Create free account
hub / github.com/ElementsProject/elements / relay_tests

Method relay_tests

test/functional/p2p_addr_relay.py:134–193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

132 self.nodes[0].disconnect_p2ps()
133
134 def relay_tests(self):
135 self.log.info('Test address relay')
136 self.log.info('Check that addr message content is relayed and added to addrman')
137 addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
138 num_receivers = 7
139 receivers = []
140 for _ in range(num_receivers):
141 receivers.append(self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True)))
142
143 # Keep this with length <= 10. Addresses from larger messages are not
144 # relayed.
145 num_ipv4_addrs = 10
146 msg = self.setup_addr_msg(num_ipv4_addrs)
147 with self.nodes[0].assert_debug_log(
148 [
149 'received: addr (301 bytes) peer=1',
150 ]
151 ):
152 self.send_addr_msg(addr_source, msg, receivers)
153
154 total_ipv4_received = sum(r.num_ipv4_received for r in receivers)
155
156 # Every IPv4 address must be relayed to two peers, other than the
157 # originating node (addr_source).
158 ipv4_branching_factor = 2
159 assert_equal(total_ipv4_received, num_ipv4_addrs * ipv4_branching_factor)
160
161 self.nodes[0].disconnect_p2ps()
162
163 self.log.info('Check relay of addresses received from outbound peers')
164 inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True, send_getaddr=False))
165 full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay")
166 msg = self.setup_addr_msg(2)
167 self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
168 self.log.info('Check that the first addr message received from an outbound peer is not relayed')
169 # Currently, there is a flag that prevents the first addr message received
170 # from a new outbound peer to be relayed to others. Originally meant to prevent
171 # large GETADDR responses from being relayed, it now typically affects the self-announcement
172 # of the outbound peer which is often sent before the GETADDR response.
173 assert_equal(inbound_peer.num_ipv4_received, 0)
174
175 # Send an empty ADDR message to initialize address relay on this connection.
176 inbound_peer.send_and_ping(msg_addr())
177
178 self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
179 msg2 = self.setup_addr_msg(2)
180 self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
181 assert_equal(inbound_peer.num_ipv4_received, 2)
182
183 self.log.info('Check address relay to outbound peers')
184 block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only")
185 msg3 = self.setup_addr_msg(2)
186 self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer])
187
188 self.log.info('Check that addresses are relayed to full outbound peers')
189 assert_equal(full_outbound_peer.num_ipv4_received, 2)
190 self.log.info('Check that addresses are not relayed to block-relay-only outbound peers')
191 assert_equal(block_relay_peer.num_ipv4_received, 0)

Callers 1

run_testMethod · 0.95

Calls 12

setup_addr_msgMethod · 0.95
send_addr_msgMethod · 0.95
P2PInterfaceClass · 0.90
assert_equalFunction · 0.90
msg_addrClass · 0.90
infoMethod · 0.80
AddrReceiverClass · 0.70
add_p2p_connectionMethod · 0.45
assert_debug_logMethod · 0.45
disconnect_p2psMethod · 0.45
send_and_pingMethod · 0.45

Tested by

no test coverage detected