@@ -27,6 +27,7 @@ use common::{
2727 TestSyncStore ,
2828} ;
2929use ldk_node:: config:: { AsyncPaymentsRole , EsploraSyncConfig } ;
30+ use ldk_node:: entropy:: NodeEntropy ;
3031use ldk_node:: liquidity:: LSPS2ServiceConfig ;
3132use ldk_node:: payment:: {
3233 ConfirmationStatus , PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus ,
@@ -39,6 +40,7 @@ use lightning::routing::router::RouteParametersConfig;
3940use lightning_invoice:: { Bolt11InvoiceDescription , Description } ;
4041use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
4142use log:: LevelFilter ;
43+ use rand:: { rng, Rng } ;
4244
4345#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
4446async fn channel_full_cycle ( ) {
@@ -2436,3 +2438,65 @@ async fn payment_persistence_after_restart() {
24362438
24372439 restarted_node_a. stop ( ) . unwrap ( ) ;
24382440}
2441+
2442+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
2443+ async fn persistence_backwards_compatibility ( ) {
2444+ let ( bitcoind, electrsd) = common:: setup_bitcoind_and_electrsd ( ) ;
2445+ let esplora_url = format ! ( "http://{}" , electrsd. esplora_url. as_ref( ) . unwrap( ) ) ;
2446+
2447+ let storage_path = common:: random_storage_path ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) ;
2448+ let seed_bytes = [ 42u8 ; 64 ] ;
2449+ let node_entropy = NodeEntropy :: from_seed_bytes ( seed_bytes) ;
2450+
2451+ // Setup a v0.6.2 `Node` persisted with the v0 scheme.
2452+ let ( old_balance, old_node_id) = {
2453+ let mut builder_old = ldk_node_062:: Builder :: new ( ) ;
2454+ builder_old. set_network ( bitcoin:: Network :: Regtest ) ;
2455+ builder_old. set_storage_dir_path ( storage_path. clone ( ) ) ;
2456+ builder_old. set_entropy_seed_bytes ( seed_bytes) ;
2457+ builder_old. set_chain_source_esplora ( esplora_url. clone ( ) , None ) ;
2458+ let node_old = builder_old. build ( ) . unwrap ( ) ;
2459+
2460+ node_old. start ( ) . unwrap ( ) ;
2461+ let addr_old = node_old. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
2462+ common:: premine_and_distribute_funds (
2463+ & bitcoind. client ,
2464+ & electrsd. client ,
2465+ vec ! [ addr_old] ,
2466+ bitcoin:: Amount :: from_sat ( 100_000 ) ,
2467+ )
2468+ . await ;
2469+ node_old. sync_wallets ( ) . unwrap ( ) ;
2470+
2471+ let balance = node_old. list_balances ( ) . spendable_onchain_balance_sats ;
2472+ assert ! ( balance > 0 ) ;
2473+ let node_id = node_old. node_id ( ) ;
2474+
2475+ // Workaround necessary as v0.6.2's VSS runtime wasn't dropsafe in a tokio context.
2476+ tokio:: task:: block_in_place ( move || {
2477+ node_old. stop ( ) . unwrap ( ) ;
2478+ drop ( node_old) ;
2479+ } ) ;
2480+
2481+ ( balance, node_id)
2482+ } ;
2483+
2484+ // Now ensure we can still reinit from the same backend.
2485+ let mut builder_new = Builder :: new ( ) ;
2486+ builder_new. set_network ( bitcoin:: Network :: Regtest ) ;
2487+ builder_new. set_storage_dir_path ( storage_path) ;
2488+ builder_new. set_chain_source_esplora ( esplora_url, None ) ;
2489+
2490+ let node_new = builder_new. build ( node_entropy) . unwrap ( ) ;
2491+
2492+ node_new. start ( ) . unwrap ( ) ;
2493+ node_new. sync_wallets ( ) . unwrap ( ) ;
2494+
2495+ let new_balance = node_new. list_balances ( ) . spendable_onchain_balance_sats ;
2496+ let new_node_id = node_new. node_id ( ) ;
2497+
2498+ assert_eq ! ( old_node_id, new_node_id) ;
2499+ assert_eq ! ( old_balance, new_balance) ;
2500+
2501+ node_new. stop ( ) . unwrap ( ) ;
2502+ }
0 commit comments