Skip to content

Commit

Permalink
pytest: tighten the query_channel_range test.
Browse files Browse the repository at this point in the history
Make the two channels adjacent, and specify exactly the number of
divide-and-conquer steps there are.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 15, 2019
1 parent cd2a452 commit 39425e7
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,34 @@ def test_gossip_query_channel_range(node_factory, bitcoind):
l1, l2, l3, l4 = node_factory.line_graph(4, opts={'log-level': 'io'},
fundchannel=False)

# Make public channels.
scid12 = l1.fund_channel(l2, 10**5)
block12 = int(scid12.split('x')[0])
scid23 = l2.fund_channel(l3, 10**5)
block23 = int(scid23.split('x')[0])
# Make public channels on consecutive blocks
l1.fundwallet(10**6)
l2.fundwallet(10**6)

num_tx = len(bitcoind.rpc.getrawmempool())
l1.rpc.fundchannel(l2.info['id'], 10**5)['tx']
wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == num_tx + 1)
bitcoind.generate_block(1)

num_tx = len(bitcoind.rpc.getrawmempool())
l2.rpc.fundchannel(l3.info['id'], 10**5)['tx']
wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == num_tx + 1)
bitcoind.generate_block(1)

# Get them both to gossip depth.
bitcoind.generate_block(5)

# Make sure l2 has received all the gossip.
l2.daemon.wait_for_logs(['Received node_announcement for node ' + l1.info['id'],
'Received node_announcement for node ' + l3.info['id']])

scid12 = only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'][0]['short_channel_id']
scid23 = only_one(l3.rpc.listpeers(l2.info['id'])['peers'])['channels'][0]['short_channel_id']
block12 = int(scid12.split('x')[0])
block23 = int(scid23.split('x')[0])

assert block23 == block12 + 1

# l1 asks for all channels, gets both.
ret = l1.rpc.dev_query_channel_range(id=l2.info['id'],
first=0,
Expand Down Expand Up @@ -633,13 +650,19 @@ def test_gossip_query_channel_range(node_factory, bitcoind):
assert ret['final_complete']
assert len(ret['short_channel_ids']) == 0

# Turn on IO logging in l1 channeld.
subprocess.run(['kill', '-USR1', l1.subd_pid('channeld')])

# Make l2 split reply into two (technically async)
l2.rpc.dev_set_max_scids_encode_size(max=9)
l2.daemon.wait_for_log('Set max_scids_encode_bytes to 9')
ret = l1.rpc.dev_query_channel_range(id=l2.info['id'],
first=0,
num=1000000)

# Turns out it sends huge number of empty replies here.
l1.daemon.wait_for_logs([r'\[IN\] 0108'] * 21)

# It should definitely have split
assert ret['final_first_block'] != 0 or ret['final_num_blocks'] != 1000000
assert ret['final_complete']
Expand All @@ -653,9 +676,6 @@ def test_gossip_query_channel_range(node_factory, bitcoind):
bitcoind.generate_block(5)
l2.daemon.wait_for_log('Received node_announcement for node ' + l4.info['id'])

# Turn on IO logging in l1 channeld.
subprocess.run(['kill', '-USR1', l1.subd_pid('channeld')])

# Restore infinite encode size.
l2.rpc.dev_set_max_scids_encode_size(max=(2**32 - 1))
l2.daemon.wait_for_log('Set max_scids_encode_bytes to {}'
Expand Down

0 comments on commit 39425e7

Please sign in to comment.