]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Update to LDK v0.0.114
authorValentine Wallace <vwallace@protonmail.com>
Tue, 7 Mar 2023 17:02:36 +0000 (12:02 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 7 Mar 2023 17:02:38 +0000 (12:02 -0500)
Cargo.lock
Cargo.toml
src/bitcoind_client.rs
src/cli.rs
src/disk.rs
src/main.rs

index e3042e92a8c4ae4d7b593acdadd0cf6d1e0b7edc..c6b9c381974eddd8ff279954d83b84a05a750b5c 100644 (file)
@@ -347,18 +347,18 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
 
 [[package]]
 name = "lightning"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "087add70f81d2fdc6d4409bc0cef69e11ad366ef1d0068550159bd22b3ac8664"
+checksum = "800ec68a160529ba3ca12c5db629867c4a8de2df272792c1246602966a5b789b"
 dependencies = [
  "bitcoin",
 ]
 
 [[package]]
 name = "lightning-background-processor"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2288d211a2ab15e2c9fb492fb99c7998df1a37f228552f703824ee678b8980c9"
+checksum = "7af76b912df8827d9e6bde2fadbbb7b1e2d04f7da92009d244394bd2faa37380"
 dependencies = [
  "bitcoin",
  "lightning",
@@ -367,9 +367,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-block-sync"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2fc7227008536500026866e90d5e2db2da2725c5cdc7d19013df743d9de3e68"
+checksum = "71a6fcb6ffc245cf0aee4a4654145a2a7e670be2d879c14b8ed456cdc4235255"
 dependencies = [
  "bitcoin",
  "chunked_transfer",
@@ -381,9 +381,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-invoice"
-version = "0.21.0"
+version = "0.22.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e9680857590c3529cf8c7d32b04501f215f2bf1e029fdfa22f4112f66c1741e4"
+checksum = "adfb59c6d13e130aece30fc72a7c17d74b201aed0ffb201b740f36e07aaece32"
 dependencies = [
  "bech32 0.9.1",
  "bitcoin_hashes",
@@ -394,9 +394,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-net-tokio"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2e94b019ffcbd423c67bc8e65093d46cf5c00ff696b4b633936fce6e4d0cb845"
+checksum = "19197703db1195ed908ccd84cd76baaa5916e0d22750a2e1b7188f66516812bd"
 dependencies = [
  "bitcoin",
  "lightning",
@@ -405,9 +405,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-persister"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48b28023f8b84764e0b861389fc865a1a1dc3896616a14678ece389b0811fe04"
+checksum = "fce2d2ebf01ec7c9f4fad02846207999118a4ec3992c06d6eab93df7a862066c"
 dependencies = [
  "bitcoin",
  "libc",
@@ -417,9 +417,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-rapid-gossip-sync"
-version = "0.0.113"
+version = "0.0.114"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "488b68c7d24093d35a83f37c560e427f1085f4c5d37918b81b11d95cd3675a0f"
+checksum = "6073e6cac4019f39e0bb02d3c92ebbb22950a46a663059b3b0e19f7928e00edb"
 dependencies = [
  "bitcoin",
  "lightning",
index c7a063d519737a34d6c09c2daa86903e73ed3596..15c6c79104034cf6b066457263346cee2595baeb 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.113", features = ["max_level_trace"] }
-lightning-block-sync = { version = "0.0.113", features = [ "rpc-client" ] }
-lightning-invoice = { version = "0.21" }
-lightning-net-tokio = { version = "0.0.113" }
-lightning-persister = { version = "0.0.113" }
-lightning-background-processor = { version = "0.0.113" }
-lightning-rapid-gossip-sync = { version = "0.0.113" }
+lightning = { version = "0.0.114", features = ["max_level_trace"] }
+lightning-block-sync = { version = "0.0.114", features = [ "rpc-client" ] }
+lightning-invoice = { version = "0.22" }
+lightning-net-tokio = { version = "0.0.114" }
+lightning-persister = { version = "0.0.114" }
+lightning-background-processor = { version = "0.0.114" }
+lightning-rapid-gossip-sync = { version = "0.0.114" }
 
 base64 = "0.13.0"
 bitcoin = "0.29.0"
index 84efbfca331433d01dd810df44ea95495092e556..68843296ef48e38e2aa6af1602a785eccfe513a6 100644 (file)
@@ -5,6 +5,7 @@ use bitcoin::consensus::encode;
 use bitcoin::hash_types::{BlockHash, Txid};
 use bitcoin::util::address::Address;
 use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
+use lightning::routing::utxo::{UtxoLookup, UtxoResult};
 use lightning_block_sync::http::HttpEndpoint;
 use lightning_block_sync::rpc::RpcClient;
 use lightning_block_sync::{AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource};
@@ -273,3 +274,10 @@ impl BroadcasterInterface for BitcoindClient {
                });
        }
 }
+
+impl UtxoLookup for BitcoindClient {
+       fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
+               // P2PGossipSync takes None for a UtxoLookup, so this will never be called.
+               todo!();
+       }
+}
index b4b7a1c769b8f617e35ad76470d2dbe87f950bb7..9e5e20b1b9ec1df1abb56669e23d738b9fc2f40a 100644 (file)
@@ -1,22 +1,23 @@
 use crate::disk;
 use crate::hex_utils;
 use crate::{
-       ChannelManager, HTLCStatus, InvoicePayer, MillisatAmount, NetworkGraph, OnionMessenger,
-       PaymentInfo, PaymentInfoStorage, PeerManager,
+       ChannelManager, HTLCStatus, MillisatAmount, NetworkGraph, OnionMessenger, PaymentInfo,
+       PaymentInfoStorage, PeerManager,
 };
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::PublicKey;
-use lightning::chain::keysinterface::{KeysInterface, KeysManager, Recipient};
-use lightning::ln::msgs::{DecodeError, NetAddress};
+use lightning::chain::keysinterface::{EntropySource, KeysManager};
+use lightning::ln::channelmanager::{PaymentId, Retry};
+use lightning::ln::msgs::NetAddress;
 use lightning::ln::{PaymentHash, PaymentPreimage};
 use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
 use lightning::routing::gossip::NodeId;
+use lightning::routing::router::{PaymentParameters, RouteParameters};
 use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
-use lightning::util::events::EventHandler;
 use lightning::util::ser::{Writeable, Writer};
-use lightning_invoice::payment::PaymentError;
+use lightning_invoice::payment::pay_invoice;
 use lightning_invoice::{utils, Currency, Invoice};
 use std::env;
 use std::io;
@@ -57,12 +58,12 @@ impl Writeable for UserOnionMessageContents {
        }
 }
 
-pub(crate) async fn poll_for_user_input<E: EventHandler>(
-       invoice_payer: Arc<InvoicePayer<E>>, peer_manager: Arc<PeerManager>,
-       channel_manager: Arc<ChannelManager>, keys_manager: Arc<KeysManager>,
-       network_graph: Arc<NetworkGraph>, onion_messenger: Arc<OnionMessenger>,
-       inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
-       ldk_data_dir: String, network: Network, logger: Arc<disk::FilesystemLogger>,
+pub(crate) async fn poll_for_user_input(
+       peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
+       keys_manager: Arc<KeysManager>, network_graph: Arc<NetworkGraph>,
+       onion_messenger: Arc<OnionMessenger>, inbound_payments: PaymentInfoStorage,
+       outbound_payments: PaymentInfoStorage, ldk_data_dir: String, network: Network,
+       logger: Arc<disk::FilesystemLogger>,
 ) {
        println!(
                "LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
@@ -156,7 +157,7 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                }
                                        };
 
-                                       send_payment(&*invoice_payer, &invoice, outbound_payments.clone());
+                                       send_payment(&*channel_manager, &invoice, outbound_payments.clone());
                                }
                                "keysend" => {
                                        let dest_pubkey = match words.next() {
@@ -187,7 +188,7 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                }
                                        };
                                        keysend(
-                                               &*invoice_payer,
+                                               &*channel_manager,
                                                dest_pubkey,
                                                amt_msat,
                                                &*keys_manager,
@@ -364,7 +365,7 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                "{:?}",
                                                lightning::util::message_signing::sign(
                                                        &line.as_bytes()[MSG_STARTPOS..],
-                                                       &keys_manager.get_node_secret(Recipient::Node).unwrap()
+                                                       &keys_manager.get_node_secret_key()
                                                )
                                        );
                                }
@@ -479,7 +480,7 @@ fn node_info(channel_manager: &Arc<ChannelManager>, peer_manager: &Arc<PeerManag
 
 fn list_peers(peer_manager: Arc<PeerManager>) {
        println!("\t{{");
-       for pubkey in peer_manager.get_peer_node_ids() {
+       for (pubkey, _) in peer_manager.get_peer_node_ids() {
                println!("\t\t pubkey: {}", pubkey);
        }
        println!("\t}},");
@@ -571,7 +572,7 @@ fn list_payments(inbound_payments: PaymentInfoStorage, outbound_payments: Paymen
 pub(crate) async fn connect_peer_if_necessary(
        pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc<PeerManager>,
 ) -> Result<(), ()> {
-       for node_pubkey in peer_manager.get_peer_node_ids() {
+       for (node_pubkey, _) in peer_manager.get_peer_node_ids() {
                if node_pubkey == pubkey {
                        return Ok(());
                }
@@ -598,7 +599,7 @@ pub(crate) async fn do_connect_peer(
                                        std::task::Poll::Pending => {}
                                }
                                // Avoid blocking the tokio context by sleeping a bit
-                               match peer_manager.get_peer_node_ids().iter().find(|id| **id == pubkey) {
+                               match peer_manager.get_peer_node_ids().iter().find(|(id, _)| *id == pubkey) {
                                        Some(_) => return Ok(()),
                                        None => tokio::time::sleep(Duration::from_millis(10)).await,
                                }
@@ -622,12 +623,12 @@ fn do_disconnect_peer(
 
        //check the pubkey matches a valid connected peer
        let peers = peer_manager.get_peer_node_ids();
-       if !peers.contains(&pubkey) {
+       if !peers.iter().any(|(pk, _)| &pubkey == pk) {
                println!("Error: Could not find peer {}", pubkey);
                return Err(());
        }
 
-       peer_manager.disconnect_by_node_id(pubkey, false);
+       peer_manager.disconnect_by_node_id(pubkey);
        Ok(())
 }
 
@@ -660,33 +661,24 @@ fn open_channel(
        }
 }
 
-fn send_payment<E: EventHandler>(
-       invoice_payer: &InvoicePayer<E>, invoice: &Invoice, payment_storage: PaymentInfoStorage,
+fn send_payment(
+       channel_manager: &ChannelManager, invoice: &Invoice, payment_storage: PaymentInfoStorage,
 ) {
-       let status = match invoice_payer.pay_invoice(invoice) {
-               Ok(_payment_id) => {
-                       let payee_pubkey = invoice.recover_payee_pub_key();
-                       let amt_msat = invoice.amount_milli_satoshis().unwrap();
-                       println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
-                       print!("> ");
-                       HTLCStatus::Pending
-               }
-               Err(PaymentError::Invoice(e)) => {
-                       println!("ERROR: invalid invoice: {}", e);
-                       print!("> ");
-                       return;
-               }
-               Err(PaymentError::Routing(e)) => {
-                       println!("ERROR: failed to find route: {}", e.err);
-                       print!("> ");
-                       return;
-               }
-               Err(PaymentError::Sending(e)) => {
-                       println!("ERROR: failed to send payment: {:?}", e);
-                       print!("> ");
-                       HTLCStatus::Failed
-               }
-       };
+       let status =
+               match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) {
+                       Ok(_payment_id) => {
+                               let payee_pubkey = invoice.recover_payee_pub_key();
+                               let amt_msat = invoice.amount_milli_satoshis().unwrap();
+                               println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
+                               print!("> ");
+                               HTLCStatus::Pending
+                       }
+                       Err(e) => {
+                               println!("ERROR: failed to send payment: {:?}", e);
+                               print!("> ");
+                               HTLCStatus::Failed
+                       }
+               };
        let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
        let payment_secret = Some(invoice.payment_secret().clone());
 
@@ -702,34 +694,29 @@ fn send_payment<E: EventHandler>(
        );
 }
 
-fn keysend<E: EventHandler, K: KeysInterface>(
-       invoice_payer: &InvoicePayer<E>, payee_pubkey: PublicKey, amt_msat: u64, keys: &K,
+fn keysend<E: EntropySource>(
+       channel_manager: &ChannelManager, payee_pubkey: PublicKey, amt_msat: u64, entropy_source: &E,
        payment_storage: PaymentInfoStorage,
 ) {
-       let payment_preimage = keys.get_secure_random_bytes();
+       let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
+       let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
 
-       let status = match invoice_payer.pay_pubkey(
-               payee_pubkey,
-               PaymentPreimage(payment_preimage),
-               amt_msat,
-               40,
+       let route_params = RouteParameters {
+               payment_params: PaymentParameters::for_keysend(payee_pubkey, 40),
+               final_value_msat: amt_msat,
+       };
+       let status = match channel_manager.send_spontaneous_payment_with_retry(
+               Some(payment_preimage),
+               PaymentId(payment_hash.0),
+               route_params,
+               Retry::Timeout(Duration::from_secs(10)),
        ) {
-               Ok(_payment_id) => {
+               Ok(_payment_hash) => {
                        println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
                        print!("> ");
                        HTLCStatus::Pending
                }
-               Err(PaymentError::Invoice(e)) => {
-                       println!("ERROR: invalid payee: {}", e);
-                       print!("> ");
-                       return;
-               }
-               Err(PaymentError::Routing(e)) => {
-                       println!("ERROR: failed to find route: {}", e.err);
-                       print!("> ");
-                       return;
-               }
-               Err(PaymentError::Sending(e)) => {
+               Err(e) => {
                        println!("ERROR: failed to send payment: {:?}", e);
                        print!("> ");
                        HTLCStatus::Failed
@@ -738,7 +725,7 @@ fn keysend<E: EventHandler, K: KeysInterface>(
 
        let mut payments = payment_storage.lock().unwrap();
        payments.insert(
-               PaymentHash(Sha256::hash(&payment_preimage).into_inner()),
+               payment_hash,
                PaymentInfo {
                        preimage: None,
                        secret: None,
@@ -768,6 +755,7 @@ fn get_invoice(
                Some(amt_msat),
                "ldk-tutorial-node".to_string(),
                expiry_secs,
+               None,
        ) {
                Ok(inv) => {
                        println!("SUCCESS: generated invoice: {}", inv);
index 681d742d5444438784e488d95b09348211b6cf0e..0c3085134bedcd8cf35ca57330a776ad196223a9 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{cli, NetworkGraph};
 use bitcoin::secp256k1::PublicKey;
-use bitcoin::BlockHash;
+use bitcoin::Network;
 use chrono::Utc;
 use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
 use lightning::util::logger::{Logger, Record};
@@ -73,14 +73,14 @@ pub(crate) fn read_channel_peer_data(
 }
 
 pub(crate) fn read_network(
-       path: &Path, genesis_hash: BlockHash, logger: Arc<FilesystemLogger>,
+       path: &Path, network: Network, logger: Arc<FilesystemLogger>,
 ) -> NetworkGraph {
        if let Ok(file) = File::open(path) {
                if let Ok(graph) = NetworkGraph::read(&mut BufReader::new(file), logger.clone()) {
                        return graph;
                }
        }
-       NetworkGraph::new(genesis_hash, logger)
+       NetworkGraph::new(network, logger)
 }
 
 pub(crate) fn read_scorer(
index 57da6d15fb501ca373c87bc2c3fbac9c72e4193e..1e5edf47f00b1d2fa860a789c2dfe0a09f8a6865 100644 (file)
@@ -7,7 +7,6 @@ mod hex_utils;
 
 use crate::bitcoind_client::BitcoindClient;
 use crate::disk::FilesystemLogger;
-use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::consensus::encode;
 use bitcoin::network::constants::Network;
@@ -16,7 +15,7 @@ use bitcoin::BlockHash;
 use bitcoin_bech32::WitnessProgram;
 use lightning::chain;
 use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
-use lightning::chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager, Recipient};
+use lightning::chain::keysinterface::{EntropySource, InMemorySigner, KeysManager};
 use lightning::chain::{chainmonitor, ChannelMonitorUpdateStatus};
 use lightning::chain::{Filter, Watch};
 use lightning::ln::channelmanager;
@@ -29,7 +28,6 @@ use lightning::onion_message::SimpleArcOnionMessenger;
 use lightning::routing::gossip;
 use lightning::routing::gossip::{NodeId, P2PGossipSync};
 use lightning::routing::router::DefaultRouter;
-use lightning::routing::scoring::ProbabilisticScorer;
 use lightning::util::config::UserConfig;
 use lightning::util::events::{Event, PaymentPurpose};
 use lightning::util::ser::ReadableArgs;
@@ -38,7 +36,6 @@ use lightning_block_sync::init;
 use lightning_block_sync::poll;
 use lightning_block_sync::SpvClient;
 use lightning_block_sync::UnboundedCache;
-use lightning_invoice::payment;
 use lightning_net_tokio::SocketDescriptor;
 use lightning_persister::FilesystemPersister;
 use rand::{thread_rng, Rng};
@@ -95,22 +92,13 @@ pub(crate) type PeerManager = SimpleArcPeerManager<
        ChainMonitor,
        BitcoindClient,
        BitcoindClient,
-       dyn chain::Access + Send + Sync,
+       BitcoindClient,
        FilesystemLogger,
 >;
 
 pub(crate) type ChannelManager =
        SimpleArcChannelManager<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
 
-pub(crate) type InvoicePayer<E> =
-       payment::InvoicePayer<Arc<ChannelManager>, Router, Arc<FilesystemLogger>, E>;
-
-type Router = DefaultRouter<
-       Arc<NetworkGraph>,
-       Arc<FilesystemLogger>,
-       Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph>, Arc<FilesystemLogger>>>>,
->;
-
 pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
 
 type OnionMessenger = SimpleArcOnionMessenger<FilesystemLogger>;
@@ -479,14 +467,35 @@ async fn start_ldk() {
        let keys_manager = Arc::new(KeysManager::new(&keys_seed, cur.as_secs(), cur.subsec_nanos()));
 
        // Step 7: Read ChannelMonitor state from disk
-       let mut channelmonitors = persister.read_channelmonitors(keys_manager.clone()).unwrap();
+       let mut channelmonitors =
+               persister.read_channelmonitors(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())
                .await
                .expect("Failed to fetch best block header and best block");
 
-       // Step 9: Initialize the ChannelManager
+       // Step 9: Initialize routing ProbabilisticScorer
+       let network_graph_path = format!("{}/network_graph", ldk_data_dir.clone());
+       let network_graph =
+               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(
+               Path::new(&scorer_path),
+               Arc::clone(&network_graph),
+               Arc::clone(&logger),
+       )));
+
+       // Step 10: Create Router
+       let router = Arc::new(DefaultRouter::new(
+               network_graph.clone(),
+               logger.clone(),
+               keys_manager.get_secure_random_bytes(),
+               scorer.clone(),
+       ));
+
+       // Step 11: Initialize the ChannelManager
        let mut user_config = UserConfig::default();
        user_config.channel_handshake_limits.force_announced_channel_preference = false;
        let mut restarting_node = true;
@@ -497,10 +506,13 @@ async fn start_ldk() {
                                channel_monitor_mut_references.push(channel_monitor);
                        }
                        let read_args = ChannelManagerReadArgs::new(
+                               keys_manager.clone(),
+                               keys_manager.clone(),
                                keys_manager.clone(),
                                fee_estimator.clone(),
                                chain_monitor.clone(),
                                broadcaster.clone(),
+                               router,
                                logger.clone(),
                                user_config,
                                channel_monitor_mut_references,
@@ -518,8 +530,11 @@ async fn start_ldk() {
                                fee_estimator.clone(),
                                chain_monitor.clone(),
                                broadcaster.clone(),
+                               router,
                                logger.clone(),
                                keys_manager.clone(),
+                               keys_manager.clone(),
+                               keys_manager.clone(),
                                user_config,
                                chain_params,
                        );
@@ -527,7 +542,7 @@ async fn start_ldk() {
                }
        };
 
-       // Step 10: Sync ChannelMonitors and ChannelManager to chain tip
+       // Step 12: Sync ChannelMonitors and ChannelManager to chain tip
        let mut chain_listener_channel_monitors = Vec::new();
        let mut cache = UnboundedCache::new();
        let chain_tip = if restarting_node {
@@ -564,7 +579,7 @@ async fn start_ldk() {
                polled_chain_tip
        };
 
-       // Step 11: Give ChannelMonitors to ChainMonitor
+       // Step 13: Give ChannelMonitors to ChainMonitor
        for item in chain_listener_channel_monitors.drain(..) {
                let channel_monitor = item.1 .0;
                let funding_outpoint = item.2;
@@ -574,20 +589,17 @@ async fn start_ldk() {
                );
        }
 
-       // Step 12: Optional: Initialize the P2PGossipSync
-       let genesis = genesis_block(args.network).header.block_hash();
-       let network_graph_path = format!("{}/network_graph", ldk_data_dir.clone());
-       let network_graph =
-               Arc::new(disk::read_network(Path::new(&network_graph_path), genesis, logger.clone()));
+       // Step 14: Optional: Initialize the P2PGossipSync
        let gossip_sync = Arc::new(P2PGossipSync::new(
                Arc::clone(&network_graph),
-               None::<Arc<dyn chain::Access + Send + Sync>>,
+               None::<Arc<BitcoindClient>>,
                logger.clone(),
        ));
 
-       // Step 13: Initialize the PeerManager
+       // Step 15: Initialize the PeerManager
        let channel_manager: Arc<ChannelManager> = Arc::new(channel_manager);
        let onion_messenger: Arc<OnionMessenger> = Arc::new(OnionMessenger::new(
+               Arc::clone(&keys_manager),
                Arc::clone(&keys_manager),
                Arc::clone(&logger),
                IgnoringMessageHandler {},
@@ -602,15 +614,15 @@ async fn start_ldk() {
        };
        let peer_manager: Arc<PeerManager> = Arc::new(PeerManager::new(
                lightning_msg_handler,
-               keys_manager.get_node_secret(Recipient::Node).unwrap(),
                current_time.try_into().unwrap(),
                &ephemeral_bytes,
                logger.clone(),
                IgnoringMessageHandler {},
+               Arc::clone(&keys_manager),
        ));
 
        // ## Running LDK
-       // Step 14: Initialize networking
+       // Step 16: Initialize networking
 
        let peer_manager_connection_handler = peer_manager.clone();
        let listening_port = args.ldk_peer_listening_port;
@@ -636,7 +648,7 @@ async fn start_ldk() {
                }
        });
 
-       // Step 15: Connect and Disconnect Blocks
+       // Step 17: Connect and Disconnect Blocks
        let channel_manager_listener = channel_manager.clone();
        let chain_monitor_listener = chain_monitor.clone();
        let bitcoind_block_source = bitcoind_client.clone();
@@ -651,7 +663,7 @@ async fn start_ldk() {
                }
        });
 
-       // Step 16: Handle LDK Events
+       // Step 18: Handle LDK Events
        let channel_manager_event_listener = channel_manager.clone();
        let keys_manager_listener = keys_manager.clone();
        // TODO: persist payment info to disk
@@ -676,36 +688,13 @@ async fn start_ldk() {
                ));
        };
 
-       // Step 17: Initialize routing ProbabilisticScorer
-       let scorer_path = format!("{}/scorer", ldk_data_dir.clone());
-       let scorer = Arc::new(Mutex::new(disk::read_scorer(
-               Path::new(&scorer_path),
-               Arc::clone(&network_graph),
-               Arc::clone(&logger),
-       )));
-
-       // Step 18: Create InvoicePayer
-       let router = DefaultRouter::new(
-               network_graph.clone(),
-               logger.clone(),
-               keys_manager.get_secure_random_bytes(),
-               scorer.clone(),
-       );
-       let invoice_payer = Arc::new(InvoicePayer::new(
-               channel_manager.clone(),
-               router,
-               logger.clone(),
-               event_handler,
-               payment::Retry::Timeout(Duration::from_secs(10)),
-       ));
-
        // Step 19: Persist ChannelManager and NetworkGraph
        let persister = Arc::new(FilesystemPersister::new(ldk_data_dir.clone()));
 
        // Step 20: Background Processing
        let background_processor = BackgroundProcessor::start(
                persister,
-               invoice_payer.clone(),
+               event_handler,
                chain_monitor.clone(),
                channel_manager.clone(),
                GossipSync::p2p(gossip_sync.clone()),
@@ -730,7 +719,7 @@ async fn start_ldk() {
                                                .list_channels()
                                                .iter()
                                                .map(|chan| chan.counterparty.node_id)
-                                               .filter(|id| !peers.contains(id))
+                                               .filter(|id| !peers.iter().any(|(pk, _)| id == pk))
                                        {
                                                if stop_connect.load(Ordering::Acquire) {
                                                        return;
@@ -774,7 +763,6 @@ async fn start_ldk() {
 
        // Start the CLI.
        cli::poll_for_user_input(
-               Arc::clone(&invoice_payer),
                Arc::clone(&peer_manager),
                Arc::clone(&channel_manager),
                Arc::clone(&keys_manager),