MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_connect_ratelimit

Function test_connect_ratelimit

tests/test_connection.py:4539–4595  ·  view source on GitHub ↗

l1 has 5 peers, restarts, make sure we limit

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4537
4538
4539def test_connect_ratelimit(node_factory, bitcoind):
4540 """l1 has 5 peers, restarts, make sure we limit"""
4541 # Sending nodes SIGSTOP at the wrong time makes connectd complain about
4542 # how long operations took!
4543 nodes = node_factory.get_nodes(6,
4544 opts=[{'dev-limit-connections-inflight': None, 'may_reconnect': True}]
4545 + [{'may_reconnect': True, 'broken_log': "connectd: wake delay for"}] * 5)
4546
4547 l1 = nodes[0]
4548 nodes = nodes[1:]
4549
4550 addr = l1.rpc.newaddr('bech32')['bech32']
4551 for n in nodes:
4552 bitcoind.rpc.sendtoaddress(addr, (FUNDAMOUNT + 1000000) / 10**8)
4553 bitcoind.generate_block(1, wait_for_mempool=len(nodes))
4554 sync_blockheight(bitcoind, [l1])
4555
4556 for n in nodes:
4557 l1.rpc.connect(n.info['id'], 'localhost', n.port)
4558 l1.rpc.fundchannel(n.info['id'], FUNDAMOUNT)
4559
4560 # Make sure all channels are established and announced.
4561 bitcoind.generate_block(6, wait_for_mempool=len(nodes))
4562 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == len(nodes) * 2)
4563
4564 assert not l1.daemon.is_in_log('Unblocking for')
4565
4566 l1.stop()
4567
4568 # Suspend the others' connectd, to make sure they cannot respond too fast.
4569 connectd_pids = []
4570 for n in nodes:
4571 log = n.daemon.is_in_log(' connectd: pid .*, msgfd')
4572 m = re.search(r'connectd: pid (\d*),', log)
4573 pid = int(m.groups()[0])
4574 connectd_pids.append(pid)
4575 os.kill(pid, signal.SIGSTOP)
4576
4577 try:
4578 l1.start()
4579
4580 # The first will be ok, but others should block and be unblocked.
4581 l1.daemon.wait_for_logs((['Unblocking for ']
4582 + ['Too many connections, waiting'])
4583 * (len(nodes) - 1))
4584 except Exception as err:
4585 # Resume, so pytest doesn't hang!
4586 for p in connectd_pids:
4587 os.kill(p, signal.SIGCONT)
4588 raise err
4589
4590 # Resume them
4591 for p in connectd_pids:
4592 os.kill(p, signal.SIGCONT)
4593
4594 # And now they're all connected
4595 wait_for(lambda: [p['connected'] for p in l1.rpc.listpeers()['peers']] == [True] * len(nodes))
4596

Callers

nothing calls this directly

Calls 14

sync_blockheightFunction · 0.90
wait_forFunction · 0.90
get_nodesMethod · 0.80
generate_blockMethod · 0.80
is_in_logMethod · 0.80
killMethod · 0.80
wait_for_logsMethod · 0.80
newaddrMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45
listchannelsMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected