Skip to content

Commit 6653fa3

Browse files
committed
[test] Update p2p_addr_relay test to prepare
Use an init param to make clear whether a getaddr message should be sent when the P2PConnection receives a version message. These changes are in preparation for upcoming commits that modify the behavior of a bitcoind node and the test framework.
1 parent 2fcaec7 commit 6653fa3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

test/functional/p2p_addr_relay.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
NODE_NETWORK,
1212
NODE_WITNESS,
1313
msg_addr,
14-
msg_getaddr
14+
msg_getaddr,
15+
msg_verack
1516
)
1617
from test_framework.p2p import (
1718
P2PInterface,
@@ -27,10 +28,12 @@ class AddrReceiver(P2PInterface):
2728
num_ipv4_received = 0
2829
test_addr_contents = False
2930
_tokens = 1
31+
send_getaddr = True
3032

31-
def __init__(self, test_addr_contents=False):
33+
def __init__(self, test_addr_contents=False, send_getaddr=True):
3234
super().__init__()
3335
self.test_addr_contents = test_addr_contents
36+
self.send_getaddr = send_getaddr
3437

3538
def on_addr(self, message):
3639
for addr in message.addrs:
@@ -60,6 +63,11 @@ def increment_tokens(self, n):
6063
def addr_received(self):
6164
return self.num_ipv4_received != 0
6265

66+
def on_version(self, message):
67+
self.send_message(msg_verack())
68+
if (self.send_getaddr):
69+
self.send_message(msg_getaddr())
70+
6371
def getaddr_received(self):
6472
return self.message_count['getaddr'] > 0
6573

@@ -156,7 +164,7 @@ def relay_tests(self):
156164
self.nodes[0].disconnect_p2ps()
157165

158166
self.log.info('Check relay of addresses received from outbound peers')
159-
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True))
167+
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True, send_getaddr=False))
160168
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay")
161169
msg = self.setup_addr_msg(2)
162170
self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
@@ -185,6 +193,12 @@ def relay_tests(self):
185193
self.nodes[0].disconnect_p2ps()
186194

187195
def getaddr_tests(self):
196+
# In the previous tests, the node answered GETADDR requests with an
197+
# empty addrman. Due to GETADDR response caching (see
198+
# CConnman::GetAddresses), the node would continue to provide 0 addrs
199+
# in response until enough time has passed or the node is restarted.
200+
self.restart_node(0)
201+
188202
self.log.info('Test getaddr behavior')
189203
self.log.info('Check that we send a getaddr message upon connecting to an outbound-full-relay peer')
190204
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay")
@@ -197,7 +211,7 @@ def getaddr_tests(self):
197211
assert_equal(block_relay_peer.getaddr_received(), False)
198212

199213
self.log.info('Check that we answer getaddr messages only from inbound peers')
200-
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver())
214+
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
201215
inbound_peer.sync_with_ping()
202216

203217
# Add some addresses to addrman

0 commit comments

Comments
 (0)