MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_recover_plugin

Function test_recover_plugin

tests/test_misc.py:3250–3297  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

3248@pytest.mark.openchannel('v1')
3249@pytest.mark.openchannel('v2')
3250def test_recover_plugin(node_factory, bitcoind):
3251 l1, l2 = node_factory.get_nodes(2, opts=[{'may_reconnect': True,
3252 'dev-no-reconnect': None},
3253 {'may_reconnect': True,
3254 'dev-no-reconnect': None,
3255 'broken_log': 'Cannot broadcast our commitment tx: they have a future one|ERROR: Unknown commitment #[0-9]*, recovering our funds!'}])
3256
3257 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
3258 l2.fundchannel(l1, 10**6)
3259 mine_funding_to_announce(bitcoind, [l1, l2])
3260
3261 l2.stop()
3262
3263 # Save copy of the db.
3264 dbpath = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3")
3265 orig_db = Path(dbpath).read_bytes()
3266
3267 l2.start()
3268
3269 assert l2.daemon.is_in_log('Server started with public key')
3270 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
3271
3272 # successful payments
3273 i31 = l1.rpc.invoice(10000, 'i31', 'desc')
3274 l2.rpc.xpay(i31['bolt11'])
3275
3276 # Now, move l2 back in time.
3277 l2.stop()
3278
3279 # Overwrite with OLD db.
3280 Path(dbpath).write_bytes(orig_db)
3281
3282 l2.start()
3283
3284 # Force a reconnect, so l2 learns that it went back in time.
3285 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
3286
3287 # Starting the node again causes it to reconnect, and discover
3288 # that it lost state. This in turn causes the peer to close the
3289 # channel for us. Here we wait for the close transaction.
3290 bitcoind.generate_block(5, wait_for_mempool=1)
3291 sync_blockheight(bitcoind, [l1, l2])
3292
3293 l2.daemon.wait_for_log(f"{l1.info['id']}-chan#1: State changed from FUNDING_SPEND_SEEN to ONCHAIN")
3294 wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN")
3295
3296 # Both channels should go ONCHAIN!
3297 assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN"
3298
3299
3300@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")

Callers

nothing calls this directly

Calls 15

mine_funding_to_announceFunction · 0.90
sync_blockheightFunction · 0.90
wait_forFunction · 0.90
get_nodesMethod · 0.80
joinMethod · 0.80
is_in_logMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
stopMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected