Test restorefrompeer
(node_factory, bitcoind)
| 3299 | |
| 3300 | @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3") |
| 3301 | def test_restorefrompeer(node_factory, bitcoind): |
| 3302 | """ |
| 3303 | Test restorefrompeer |
| 3304 | """ |
| 3305 | l1, l2 = node_factory.get_nodes(2, [{'broken_log': 'ERROR: Unknown commitment #.*, recovering our funds!', |
| 3306 | 'may_reconnect': True, |
| 3307 | 'allow_bad_gossip': True}, |
| 3308 | {'may_reconnect': True}]) |
| 3309 | |
| 3310 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3311 | |
| 3312 | c12, _ = l1.fundchannel(l2, 10**5) |
| 3313 | assert l1.daemon.is_in_log('Peer storage sent!') |
| 3314 | assert l2.daemon.is_in_log('Peer storage sent!') |
| 3315 | |
| 3316 | # Note: each node may or may not send peer_storage_retrieval: if it |
| 3317 | # receives storage fast enough, it will, otherwise not. |
| 3318 | l1.rpc.disconnect(l2.info['id'], force=True) |
| 3319 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3320 | l1.daemon.wait_for_logs(['peer_out WIRE_PEER_STORAGE', |
| 3321 | 'peer_in WIRE_PEER_STORAGE']) |
| 3322 | l2.daemon.wait_for_logs(['peer_out WIRE_PEER_STORAGE', |
| 3323 | 'peer_in WIRE_PEER_STORAGE']) |
| 3324 | |
| 3325 | l1.stop() |
| 3326 | os.unlink(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3")) |
| 3327 | |
| 3328 | l1.start() |
| 3329 | assert l1.daemon.is_in_log('Server started with public key') |
| 3330 | |
| 3331 | # If this happens fast enough, connect fails with "disconnected |
| 3332 | # during connection" |
| 3333 | try: |
| 3334 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3335 | except RpcError as err: |
| 3336 | assert "disconnected during connection" in err.error['message'] |
| 3337 | |
| 3338 | l1.daemon.wait_for_log('peer_in WIRE_PEER_STORAGE_RETRIEVAL') |
| 3339 | |
| 3340 | assert l1.rpc.restorefrompeer()['stubs'][0] == _['channel_id'] |
| 3341 | |
| 3342 | l1.daemon.wait_for_log('Sending a bogus channel_reestablish message to make the peer unilaterally close the channel.') |
| 3343 | l1.daemon.wait_for_log('peer_out WIRE_ERROR') |
| 3344 | |
| 3345 | l2.daemon.wait_for_log('State changed from CHANNELD_NORMAL to AWAITING_UNILATERAL') |
| 3346 | |
| 3347 | bitcoind.generate_block(5, wait_for_mempool=1) |
| 3348 | sync_blockheight(bitcoind, [l1, l2]) |
| 3349 | |
| 3350 | l1.daemon.wait_for_log(r'All outputs resolved.*') |
| 3351 | wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") |
| 3352 | |
| 3353 | # Check if funds are recovered. |
| 3354 | wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") |
| 3355 | wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") |
| 3356 | |
| 3357 | |
| 3358 | def test_commitfee_option(node_factory): |
nothing calls this directly
no test coverage detected