Skip to content

Commit

Permalink
tests/test_misc.py: Add test_recover_plugin to check if the funds are…
Browse files Browse the repository at this point in the history
… being recovered when we lose some state and enter recover mode.
  • Loading branch information
adi2011 committed Feb 14, 2024
1 parent bc3b890 commit da547bc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,58 @@ def test_emergencyrecover(node_factory, bitcoind):
assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"


@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "sqlite3-specific DB rollback")
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
def test_recover_plugin(node_factory, bitcoind):
l1 = node_factory.get_node(may_reconnect=True, options={'log-level': 'info', 'experimental-peer-storage': None},
allow_warning=True,
feerates=(7500, 7500, 7500, 7500))
l2 = node_factory.get_node(may_reconnect=True, options={'log-level': 'info', 'experimental-peer-storage': None},
feerates=(7500, 7500, 7500, 7500), allow_broken_log=True, allow_bad_gossip=True)

l3 = node_factory.get_node(may_reconnect=True, options={'log-level': 'info', 'experimental-peer-storage': None},
feerates=(7500, 7500, 7500, 7500), allow_broken_log=True)

l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l2.fundchannel(l1, 10**6)
mine_funding_to_announce(bitcoind, [l1, l2, l3])

l2.stop()

# Save copy of the db.
dbpath = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3")
orig_db = open(dbpath, "rb").read()
l2.start()

l2.rpc.connect(l3.info['id'], 'localhost', l3.port)

l2.fundchannel(l3, 10**6)
mine_funding_to_announce(bitcoind, [l1, l2, l3])

l2.pay(l1, 200000000)

# Now, move l2 back in time.
l2.stop()

# Overwrite with OLD db.
open(dbpath, "wb").write(orig_db)
l2.start()

bitcoind.generate_block(5, wait_for_mempool=1)
sync_blockheight(bitcoind, [l1, l2, l3])

l2.daemon.wait_for_log(f"{l3.info['id']}-chan#2: State changed from FUNDING_SPEND_SEEN to ONCHAIN")
wait_for(lambda: l2.rpc.listfunds()["channels"][1]["state"] == "ONCHAIN")

l2.daemon.wait_for_log(f"{l1.info['id']}-chan#1: State changed from FUNDING_SPEND_SEEN to ONCHAIN")
wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN")

# Both channels should go ONCHAIN!
assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"
assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"


@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
def test_restorefrompeer(node_factory, bitcoind):
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3750,6 +3750,8 @@ def test_sql(node_factory, bitcoind):
'type': 'u32'},
{'name': 'ignore_fee_limits',
'type': 'boolean'},
{'name': 'lost_state',
'type': 'boolean'},
{'name': 'feerate_perkw',
'type': 'u32'},
{'name': 'feerate_perkb',
Expand Down

0 comments on commit da547bc

Please sign in to comment.