]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Upgrade to LDK 0.0.117
authorMatt Corallo <git@bluematt.me>
Mon, 18 Sep 2023 04:43:32 +0000 (04:43 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 15 Oct 2023 17:14:03 +0000 (17:14 +0000)
Cargo.toml
src/args.rs
src/cli.rs
src/main.rs
src/sweep.rs

index dbd703e71d652b9cd7e05a3f24d807a000e36b0b..adac61dae1a692c9701cae0d3ea040d36d53fd0b 100644 (file)
@@ -8,13 +8,13 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-lightning = { version = "0.0.116", features = ["max_level_trace"] }
-lightning-block-sync = { version = "0.0.116", features = [ "rpc-client" ] }
-lightning-invoice = { version = "0.24.0" }
-lightning-net-tokio = { version = "0.0.116" }
-lightning-persister = { version = "0.0.116" }
-lightning-background-processor = { version = "0.0.116", features = [ "futures" ] }
-lightning-rapid-gossip-sync = { version = "0.0.116" }
+lightning = { version = "0.0.117", features = ["max_level_trace"] }
+lightning-block-sync = { version = "0.0.117", features = [ "rpc-client" ] }
+lightning-invoice = { version = "0.25.0" }
+lightning-net-tokio = { version = "0.0.117" }
+lightning-persister = { version = "0.0.117" }
+lightning-background-processor = { version = "0.0.117", features = [ "futures" ] }
+lightning-rapid-gossip-sync = { version = "0.0.117" }
 
 base64 = "0.13.0"
 bitcoin = "0.29.0"
index b6ae379afb487452996b311e17b52b8e49e5f1dc..3778aa20d24d80395c1c988e80873b683c76d822 100644 (file)
@@ -1,10 +1,9 @@
 use crate::cli::LdkUserInfo;
 use bitcoin::network::constants::Network;
-use lightning::ln::msgs::NetAddress;
+use lightning::ln::msgs::SocketAddress;
 use std::collections::HashMap;
 use std::env;
 use std::fs;
-use std::net::IpAddr;
 use std::path::{Path, PathBuf};
 use std::str::FromStr;
 
@@ -86,18 +85,12 @@ pub(crate) fn parse_startup_args() -> Result<LdkUserInfo, ()> {
        let mut ldk_announced_listen_addr = Vec::new();
        loop {
                match env::args().skip(arg_idx + 1).next().as_ref() {
-                       Some(s) => match IpAddr::from_str(s) {
-                               Ok(IpAddr::V4(a)) => {
-                                       ldk_announced_listen_addr
-                                               .push(NetAddress::IPv4 { addr: a.octets(), port: ldk_peer_listening_port });
+                       Some(s) => match SocketAddress::from_str(s) {
+                               Ok(sa) => {
+                                       ldk_announced_listen_addr.push(sa);
                                        arg_idx += 1;
                                }
-                               Ok(IpAddr::V6(a)) => {
-                                       ldk_announced_listen_addr
-                                               .push(NetAddress::IPv6 { addr: a.octets(), port: ldk_peer_listening_port });
-                                       arg_idx += 1;
-                               }
-                               Err(_) => panic!("Failed to parse announced-listen-addr into an IP address"),
+                               Err(_) => panic!("Failed to parse announced-listen-addr into a socket address"),
                        },
                        None => break,
                }
index 75b79673a11ba8aa342275c78b0042d0a97073f1..121aa98554b1126944509f8c7f5945af9b4dc3e7 100644 (file)
@@ -9,19 +9,19 @@ use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::PublicKey;
 use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
-use lightning::ln::msgs::NetAddress;
-use lightning::ln::{PaymentHash, PaymentPreimage};
+use lightning::ln::msgs::SocketAddress;
+use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
 use lightning::onion_message::OnionMessagePath;
 use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
 use lightning::routing::gossip::NodeId;
 use lightning::routing::router::{PaymentParameters, RouteParameters};
 use lightning::sign::{EntropySource, KeysManager};
 use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
-use lightning::util::persist::KVStorePersister;
+use lightning::util::persist::KVStore;
 use lightning::util::ser::{Writeable, Writer};
 use lightning_invoice::payment::pay_invoice;
 use lightning_invoice::{utils, Bolt11Invoice, Currency};
-use lightning_persister::FilesystemPersister;
+use lightning_persister::fs_store::FilesystemStore;
 use std::env;
 use std::io;
 use std::io::Write;
@@ -38,7 +38,7 @@ pub(crate) struct LdkUserInfo {
        pub(crate) bitcoind_rpc_host: String,
        pub(crate) ldk_storage_dir_path: String,
        pub(crate) ldk_peer_listening_port: u16,
-       pub(crate) ldk_announced_listen_addr: Vec<NetAddress>,
+       pub(crate) ldk_announced_listen_addr: Vec<SocketAddress>,
        pub(crate) ldk_announced_node_name: [u8; 32],
        pub(crate) network: Network,
 }
@@ -65,7 +65,7 @@ pub(crate) fn poll_for_user_input(
        keys_manager: Arc<KeysManager>, network_graph: Arc<NetworkGraph>,
        onion_messenger: Arc<OnionMessenger>, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
        outbound_payments: Arc<Mutex<PaymentInfoStorage>>, ldk_data_dir: String, network: Network,
-       logger: Arc<disk::FilesystemLogger>, persister: Arc<FilesystemPersister>,
+       logger: Arc<disk::FilesystemLogger>, persister: Arc<FilesystemStore>,
 ) {
        println!(
                "LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
@@ -247,7 +247,9 @@ pub(crate) fn poll_for_user_input(
                                                expiry_secs.unwrap(),
                                                Arc::clone(&logger),
                                        );
-                                       persister.persist(INBOUND_PAYMENTS_FNAME, &*inbound_payments).unwrap();
+                                       persister
+                                               .write("", "", INBOUND_PAYMENTS_FNAME, &inbound_payments.encode())
+                                               .unwrap();
                                }
                                "connectpeer" => {
                                        let peer_pubkey_and_ip_addr = words.next();
@@ -515,7 +517,7 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
        for chan_info in channel_manager.list_channels() {
                println!("");
                println!("\t{{");
-               println!("\t\tchannel_id: {},", hex_utils::hex_str(&chan_info.channel_id[..]));
+               println!("\t\tchannel_id: {},", chan_info.channel_id);
                if let Some(funding_txo) = chan_info.funding_txo {
                        println!("\t\tfunding_txid: {},", funding_txo.txid);
                }
@@ -539,7 +541,7 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
                }
                println!("\t\tis_channel_ready: {},", chan_info.is_channel_ready);
                println!("\t\tchannel_value_satoshis: {},", chan_info.channel_value_satoshis);
-               println!("\t\tlocal_balance_msat: {},", chan_info.balance_msat);
+               println!("\t\toutbound_capacity_msat: {},", chan_info.outbound_capacity_msat);
                if chan_info.is_usable {
                        println!("\t\tavailable_balance_for_send_msat: {},", chan_info.outbound_capacity_msat);
                        println!("\t\tavailable_balance_for_recv_msat: {},", chan_info.inbound_capacity_msat);
@@ -682,7 +684,7 @@ fn open_channel(
 
 fn send_payment(
        channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
-       outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemPersister>,
+       outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemStore>,
 ) {
        let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
        let payment_secret = Some(*invoice.payment_secret());
@@ -695,7 +697,7 @@ fn send_payment(
                        amt_msat: MillisatAmount(invoice.amount_milli_satoshis()),
                },
        );
-       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound_payments).unwrap();
+       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
        match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) {
                Ok(_payment_id) => {
                        let payee_pubkey = invoice.recover_payee_pub_key();
@@ -707,22 +709,22 @@ fn send_payment(
                        println!("ERROR: failed to send payment: {:?}", e);
                        print!("> ");
                        outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
-                       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound_payments).unwrap();
+                       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
                }
        };
 }
 
 fn keysend<E: EntropySource>(
        channel_manager: &ChannelManager, payee_pubkey: PublicKey, amt_msat: u64, entropy_source: &E,
-       outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemPersister>,
+       outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemStore>,
 ) {
        let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
        let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
 
-       let route_params = RouteParameters {
-               payment_params: PaymentParameters::for_keysend(payee_pubkey, 40, false),
-               final_value_msat: amt_msat,
-       };
+       let route_params = RouteParameters::from_payment_params_and_value(
+               PaymentParameters::for_keysend(payee_pubkey, 40, false),
+               amt_msat,
+       );
        outbound_payments.payments.insert(
                payment_hash,
                PaymentInfo {
@@ -732,7 +734,7 @@ fn keysend<E: EntropySource>(
                        amt_msat: MillisatAmount(Some(amt_msat)),
                },
        );
-       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound_payments).unwrap();
+       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
        match channel_manager.send_spontaneous_payment_with_retry(
                Some(payment_preimage),
                RecipientOnionFields::spontaneous_empty(),
@@ -748,7 +750,7 @@ fn keysend<E: EntropySource>(
                        println!("ERROR: failed to send payment: {:?}", e);
                        print!("> ");
                        outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
-                       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound_payments).unwrap();
+                       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
                }
        };
 }
@@ -799,7 +801,7 @@ fn get_invoice(
 fn close_channel(
        channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
 ) {
-       match channel_manager.close_channel(&channel_id, &counterparty_node_id) {
+       match channel_manager.close_channel(&ChannelId(channel_id), &counterparty_node_id) {
                Ok(()) => println!("EVENT: initiating channel close"),
                Err(e) => println!("ERROR: failed to close channel: {:?}", e),
        }
@@ -808,7 +810,9 @@ fn close_channel(
 fn force_close_channel(
        channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
 ) {
-       match channel_manager.force_close_broadcasting_latest_txn(&channel_id, &counterparty_node_id) {
+       match channel_manager
+               .force_close_broadcasting_latest_txn(&ChannelId(channel_id), &counterparty_node_id)
+       {
                Ok(()) => println!("EVENT: initiating channel force-close"),
                Err(e) => println!("ERROR: failed to force-close channel: {:?}", e),
        }
index 40240a729711bd33d5c708730b2fb8a44c24615a..69f0981ca4091403f827f5861258166a2087c5ce 100644 (file)
@@ -24,7 +24,7 @@ use lightning::ln::channelmanager::{
 };
 use lightning::ln::msgs::DecodeError;
 use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager};
-use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
+use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
 use lightning::onion_message::{DefaultMessageRouter, SimpleArcOnionMessenger};
 use lightning::routing::gossip;
 use lightning::routing::gossip::{NodeId, P2PGossipSync};
@@ -32,7 +32,7 @@ use lightning::routing::router::DefaultRouter;
 use lightning::routing::scoring::ProbabilisticScoringFeeParameters;
 use lightning::sign::{EntropySource, InMemorySigner, KeysManager, SpendableOutputDescriptor};
 use lightning::util::config::UserConfig;
-use lightning::util::persist::KVStorePersister;
+use lightning::util::persist::{self, read_channel_monitors, KVStore};
 use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
 use lightning::{chain, impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
 use lightning_background_processor::{process_events_async, GossipSync};
@@ -41,7 +41,7 @@ use lightning_block_sync::poll;
 use lightning_block_sync::SpvClient;
 use lightning_block_sync::UnboundedCache;
 use lightning_net_tokio::SocketDescriptor;
-use lightning_persister::FilesystemPersister;
+use lightning_persister::fs_store::FilesystemStore;
 use rand::{thread_rng, Rng};
 use std::collections::hash_map::Entry;
 use std::collections::HashMap;
@@ -53,7 +53,7 @@ use std::io;
 use std::io::Write;
 use std::path::Path;
 use std::sync::atomic::{AtomicBool, Ordering};
-use std::sync::{Arc, Mutex};
+use std::sync::{Arc, Mutex, RwLock};
 use std::time::{Duration, SystemTime};
 
 pub(crate) const PENDING_SPENDABLE_OUTPUT_DIR: &'static str = "pending_spendable_outputs";
@@ -123,7 +123,7 @@ type ChainMonitor = chainmonitor::ChainMonitor<
        Arc<BitcoindClient>,
        Arc<BitcoindClient>,
        Arc<FilesystemLogger>,
-       Arc<FilesystemPersister>,
+       Arc<FilesystemStore>,
 >;
 
 pub(crate) type PeerManager = SimpleArcPeerManager<
@@ -131,7 +131,7 @@ pub(crate) type PeerManager = SimpleArcPeerManager<
        ChainMonitor,
        BitcoindClient,
        BitcoindClient,
-       BitcoindClient,
+       Arc<BitcoindClient>,
        FilesystemLogger,
 >;
 
@@ -153,7 +153,7 @@ async fn handle_ldk_events(
        channel_manager: &Arc<ChannelManager>, bitcoind_client: &BitcoindClient,
        network_graph: &NetworkGraph, keys_manager: &KeysManager,
        bump_tx_event_handler: &BumpTxEventHandler, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
-       outbound_payments: Arc<Mutex<PaymentInfoStorage>>, persister: &Arc<FilesystemPersister>,
+       outbound_payments: Arc<Mutex<PaymentInfoStorage>>, persister: &Arc<FilesystemStore>,
        network: Network, event: Event,
 ) {
        match event {
@@ -229,7 +229,14 @@ async fn handle_ldk_events(
                        };
                        channel_manager.claim_funds(payment_preimage.unwrap());
                }
-               Event::PaymentClaimed { payment_hash, purpose, amount_msat, receiver_node_id: _ } => {
+               Event::PaymentClaimed {
+                       payment_hash,
+                       purpose,
+                       amount_msat,
+                       receiver_node_id: _,
+                       htlcs: _,
+                       sender_intended_total_msat: _,
+               } => {
                        println!(
                                "\nEVENT: claimed payment from payment hash {} of {} millisatoshis",
                                hex_utils::hex_str(&payment_hash.0),
@@ -260,7 +267,7 @@ async fn handle_ldk_events(
                                        });
                                }
                        }
-                       persister.persist(INBOUND_PAYMENTS_FNAME, &*inbound).unwrap();
+                       persister.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap();
                }
                Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
                        let mut outbound = outbound_payments.lock().unwrap();
@@ -284,7 +291,7 @@ async fn handle_ldk_events(
                                        io::stdout().flush().unwrap();
                                }
                        }
-                       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound).unwrap();
+                       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
                }
                Event::OpenChannelRequest {
                        ref temporary_channel_id, ref counterparty_node_id, ..
@@ -301,14 +308,14 @@ async fn handle_ldk_events(
                        if let Err(e) = res {
                                print!(
                                        "\nEVENT: Failed to accept inbound channel ({}) from {}: {:?}",
-                                       hex_utils::hex_str(&temporary_channel_id[..]),
+                                       temporary_channel_id,
                                        hex_utils::hex_str(&counterparty_node_id.serialize()),
                                        e,
                                );
                        } else {
                                print!(
                                        "\nEVENT: Accepted inbound channel ({}) from {}",
-                                       hex_utils::hex_str(&temporary_channel_id[..]),
+                                       temporary_channel_id,
                                        hex_utils::hex_str(&counterparty_node_id.serialize()),
                                );
                        }
@@ -333,7 +340,7 @@ async fn handle_ldk_events(
                                let payment = outbound.payments.get_mut(&payment_hash).unwrap();
                                payment.status = HTLCStatus::Failed;
                        }
-                       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound).unwrap();
+                       persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
                }
                Event::PaymentForwarded {
                        prev_channel_id,
@@ -346,7 +353,7 @@ async fn handle_ldk_events(
                        let nodes = read_only_network_graph.nodes();
                        let channels = channel_manager.list_channels();
 
-                       let node_str = |channel_id: &Option<[u8; 32]>| match channel_id {
+                       let node_str = |channel_id: &Option<ChannelId>| match channel_id {
                                None => String::new(),
                                Some(channel_id) => match channels.iter().find(|c| c.channel_id == *channel_id) {
                                        None => String::new(),
@@ -363,9 +370,9 @@ async fn handle_ldk_events(
                                        }
                                },
                        };
-                       let channel_str = |channel_id: &Option<[u8; 32]>| {
+                       let channel_str = |channel_id: &Option<ChannelId>| {
                                channel_id
-                                       .map(|channel_id| format!(" with channel {}", hex_utils::hex_str(&channel_id)))
+                                       .map(|channel_id| format!(" with channel {}", channel_id))
                                        .unwrap_or_default()
                        };
                        let from_prev_str =
@@ -407,7 +414,7 @@ async fn handle_ldk_events(
                                forwarding_channel_manager.process_pending_htlc_forwards();
                        });
                }
-               Event::SpendableOutputs { outputs } => {
+               Event::SpendableOutputs { outputs, channel_id: _ } => {
                        // SpendableOutputDescriptors, of which outputs is a vec of, are critical to keep track
                        // of! While a `StaticOutput` descriptor is just an output to a static, well-known key,
                        // other descriptors are not currently ever regenerated for you by LDK. Once we return
@@ -421,15 +428,13 @@ async fn handle_ldk_events(
                                let key = hex_utils::hex_str(&keys_manager.get_secure_random_bytes());
                                // Note that if the type here changes our read code needs to change as well.
                                let output: SpendableOutputDescriptor = output;
-                               persister
-                                       .persist(&format!("{}/{}", PENDING_SPENDABLE_OUTPUT_DIR, key), &output)
-                                       .unwrap();
+                               persister.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap();
                        }
                }
                Event::ChannelPending { channel_id, counterparty_node_id, .. } => {
                        println!(
                                "\nEVENT: Channel {} with peer {} is pending awaiting funding lock-in!",
-                               hex_utils::hex_str(&channel_id),
+                               channel_id,
                                hex_utils::hex_str(&counterparty_node_id.serialize()),
                        );
                        print!("> ");
@@ -443,16 +448,23 @@ async fn handle_ldk_events(
                } => {
                        println!(
                                "\nEVENT: Channel {} with peer {} is ready to be used!",
-                               hex_utils::hex_str(channel_id),
+                               channel_id,
                                hex_utils::hex_str(&counterparty_node_id.serialize()),
                        );
                        print!("> ");
                        io::stdout().flush().unwrap();
                }
-               Event::ChannelClosed { channel_id, reason, user_channel_id: _ } => {
+               Event::ChannelClosed {
+                       channel_id,
+                       reason,
+                       user_channel_id: _,
+                       counterparty_node_id,
+                       channel_capacity_sats: _,
+               } => {
                        println!(
-                               "\nEVENT: Channel {} closed due to: {:?}",
-                               hex_utils::hex_str(&channel_id),
+                               "\nEVENT: Channel {} with counterparty {} closed due to: {:?}",
+                               channel_id,
+                               counterparty_node_id.map(|id| format!("{}", id)).unwrap_or("".to_owned()),
                                reason
                        );
                        print!("> ");
@@ -527,7 +539,7 @@ async fn start_ldk() {
        let broadcaster = bitcoind_client.clone();
 
        // Step 4: Initialize Persist
-       let persister = Arc::new(FilesystemPersister::new(ldk_data_dir.clone()));
+       let persister = Arc::new(FilesystemStore::new(ldk_data_dir.clone().into()));
 
        // Step 5: Initialize the ChainMonitor
        let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
@@ -575,7 +587,8 @@ async fn start_ldk() {
 
        // Step 7: Read ChannelMonitor state from disk
        let mut channelmonitors =
-               persister.read_channelmonitors(keys_manager.clone(), keys_manager.clone()).unwrap();
+               read_channel_monitors(Arc::clone(&persister), keys_manager.clone(), keys_manager.clone())
+                       .unwrap();
 
        // Step 8: Poll for the best chain tip, which may be used by the channel manager & spv client
        let polled_chain_tip = init::validate_best_block_header(bitcoind_client.as_ref())
@@ -588,7 +601,7 @@ async fn start_ldk() {
                Arc::new(disk::read_network(Path::new(&network_graph_path), args.network, logger.clone()));
 
        let scorer_path = format!("{}/scorer", ldk_data_dir.clone());
-       let scorer = Arc::new(Mutex::new(disk::read_scorer(
+       let scorer = Arc::new(RwLock::new(disk::read_scorer(
                Path::new(&scorer_path),
                Arc::clone(&network_graph),
                Arc::clone(&logger),
@@ -697,7 +710,7 @@ async fn start_ldk() {
                let funding_outpoint = item.2;
                assert_eq!(
                        chain_monitor.watch_channel(funding_outpoint, channel_monitor),
-                       ChannelMonitorUpdateStatus::Completed
+                       Ok(ChannelMonitorUpdateStatus::Completed)
                );
        }
 
@@ -790,8 +803,9 @@ async fn start_ldk() {
                .into_iter()
                .filter_map(|p| match p {
                        RecentPaymentDetails::Pending { payment_hash, .. } => Some(payment_hash),
-                       RecentPaymentDetails::Fulfilled { payment_hash } => payment_hash,
-                       RecentPaymentDetails::Abandoned { payment_hash } => Some(payment_hash),
+                       RecentPaymentDetails::Fulfilled { payment_hash, .. } => payment_hash,
+                       RecentPaymentDetails::Abandoned { payment_hash, .. } => Some(payment_hash),
+                       RecentPaymentDetails::AwaitingInvoice { payment_id: _ } => todo!(),
                })
                .collect::<Vec<PaymentHash>>();
        for (payment_hash, payment_info) in outbound_payments
@@ -805,7 +819,9 @@ async fn start_ldk() {
                        payment_info.status = HTLCStatus::Failed;
                }
        }
-       persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound_payments.lock().unwrap()).unwrap();
+       persister
+               .write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.lock().unwrap().encode())
+               .unwrap();
 
        // Step 18: Handle LDK Events
        let channel_manager_event_listener = Arc::clone(&channel_manager);
@@ -843,7 +859,7 @@ async fn start_ldk() {
        };
 
        // Step 19: Persist ChannelManager and NetworkGraph
-       let persister = Arc::new(FilesystemPersister::new(ldk_data_dir.clone()));
+       let persister = Arc::new(FilesystemStore::new(ldk_data_dir.clone().into()));
 
        // Step 20: Background Processing
        let (bp_exit, bp_exit_check) = tokio::sync::watch::channel(());
@@ -871,7 +887,7 @@ async fn start_ldk() {
        // Regularly reconnect to channel peers.
        let connect_cm = Arc::clone(&channel_manager);
        let connect_pm = Arc::clone(&peer_manager);
-       let peer_data_path = format!("{}/channel_peer_data", ldk_data_dir.clone());
+       let peer_data_path = format!("{}/channel_peer_data", ldk_data_dir);
        let stop_connect = Arc::clone(&stop_listen_connect);
        tokio::spawn(async move {
                let mut interval = tokio::time::interval(Duration::from_secs(1));
@@ -979,7 +995,14 @@ async fn start_ldk() {
        peer_manager.disconnect_all_peers();
 
        if let Err(e) = bg_res {
-               let persist_res = persister.persist("manager", &*channel_manager).unwrap();
+               let persist_res = persister
+                       .write(
+                               persist::CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
+                               persist::CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
+                               persist::CHANNEL_MANAGER_PERSISTENCE_KEY,
+                               &channel_manager.encode(),
+                       )
+                       .unwrap();
                use lightning::util::logger::Logger;
                lightning::log_error!(
                        &*logger,
index 94120f9088ba377a659faf867ac394d1981ee80a..01cea9d32bbc7c042d4a7b457015b23a01409d4d 100644 (file)
@@ -7,8 +7,10 @@ use std::{fs, io};
 use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
 use lightning::sign::{EntropySource, KeysManager, SpendableOutputDescriptor};
 use lightning::util::logger::Logger;
-use lightning::util::persist::KVStorePersister;
-use lightning::util::ser::{Readable, WithoutLength};
+use lightning::util::persist::KVStore;
+use lightning::util::ser::{Readable, WithoutLength, Writeable};
+
+use lightning_persister::fs_store::FilesystemStore;
 
 use bitcoin::secp256k1::Secp256k1;
 use bitcoin::{LockTime, PackedLockTime};
@@ -18,7 +20,6 @@ use crate::hex_utils;
 use crate::BitcoindClient;
 use crate::ChannelManager;
 use crate::FilesystemLogger;
-use crate::FilesystemPersister;
 
 /// If we have any pending claimable outputs, we should slowly sweep them to our Bitcoin Core
 /// wallet. We technically don't need to do this - they're ours to spend when we want and can just
@@ -30,7 +31,7 @@ use crate::FilesystemPersister;
 /// we don't do that here either.
 pub(crate) async fn periodic_sweep(
        ldk_data_dir: String, keys_manager: Arc<KeysManager>, logger: Arc<FilesystemLogger>,
-       persister: Arc<FilesystemPersister>, bitcoind_client: Arc<BitcoindClient>,
+       persister: Arc<FilesystemStore>, bitcoind_client: Arc<BitcoindClient>,
        channel_manager: Arc<ChannelManager>,
 ) {
        // Regularly claim outputs which are exclusively spendable by us and send them to Bitcoin Core.
@@ -79,7 +80,7 @@ pub(crate) async fn periodic_sweep(
                        if !outputs.is_empty() {
                                let key = hex_utils::hex_str(&keys_manager.get_secure_random_bytes());
                                persister
-                                       .persist(&format!("spendable_outputs/{}", key), &WithoutLength(&outputs))
+                                       .write("spendable_outputs", "", &key, &WithoutLength(&outputs).encode())
                                        .unwrap();
                                fs::remove_dir_all(&processing_spendables_dir).unwrap();
                        }