l1 has 5 peers, restarts, make sure we limit
(node_factory, bitcoind)
| 4537 | |
| 4538 | |
| 4539 | def 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 |
nothing calls this directly
no test coverage detected