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

Function test_connect_ratelimit

tests/test_connection.py:4723–4779  ·  view source on GitHub ↗

l1 has 5 peers, restarts, make sure we limit

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4721
4722
4723def test_connect_ratelimit(node_factory, bitcoind):
4724 """l1 has 5 peers, restarts, make sure we limit"""
4725 # Sending nodes SIGSTOP at the wrong time makes connectd complain about
4726 # how long operations took!
4727 nodes = node_factory.get_nodes(6,
4728 opts=[{'dev-limit-connections-inflight': None, 'may_reconnect': True}]
4729 + [{'may_reconnect': True, 'broken_log': "connectd: wake delay for"}] * 5)
4730
4731 l1 = nodes[0]
4732 nodes = nodes[1:]
4733
4734 addr = l1.rpc.newaddr('bech32')['bech32']
4735 for n in nodes:
4736 bitcoind.rpc.sendtoaddress(addr, (FUNDAMOUNT + 1000000) / 10**8)
4737 bitcoind.generate_block(1, wait_for_mempool=len(nodes))
4738 sync_blockheight(bitcoind, [l1])
4739
4740 for n in nodes:
4741 l1.rpc.connect(n.info['id'], 'localhost', n.port)
4742 l1.rpc.fundchannel(n.info['id'], FUNDAMOUNT)
4743
4744 # Make sure all channels are established and announced.
4745 bitcoind.generate_block(6, wait_for_mempool=len(nodes))
4746 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == len(nodes) * 2)
4747
4748 assert not l1.daemon.is_in_log('Unblocking for')
4749
4750 l1.stop()
4751
4752 # Suspend the others' connectd, to make sure they cannot respond too fast.
4753 connectd_pids = []
4754 for n in nodes:
4755 log = n.daemon.is_in_log(' connectd: pid .*, msgfd')
4756 m = re.search(r'connectd: pid (\d*),', log)
4757 pid = int(m.groups()[0])
4758 connectd_pids.append(pid)
4759 os.kill(pid, signal.SIGSTOP)
4760
4761 try:
4762 l1.start()
4763
4764 # The first will be ok, but others should block and be unblocked.
4765 l1.daemon.wait_for_logs((['Unblocking for ']
4766 + ['Too many connections, waiting'])
4767 * (len(nodes) - 1))
4768 except Exception as err:
4769 # Resume, so pytest doesn't hang!
4770 for p in connectd_pids:
4771 os.kill(p, signal.SIGCONT)
4772 raise err
4773
4774 # Resume them
4775 for p in connectd_pids:
4776 os.kill(p, signal.SIGCONT)
4777
4778 # And now they're all connected
4779 wait_for(lambda: [p['connected'] for p in l1.rpc.listpeers()['peers']] == [True] * len(nodes))
4780

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