aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_addr_relay.py
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-07-31 21:56:59 +0200
committerJon Atack <jon@atack.com>2021-08-04 19:03:51 +0200
commitd930c7f5b091687eb4208a5ffe8a2abe311d8054 (patch)
treee0460df9eb8367667dd86406f2193925caef42a5 /test/functional/p2p_addr_relay.py
parent2b06af17470667a9c9ee68cb241936839b46bc33 (diff)
downloadbitcoin-d930c7f5b091687eb4208a5ffe8a2abe311d8054.tar.xz
p2p, rpc, test: address rate-limiting follow-ups
Diffstat (limited to 'test/functional/p2p_addr_relay.py')
-rwxr-xr-xtest/functional/p2p_addr_relay.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py
index 95743a1bf5..f2a682df8b 100755
--- a/test/functional/p2p_addr_relay.py
+++ b/test/functional/p2p_addr_relay.py
@@ -311,7 +311,7 @@ class AddrTest(BitcoinTestFramework):
self.nodes[0].disconnect_p2ps()
- def send_addrs_and_test_rate_limiting(self, peer, no_relay, new_addrs, total_addrs):
+ def send_addrs_and_test_rate_limiting(self, peer, no_relay, *, new_addrs, total_addrs):
"""Send an addr message and check that the number of addresses processed and rate-limited is as expected"""
peer.send_and_ping(self.setup_rand_addr_msg(new_addrs))
@@ -329,27 +329,26 @@ class AddrTest(BitcoinTestFramework):
assert_equal(addrs_rate_limited, max(0, total_addrs - peer.tokens))
def rate_limit_tests(self):
-
self.mocktime = int(time.time())
self.restart_node(0, [])
self.nodes[0].setmocktime(self.mocktime)
- for contype, no_relay in [("outbound-full-relay", False), ("block-relay-only", True), ("inbound", False)]:
- self.log.info(f'Test rate limiting of addr processing for {contype} peers')
- if contype == "inbound":
+ for conn_type, no_relay in [("outbound-full-relay", False), ("block-relay-only", True), ("inbound", False)]:
+ self.log.info(f'Test rate limiting of addr processing for {conn_type} peers')
+ if conn_type == "inbound":
peer = self.nodes[0].add_p2p_connection(AddrReceiver())
else:
- peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type=contype)
+ peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type=conn_type)
# Send 600 addresses. For all but the block-relay-only peer this should result in addresses being processed.
- self.send_addrs_and_test_rate_limiting(peer, no_relay, 600, 600)
+ self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=600, total_addrs=600)
# Send 600 more addresses. For the outbound-full-relay peer (which we send a GETADDR, and thus will
# process up to 1001 incoming addresses), this means more addresses will be processed.
- self.send_addrs_and_test_rate_limiting(peer, no_relay, 600, 1200)
+ self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=600, total_addrs=1200)
# Send 10 more. As we reached the processing limit for all nodes, no more addresses should be procesesd.
- self.send_addrs_and_test_rate_limiting(peer, no_relay, 10, 1210)
+ self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=10, total_addrs=1210)
# Advance the time by 100 seconds, permitting the processing of 10 more addresses.
# Send 200 and verify that 10 are processed.
@@ -357,7 +356,7 @@ class AddrTest(BitcoinTestFramework):
self.nodes[0].setmocktime(self.mocktime)
peer.increment_tokens(10)
- self.send_addrs_and_test_rate_limiting(peer, no_relay, 200, 1410)
+ self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=200, total_addrs=1410)
# Advance the time by 1000 seconds, permitting the processing of 100 more addresses.
# Send 200 and verify that 100 are processed.
@@ -365,9 +364,10 @@ class AddrTest(BitcoinTestFramework):
self.nodes[0].setmocktime(self.mocktime)
peer.increment_tokens(100)
- self.send_addrs_and_test_rate_limiting(peer, no_relay, 200, 1610)
+ self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=200, total_addrs=1610)
self.nodes[0].disconnect_p2ps()
+
if __name__ == '__main__':
AddrTest().main()