Skip to content

Commit cdb0001

Browse files
adi2011cdecker
authored andcommitted
tests/test_misc.py: Add test_recover_plugin to check if the funds are being recovered when we lose some state and enter recover mode.
1 parent e3b4ed4 commit cdb0001

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/test_misc.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,53 @@ def test_emergencyrecover(node_factory, bitcoind):
28082808
assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"
28092809

28102810

2811+
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "sqlite3-specific DB rollback")
2812+
@pytest.mark.openchannel('v1')
2813+
@pytest.mark.openchannel('v2')
2814+
def test_recover_plugin(node_factory, bitcoind):
2815+
l1 = node_factory.get_node(may_reconnect=True, options={'log-level': 'info', 'experimental-peer-storage': None},
2816+
allow_warning=True,
2817+
feerates=(7500, 7500, 7500, 7500))
2818+
l2 = node_factory.get_node(may_reconnect=True, options={'log-level': 'info', 'experimental-peer-storage': None},
2819+
feerates=(7500, 7500, 7500, 7500), allow_broken_log=True, allow_bad_gossip=True)
2820+
2821+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
2822+
l2.fundchannel(l1, 10**6)
2823+
mine_funding_to_announce(bitcoind, [l1, l2])
2824+
2825+
l2.stop()
2826+
2827+
# Save copy of the db.
2828+
dbpath = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3")
2829+
orig_db = open(dbpath, "rb").read()
2830+
2831+
l2.start()
2832+
2833+
assert l2.daemon.is_in_log('Server started with public key')
2834+
l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
2835+
2836+
# successful payments
2837+
i31 = l1.rpc.invoice(10000, 'i31', 'desc')
2838+
l2.rpc.pay(i31['bolt11'])
2839+
2840+
# Now, move l2 back in time.
2841+
l2.stop()
2842+
2843+
# Overwrite with OLD db.
2844+
open(dbpath, "wb").write(orig_db)
2845+
2846+
l2.start()
2847+
2848+
bitcoind.generate_block(5, wait_for_mempool=1)
2849+
sync_blockheight(bitcoind, [l1, l2])
2850+
2851+
l2.daemon.wait_for_log(f"{l1.info['id']}-chan#1: State changed from FUNDING_SPEND_SEEN to ONCHAIN")
2852+
wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN")
2853+
2854+
# Both channels should go ONCHAIN!
2855+
assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"
2856+
2857+
28112858
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
28122859
def test_restorefrompeer(node_factory, bitcoind):
28132860
"""

tests/test_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,8 @@ def test_sql(node_factory, bitcoind):
37503750
'type': 'u32'},
37513751
{'name': 'ignore_fee_limits',
37523752
'type': 'boolean'},
3753+
{'name': 'lost_state',
3754+
'type': 'boolean'},
37533755
{'name': 'feerate_perkw',
37543756
'type': 'u32'},
37553757
{'name': 'feerate_perkb',

0 commit comments

Comments
 (0)