From 4c89e24f64c1dc1a56a3bcb6b5e2b4fb95e8b29f Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Mon, 24 May 2021 17:56:22 -0700 Subject: [PATCH] [test] Test the delay before querying DNS seeds When starting up with a populated addrman, ThreadDNSAddressSeed adds a delay during which time the node may be able to connect to some peers. This commit tests the delay changes based on the number of addresses in the addrman. --- test/functional/p2p_dns_seeds.py | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/functional/p2p_dns_seeds.py b/test/functional/p2p_dns_seeds.py index d9977dccee2..e58ad8e0fc8 100755 --- a/test/functional/p2p_dns_seeds.py +++ b/test/functional/p2p_dns_seeds.py @@ -4,6 +4,8 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test ThreadDNSAddressSeed logic for querying DNS seeds.""" +import itertools + from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework @@ -19,6 +21,7 @@ class P2PDNSSeeds(BitcoinTestFramework): self.existing_outbound_connections_test() self.existing_block_relay_connections_test() self.force_dns_test() + self.wait_time_tests() def init_arg_tests(self): fakeaddr = "fakenodeaddr.fakedomain.invalid." @@ -90,6 +93,37 @@ class P2PDNSSeeds(BitcoinTestFramework): # Restore default for subsequent tests self.restart_node(0) + def wait_time_tests(self): + self.log.info("Check the delay before querying DNS seeds") + + # Populate addrman with < 1000 addresses + for i in range(5): + a = f"192.0.0.{i}" + self.nodes[0].addpeeraddress(a, 8333) + + # The delay should be 11 seconds + with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 11 seconds before querying DNS seeds.\n"]): + self.restart_node(0) + + # Populate addrman with > 1000 addresses + for i in itertools.count(): + first_octet = i % 2 + 1 + second_octet = i % 256 + third_octet = i % 100 + a = f"{first_octet}.{second_octet}.{third_octet}.1" + self.nodes[0].addpeeraddress(a, 8333) + if (i > 1000 and i % 100 == 0): + # The addrman size is non-deterministic because new addresses + # are sorted into buckets, potentially displacing existing + # addresses. Periodically check if we have met the desired + # threshold. + if len(self.nodes[0].getnodeaddresses(0)) > 1000: + break + + # The delay should be 5 mins + with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 300 seconds before querying DNS seeds.\n"]): + self.restart_node(0) + if __name__ == '__main__': P2PDNSSeeds().main()