From ddc94145bd2e9b4ebedbff4722783fa21478f362 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 18 Aug 2021 18:35:18 -0400 Subject: [PATCH] Update to new Netgraph + PaymentFailed API --- Cargo.lock | 12 ++++++------ Cargo.toml | 18 ++++++++++++------ src/cli.rs | 32 ++++++++++++++++++++++++-------- src/main.rs | 20 +++++++++----------- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15fb18a..03d573f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,7 +252,7 @@ checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" [[package]] name = "lightning" version = "0.0.99" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bitcoin", "secp256k1", @@ -261,7 +261,7 @@ dependencies = [ [[package]] name = "lightning-background-processor" version = "0.0.99" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bitcoin", "lightning", @@ -271,7 +271,7 @@ dependencies = [ [[package]] name = "lightning-block-sync" version = "0.0.99" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bitcoin", "chunked_transfer", @@ -284,7 +284,7 @@ dependencies = [ [[package]] name = "lightning-invoice" version = "0.7.0" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bech32", "bitcoin_hashes", @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "lightning-net-tokio" version = "0.0.99" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bitcoin", "lightning", @@ -306,7 +306,7 @@ dependencies = [ [[package]] name = "lightning-persister" version = "0.0.99" -source = "git+https://github.com/rust-bitcoin/rust-lightning?branch=main#9d8d24f6906d6fbdc6c02a88e5e2298c1fa50825" +source = "git+https://github.com/jkczyz/rust-lightning.git?branch=2021-07-network-update-handler#de7cb1d4fe22cc46eb0a59ebefb15017c43ba711" dependencies = [ "bitcoin", "libc", diff --git a/Cargo.toml b/Cargo.toml index e71926d..934f06e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,18 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -lightning = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } -lightning-block-sync = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main", features = [ "rpc-client" ] } -lightning-invoice = { version = "0.7", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } -lightning-net-tokio = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } -lightning-persister = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } -lightning-background-processor = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +# lightning = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +# lightning-block-sync = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main", features = [ "rpc-client" ] } +# lightning-invoice = { version = "0.7", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +# lightning-net-tokio = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +# lightning-persister = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +# lightning-background-processor = { version = "0.0.99", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" } +lightning = { git = "https://github.com/jkczyz/rust-lightning.git", branch = "2021-07-network-update-handler" } +lightning-block-sync = { git = "https://github.com/jkczyz/rust-lightning", branch = "2021-07-network-update-handler", features = [ "rpc-client" ] } +lightning-invoice = { git = "https://github.com/jkczyz/rust-lightning.git", branch = "2021-07-network-update-handler" } +lightning-net-tokio = { git = "https://github.com/jkczyz/rust-lightning.git", branch = "2021-07-network-update-handler" } +lightning-persister = { git = "https://github.com/jkczyz/rust-lightning.git", branch = "2021-07-network-update-handler" } +lightning-background-processor = { git = "https://github.com/jkczyz/rust-lightning.git", branch = "2021-07-network-update-handler" } base64 = "0.13.0" bitcoin = "0.27" diff --git a/src/cli.rs b/src/cli.rs index d4d7e9e..63bc539 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,7 +12,7 @@ use lightning::chain::keysinterface::KeysManager; use lightning::ln::features::InvoiceFeatures; use lightning::ln::msgs::NetAddress; use lightning::ln::{PaymentHash, PaymentSecret}; -use lightning::routing::network_graph::NetGraphMsgHandler; +use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; use lightning::routing::router; use lightning::routing::router::RouteHint; use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig}; @@ -137,7 +137,13 @@ pub(crate) fn parse_startup_args() -> Result { pub(crate) async fn poll_for_user_input( peer_manager: Arc, channel_manager: Arc, keys_manager: Arc, - router: Arc, Arc>>, + router: Arc< + NetGraphMsgHandler< + Arc, + Arc, + Arc, + >, + >, inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage, ldk_data_dir: String, logger: Arc, network: Network, ) { @@ -585,17 +591,22 @@ fn send_payment( payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash, payment_secret: Option, payee_features: Option, route_hints: Vec<&RouteHint>, - router: Arc, Arc>>, + router: Arc< + NetGraphMsgHandler< + Arc, + Arc, + Arc, + >, + >, channel_manager: Arc, payment_storage: PaymentInfoStorage, logger: Arc, ) { - let network_graph = router.network_graph.read().unwrap(); let first_hops = channel_manager.list_usable_channels(); let payer_pubkey = channel_manager.get_our_node_id(); let route = router::get_route( &payer_pubkey, - &network_graph, + &router.network_graph, &payee, payee_features, Some(&first_hops.iter().collect::>()), @@ -633,17 +644,22 @@ fn send_payment( fn keysend( payee: PublicKey, amt_msat: u64, - router: Arc, Arc>>, + router: Arc< + NetGraphMsgHandler< + Arc, + Arc, + Arc, + >, + >, channel_manager: Arc, payment_storage: PaymentInfoStorage, logger: Arc, ) { - let network_graph = router.network_graph.read().unwrap(); let first_hops = channel_manager.list_usable_channels(); let payer_pubkey = channel_manager.get_our_node_id(); let route = match router::get_keysend_route( &payer_pubkey, - &network_graph, + &router.network_graph, &payee, Some(&first_hops.iter().collect::>()), &vec![], diff --git a/src/main.rs b/src/main.rs index 0229873..7846ad6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -205,7 +205,7 @@ async fn handle_ldk_events( } } } - Event::PaymentFailed { payment_hash, rejected_by_dest } => { + Event::PaymentFailed { payment_hash, rejected_by_dest, .. } => { print!( "\nEVENT: Failed to send payment to payment hash {:?}: ", hex_utils::hex_str(&payment_hash.0) @@ -459,22 +459,19 @@ async fn start_ldk() { // Step 11: Optional: Initialize the NetGraphMsgHandler let genesis = genesis_block(args.network).header.block_hash(); let network_graph_path = format!("{}/network_graph", ldk_data_dir.clone()); - let network_graph = disk::read_network(Path::new(&network_graph_path), genesis); - let router = Arc::new(NetGraphMsgHandler::from_net_graph( + let network_graph = Arc::new(disk::read_network(Path::new(&network_graph_path), genesis)); + let router = Arc::new(NetGraphMsgHandler::new( + network_graph.clone(), None::>, logger.clone(), - network_graph, )); let router_persist = Arc::clone(&router); tokio::spawn(async move { let mut interval = tokio::time::interval(Duration::from_secs(600)); loop { interval.tick().await; - if disk::persist_network( - Path::new(&network_graph_path), - &*router_persist.network_graph.read().unwrap(), - ) - .is_err() + if disk::persist_network(Path::new(&network_graph_path), &*router_persist.network_graph) + .is_err() { // Persistence errors here are non-fatal as we can just fetch the routing graph // again later, but they may indicate a disk error which could be fatal elsewhere. @@ -552,7 +549,7 @@ async fn start_ldk() { let network = args.network; let bitcoind_rpc = bitcoind_client.clone(); let handle = tokio::runtime::Handle::current(); - let event_handler = move |event| { + let event_handler = move |event: &Event| { handle.block_on(handle_ldk_events( channel_manager_event_listener.clone(), bitcoind_rpc.clone(), @@ -560,7 +557,7 @@ async fn start_ldk() { inbound_pmts_for_events.clone(), outbound_pmts_for_events.clone(), network, - event, + event.clone(), )) }; // Step 16: Persist ChannelManager @@ -574,6 +571,7 @@ async fn start_ldk() { chain_monitor.clone(), channel_manager.clone(), peer_manager.clone(), + network_graph.clone(), logger.clone(), ); -- 2.39.5