@@ -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" )
28122859def test_restorefrompeer (node_factory , bitcoind ):
28132860 """
0 commit comments