From 930860c7816a7bee8da29342a7b0afcfc0bce433 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 26 Jun 2022 13:58:01 +0930 Subject: [PATCH] pytest: fix flakes in test_gossip_query_channel_range Nodes now spray their own gossip at the start; this can race with our query, and they can give us gossip we didn't ask for. The fix is to always query an uninvolved node: in this case, we only connected l3 and l4 to test zlib, which is gone, so now we can remove that and simply always query l4. ``` 2022-05-23T01:32:53.4695809Z # reply_channel_range == 264 2022-05-23T01:32:53.4696416Z > assert msgs == ['0108' 2022-05-23T01:32:53.4696835Z # blockhash 2022-05-23T01:32:53.4697328Z + genesis_blockhash 2022-05-23T01:32:53.4697841Z # first_blocknum, number_of_blocks, complete 2022-05-23T01:32:53.4698685Z + format(0, '08x') + format(65535, '08x') + '01' 2022-05-23T01:32:53.4699245Z # encoded_short_ids 2022-05-23T01:32:53.4699859Z + format(len(encoded) // 2, '04x') 2022-05-23T01:32:53.4700255Z + encoded] 2022-05-23T01:32:53.4700799Z E AssertionError: assert ['0100194b419...700000010000'] == ['010806226e4...700000010000'] 2022-05-23T01:32:53.4710678Z E At index 0 diff: '0100194b4190af98beedf231901aeda2dcee0e757dd5327219aa007ea6027e769c98665f49e0f99e03b91e80896ed01cd9c4b157c77e908852097d2ba753c6ca01ae41a90a81c9f492c770d9dd35010c702c7c564045cf85a4bf6efaf25cceb9b81b56d1526429d3c60bf1c7ed6a835720730fd7ad1851a937d18aecf8bc3400dd4e0a30d5c4d65999ac39ae6eb3b98d27e3157973598256d2dd4718cd39010a3612580e7f3bba9eda0fb595976f955e345b6affa62fd556f7257a30d54dd87743dc38585e7c31e1ca80b42cf803bd4c1aaa3127351c95de8a4198c46eb0bd7b4ce175a4b51fcaf9676b01806d237758494fcf3d1558279060a0c3b84806a3330c41000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000700000010000035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de19903c47b1b2afcfd68c7b86c0976adb9a4f0835bc78242fced745d78433497a867d6021c29746e4136ddff456483df3980c2d0d5f31c93ef5ded564f7294a10d7414aa' != '010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000000000000ffff01001900000068000001000100006900000100000000700000010000' ``` Signed-off-by: Rusty Russell --- tests/test_gossip.py | 61 ++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 885b766ec..5afe5f1c9 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -704,9 +704,8 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): num_blocks=6, wait_for_mempool=1) - # 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']]) + # Make sure l4 has received all the gossip. + l4.daemon.wait_for_logs(['Received node_announcement for node ' + n.info['id'] for n in (l1, l2, l3)]) 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'] @@ -715,8 +714,8 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): assert block23 == block12 + 1 - # Asks l2 for all channels, gets both. - msgs = l2.query_gossip('query_channel_range', + # Asks l4 for all channels, gets both. + msgs = l4.query_gossip('query_channel_range', chainparams['chain_hash'], 0, 1000000, filters=['0109', '0012']) @@ -735,7 +734,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): + encoded] # Does not include scid12 - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, 0, block12, filters=['0109', '0012']) @@ -749,7 +748,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): '000100'] # Does include scid12 - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, 0, block12 + 1, filters=['0109', '0012']) @@ -768,7 +767,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): + encoded] # Doesn't include scid23 - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, 0, block23, filters=['0109', '0012']) @@ -787,7 +786,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): + encoded] # Does include scid23 - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, block12, block23 - block12 + 1, filters=['0109', '0012']) @@ -806,7 +805,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): + encoded] # Only includes scid23 - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, block23, 1, filters=['0109', '0012']) @@ -825,7 +824,7 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): + encoded] # Past both - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, block23 + 1, 1000000, filters=['0109', '0012']) @@ -838,16 +837,16 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): # encoded_short_ids + '000100'] - # 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') + # Make l4 split reply into two (technically async) + l4.rpc.dev_set_max_scids_encode_size(max=9) + l4.daemon.wait_for_log('Set max_scids_encode_bytes to 9') - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, 0, 1000000, filters=['0109', '0012']) # It should definitely have split - l2.daemon.wait_for_log('reply_channel_range: splitting 0-1 of 2') + l4.daemon.wait_for_log('reply_channel_range: splitting 0-1 of 2') start = 0 scids = '00' @@ -867,40 +866,12 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams): assert scids == encoded # Test overflow case doesn't split forever; should still only get 2 for this - msgs = l2.query_gossip('query_channel_range', + msgs = l4.query_gossip('query_channel_range', genesis_blockhash, 1, 429496000, filters=['0109', '0012']) assert len(msgs) == 2 - # This used to be large enough for zlib to kick in, but no longer! - scid34, _ = l3.fundchannel(l4, 10**5) - mine_funding_to_announce(bitcoind, [l1, l2, l3, l4]) - l2.daemon.wait_for_log('Received node_announcement for node ' + l4.info['id']) - - # 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 {}' - .format(2**32 - 1)) - - msgs = l2.query_gossip('query_channel_range', - genesis_blockhash, - 0, 65535, - filters=['0109', '0012']) - encoded = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23, scid34], - check=True, - timeout=TIMEOUT, - stdout=subprocess.PIPE).stdout.strip().decode() - # reply_channel_range == 264 - assert msgs == ['0108' - # blockhash - + genesis_blockhash - # first_blocknum, number_of_blocks, complete - + format(0, '08x') + format(65535, '08x') + '01' - # encoded_short_ids - + format(len(encoded) // 2, '04x') - + encoded] - # Long test involving 4 lightningd instances. @pytest.mark.developer("needs DEVELOPER=1")