From cccce75e56dccbf5f6e4b11ecfb3aa931f210d7c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 11 Apr 2019 13:30:29 +0930 Subject: [PATCH] patch refine-test_gossip_persistence.patch --- tests/test_gossip.py | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/tests/test_gossip.py b/tests/test_gossip.py index d43201d8a..09e0b35f4 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -397,33 +397,37 @@ def test_gossip_persistence(node_factory, bitcoind): l2.rpc.connect(l3.info['id'], 'localhost', l3.port) l3.rpc.connect(l4.info['id'], 'localhost', l4.port) - l1.fund_channel(l2, 10**6) - l2.fund_channel(l3, 10**6) + scid12 = l1.fund_channel(l2, 10**6) + scid23 = l2.fund_channel(l3, 10**6) # Make channels public, except for l3 -> l4, which is kept local-only for now bitcoind.generate_block(5) - l3.fund_channel(l4, 10**6) + scid34 = l3.fund_channel(l4, 10**6) bitcoind.generate_block(1) - def count_active(node): + def active(node): chans = node.rpc.listchannels()['channels'] - active = [c for c in chans if c['active']] - return len(active) + return sorted([c['short_channel_id'] for c in chans if c['active']]) + + def non_public(node): + chans = node.rpc.listchannels()['channels'] + return sorted([c['short_channel_id'] for c in chans if not c['public']]) # Channels should be activated - wait_for(lambda: count_active(l1) == 4) - wait_for(lambda: count_active(l2) == 4) - wait_for(lambda: count_active(l3) == 6) # 4 public + 2 local + wait_for(lambda: active(l1) == [scid12, scid12, scid23, scid23]) + wait_for(lambda: active(l2) == [scid12, scid12, scid23, scid23]) + # This one sees its private channel + wait_for(lambda: active(l3) == [scid12, scid12, scid23, scid23, scid34, scid34]) # l1 restarts and doesn't connect, but loads from persisted store, all # local channels should be disabled, leaving only the two l2 <-> l3 # directions l1.restart() - wait_for(lambda: count_active(l1) == 2) + wait_for(lambda: active(l1) == [scid23, scid23]) # Now reconnect, they should re-enable the two l1 <-> l2 directions l1.rpc.connect(l2.info['id'], 'localhost', l2.port) - wait_for(lambda: count_active(l1) == 4) + wait_for(lambda: active(l1) == [scid12, scid12, scid23, scid23]) # Now spend the funding tx, generate a block and see others deleting the # channel from their network view @@ -431,32 +435,26 @@ def test_gossip_persistence(node_factory, bitcoind): time.sleep(1) bitcoind.generate_block(1) - wait_for(lambda: count_active(l1) == 2) - wait_for(lambda: count_active(l2) == 2) - wait_for(lambda: count_active(l3) == 4) # 2 public + 2 local - - # We should have one local-only channel - def count_non_public(node): - chans = node.rpc.listchannels()['channels'] - nonpublic = [c for c in chans if not c['public']] - return len(nonpublic) + wait_for(lambda: active(l1) == [scid23, scid23]) + wait_for(lambda: active(l2) == [scid23, scid23]) + wait_for(lambda: active(l3) == [scid23, scid23, scid34, scid34]) # The channel l3 -> l4 should be known only to them - assert count_non_public(l1) == 0 - assert count_non_public(l2) == 0 - wait_for(lambda: count_non_public(l3) == 2) - wait_for(lambda: count_non_public(l4) == 2) + assert non_public(l1) == [] + assert non_public(l2) == [] + wait_for(lambda: non_public(l3) == [scid34, scid34]) + wait_for(lambda: non_public(l4) == [scid34, scid34]) # Finally, it should also remember the deletion after a restart l3.restart() l4.restart() l2.rpc.connect(l3.info['id'], 'localhost', l3.port) l3.rpc.connect(l4.info['id'], 'localhost', l4.port) - wait_for(lambda: count_active(l3) == 4) # 2 public + 2 local + wait_for(lambda: active(l3) == [scid23, scid23, scid34, scid34]) # Both l3 and l4 should remember their local-only channel - wait_for(lambda: count_non_public(l3) == 2) - wait_for(lambda: count_non_public(l4) == 2) + wait_for(lambda: non_public(l3) == [scid34, scid34]) + wait_for(lambda: non_public(l4) == [scid34, scid34]) @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")