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

Method rate_limit_tests

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

Source from the content-addressed store, hash-verified

323 assert_equal(addrs_rate_limited, max(0, total_addrs - peer.tokens))
324
325 def rate_limit_tests(self):
326 self.mocktime = int(time.time())
327 self.restart_node(0, [])
328 self.nodes[0].setmocktime(self.mocktime)
329
330 for conn_type, no_relay in [("outbound-full-relay", False), ("block-relay-only", True), ("inbound", False)]:
331 self.log.info(f'Test rate limiting of addr processing for {conn_type} peers')
332 if conn_type == "inbound":
333 peer = self.nodes[0].add_p2p_connection(AddrReceiver())
334 else:
335 peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type=conn_type)
336
337 # Send 600 addresses. For all but the block-relay-only peer this should result in addresses being processed.
338 self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=600, total_addrs=600)
339
340 # Send 600 more addresses. For the outbound-full-relay peer (which we send a GETADDR, and thus will
341 # process up to 1001 incoming addresses), this means more addresses will be processed.
342 self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=600, total_addrs=1200)
343
344 # Send 10 more. As we reached the processing limit for all nodes, no more addresses should be procesesd.
345 self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=10, total_addrs=1210)
346
347 # Advance the time by 100 seconds, permitting the processing of 10 more addresses.
348 # Send 200 and verify that 10 are processed.
349 self.mocktime += 100
350 self.nodes[0].setmocktime(self.mocktime)
351 peer.increment_tokens(10)
352
353 self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=200, total_addrs=1410)
354
355 # Advance the time by 1000 seconds, permitting the processing of 100 more addresses.
356 # Send 200 and verify that 100 are processed.
357 self.mocktime += 1000
358 self.nodes[0].setmocktime(self.mocktime)
359 peer.increment_tokens(100)
360
361 self.send_addrs_and_test_rate_limiting(peer, no_relay, new_addrs=200, total_addrs=1610)
362
363 self.nodes[0].disconnect_p2ps()
364
365
366if __name__ == '__main__':

Callers 1

run_testMethod · 0.95

Calls 9

setmocktimeMethod · 0.80
infoMethod · 0.80
increment_tokensMethod · 0.80
AddrReceiverClass · 0.70
restart_nodeMethod · 0.45
add_p2p_connectionMethod · 0.45
disconnect_p2psMethod · 0.45

Tested by

no test coverage detected