Now that you’ve added addr relay statistics to getpeerinfo
, you can isolate and observe the (predictable) p2p behaviour, rather than the (stochastic) addrman effects:
0@@ -244,25 +244,55 @@ class AddrTest(BitcoinTestFramework):
1 assert_equal(addr_count_0, 0)
2
3 # Send 600 addresses. For all but the block-relay-only peer this should result in at least 1 address.
4- peer.send_and_ping(self.setup_rand_addr_msg(600))
5- addr_count_1 = len(self.nodes[0].getnodeaddresses(0))
6- assert_greater_than_or_equal(tokens, addr_count_1)
7- assert_greater_than_or_equal(addr_count_0 + 600, addr_count_1)
8- assert_equal(addr_count_1 > addr_count_0, tokens > 0)
9+ addrs = 600
10+ peer.send_and_ping(self.setup_rand_addr_msg(addrs))
11+
12+ peerinfo_1 = self.nodes[0].getpeerinfo()[0]
13+ addrs_processed_1 = peerinfo_1['addr_processed']
14+ addrs_rate_limited_1 = peerinfo_1['addr_rate_limited']
15+ self.log.info(f"addrs_processed = {addrs_processed_1}, addrs_rate_limited = {addrs_rate_limited_1}")
16+
17+ if not no_relay:
18+ assert_equal(addrs_processed_1, min(addrs, tokens))
19+ assert_equal(addrs_rate_limited_1, addrs - min(addrs, tokens))
20+ else:
21+ assert_equal(addrs_processed_1, 0)
22+ assert_equal(addrs_rate_limited_1, 0)
23
24 # Send 600 more addresses. For the outbound-full-relay peer (which sends a GETADDR, and thus will
25 # process up to 1001 incoming addresses), this means more entries will appear.
26- peer.send_and_ping(self.setup_rand_addr_msg(600))
27- addr_count_2 = len(self.nodes[0].getnodeaddresses(0))
28- assert_greater_than_or_equal(tokens, addr_count_2)
29- assert_greater_than_or_equal(addr_count_1 + 600, addr_count_2)
30- assert_equal(addr_count_2 > addr_count_1, tokens > 600)
31+ new_addrs = 600
32+ peer.send_and_ping(self.setup_rand_addr_msg(new_addrs))
33+
34+ addrs += new_addrs
35+ peerinfo_2 = self.nodes[0].getpeerinfo()[0]
36+ addrs_processed_2 = peerinfo_2['addr_processed']
37+ addrs_rate_limited_2 = peerinfo_2['addr_rate_limited']
38+ self.log.info(f"addrs_processed = {addrs_processed_2}, addrs_rate_limited = {addrs_rate_limited_2}")
39+
40+ if not no_relay:
41+ assert_equal(addrs_processed_2, min(addrs, tokens))
42+ assert_equal(addrs_rate_limited_2, addrs - min(addrs, tokens))
43+ else:
44+ assert_equal(addrs_processed_2, 0)
45+ assert_equal(addrs_rate_limited_2, 0)
46
47 # Send 10 more. As we reached the processing limit for all nodes, this should have no effect.
48- peer.send_and_ping(self.setup_rand_addr_msg(10))
49- addr_count_3 = len(self.nodes[0].getnodeaddresses(0))
50- assert_greater_than_or_equal(tokens, addr_count_3)
51- assert_equal(addr_count_2, addr_count_3)
52+ new_addrs = 10
53+ peer.send_and_ping(self.setup_rand_addr_msg(new_addrs))
54+
55+ addrs += new_addrs
56+ peerinfo_3 = self.nodes[0].getpeerinfo()[0]
57+ addrs_processed_3 = peerinfo_3['addr_processed']
58+ addrs_rate_limited_3 = peerinfo_3['addr_rate_limited']
59+ self.log.info(f"addrs_processed = {addrs_processed_3}, addrs_rate_limited = {addrs_rate_limited_3}")
60+
61+ if not no_relay:
62+ assert_equal(addrs_processed_3, min(addrs, tokens))
63+ assert_equal(addrs_rate_limited_3, addrs - min(addrs, tokens))
64+ else:
65+ assert_equal(addrs_processed_3, 0)
66+ assert_equal(addrs_rate_limited_3, 0)
67
68 # Advance the time by 100 seconds, permitting the processing of 10 more addresses. Send 200,
69 # but verify that no more than 10 are processed.
70@@ -270,10 +300,21 @@ class AddrTest(BitcoinTestFramework):
71 self.nodes[0].setmocktime(self.mocktime)
72 new_tokens = 0 if no_relay else 10
73 tokens += new_tokens
74- peer.send_and_ping(self.setup_rand_addr_msg(200))
75- addr_count_4 = len(self.nodes[0].getnodeaddresses(0))
76- assert_greater_than_or_equal(tokens, addr_count_4)
77- assert_greater_than_or_equal(addr_count_3 + new_tokens, addr_count_4)
78+ new_addrs = 200
79+ peer.send_and_ping(self.setup_rand_addr_msg(new_addrs))
80+
81+ addrs += new_addrs
82+ peerinfo_4 = self.nodes[0].getpeerinfo()[0]
83+ addrs_processed_4 = peerinfo_4['addr_processed']
84+ addrs_rate_limited_4 = peerinfo_4['addr_rate_limited']
85+ self.log.info(f"addrs_processed = {addrs_processed_4}, addrs_rate_limited = {addrs_rate_limited_4}")
86+
87+ if not no_relay:
88+ assert_equal(addrs_processed_4, min(addrs, tokens))
89+ assert_equal(addrs_rate_limited_4, addrs - min(addrs, tokens))
90+ else:
91+ assert_equal(addrs_processed_4, 0)
92+ assert_equal(addrs_rate_limited_4, 0)
93
94 # Advance the time by 1000 seconds, permitting the processing of 100 more addresses. Send 200,
95 # but verify that no more than 100 are processed (and at least some).
96@@ -281,11 +322,21 @@ class AddrTest(BitcoinTestFramework):
97 self.nodes[0].setmocktime(self.mocktime)
98 new_tokens = 0 if no_relay else 100
99 tokens += new_tokens
100- peer.send_and_ping(self.setup_rand_addr_msg(200))
101- addr_count_5 = len(self.nodes[0].getnodeaddresses(0))
102- assert_greater_than_or_equal(tokens, addr_count_5)
103- assert_greater_than_or_equal(addr_count_4 + new_tokens, addr_count_5)
104- assert_equal(addr_count_5 > addr_count_4, not no_relay)
105+ new_addrs = 200
106+ peer.send_and_ping(self.setup_rand_addr_msg(new_addrs))
107+
108+ addrs += new_addrs
109+ peerinfo_5 = self.nodes[0].getpeerinfo()[0]
110+ addrs_processed_5 = peerinfo_5['addr_processed']
111+ addrs_rate_limited_5 = peerinfo_5['addr_rate_limited']
112+ self.log.info(f"addrs_processed = {addrs_processed_5}, addrs_rate_limited = {addrs_rate_limited_5}")
113+
114+ if not no_relay:
115+ assert_equal(addrs_processed_5, min(addrs, tokens))
116+ assert_equal(addrs_rate_limited_5, addrs - min(addrs, tokens))
117+ else:
118+ assert_equal(addrs_processed_5, 0)
119+ assert_equal(addrs_rate_limited_5, 0)
120
121 self.nodes[0].disconnect_p2ps()
(Obviously, there’s a lot of duplicate code above that can be factored out into a send_and_test()
routine.)