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

Function test_gossip_query_channel_range

tests/test_gossip.py:718–934  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

716
717
718def test_gossip_query_channel_range(node_factory, bitcoind, chainparams):
719 l1, l2, l3, l4 = node_factory.line_graph(4, fundchannel=False)
720 genesis_blockhash = chainparams['chain_hash']
721
722 # Make public channels on consecutive blocks
723 l1.fundwallet(10**6)
724 l2.fundwallet(10**6)
725
726 num_tx = len(bitcoind.rpc.getrawmempool())
727 # We want these one block apart.
728 l1.rpc.fundchannel(l2.info['id'], 10**5)['tx']
729 bitcoind.generate_block(wait_for_mempool=num_tx + 1)
730 sync_blockheight(bitcoind, [l1, l2, l3, l4])
731 l2.rpc.fundchannel(l3.info['id'], 10**5)['tx']
732 # Get them both to gossip depth.
733 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4],
734 num_blocks=6,
735 wait_for_mempool=1)
736
737 # Make sure l4 has received all the gossip.
738 l4.daemon.wait_for_logs(['Received node_announcement for node ' + n.info['id'] for n in (l1, l2, l3)])
739
740 scid12 = l1.rpc.listpeerchannels(l2.info['id'])['channels'][0]['short_channel_id']
741 scid23 = l3.rpc.listpeerchannels(l2.info['id'])['channels'][0]['short_channel_id']
742 block12 = int(scid12.split('x')[0])
743 block23 = int(scid23.split('x')[0])
744
745 assert block23 == block12 + 1
746
747 # Asks l4 for all channels, gets both.
748 msgs = l4.query_gossip('query_channel_range',
749 chainparams['chain_hash'],
750 0, 1000000,
751 filters=['0109', '0107', '0012', '0105'])
752 # Either order!
753 encoded1 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
754 check=True,
755 timeout=TIMEOUT,
756 stdout=subprocess.PIPE).stdout.strip().decode()
757 encoded2 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid23, scid12],
758 check=True,
759 timeout=TIMEOUT,
760 stdout=subprocess.PIPE).stdout.strip().decode()
761 # reply_channel_range == 264
762 assert msgs in (['0108'
763 # blockhash
764 + genesis_blockhash
765 # first_blocknum, number_of_blocks, complete
766 + format(0, '08x') + format(1000000, '08x') + '01'
767 # encoded_short_ids
768 + format(len(encoded1) // 2, '04x')
769 + encoded1],
770 ['0108'
771 # blockhash
772 + genesis_blockhash
773 # first_blocknum, number_of_blocks, complete
774 + format(0, '08x') + format(1000000, '08x') + '01'
775 # encoded_short_ids

Callers

nothing calls this directly

Calls 13

sync_blockheightFunction · 0.90
mine_funding_to_announceFunction · 0.90
formatEnum · 0.85
line_graphMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
wait_for_logsMethod · 0.80
listpeerchannelsMethod · 0.80
query_gossipMethod · 0.80
wait_for_logMethod · 0.80
fundchannelMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected