]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Update to new Netgraph + PaymentFailed API
authorValentine Wallace <vwallace@protonmail.com>
Wed, 18 Aug 2021 22:35:18 +0000 (18:35 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 18 Aug 2021 22:35:18 +0000 (18:35 -0400)
Cargo.lock
Cargo.toml
src/cli.rs
src/main.rs

index 15fb18a44b19e43deea62beacc18d039ab3cac2a..03d573fe82c7a10614d0498b4d84a437d6950a19 100644 (file)
@@ -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",
index e71926de14a8c893fc91e44d399ea45e747bcb4b..934f06e9f7970918fc0027ce73045436aef60417 100644 (file)
@@ -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"
index d4d7e9ed4263079d84f3e3e42d1efc269f8f5404..63bc539ba7294ea53b3eefc949f05247d7d779a9 100644 (file)
@@ -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<LdkUserInfo, ()> {
 pub(crate) async fn poll_for_user_input(
        peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
        keys_manager: Arc<KeysManager>,
-       router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
+       router: Arc<
+               NetGraphMsgHandler<
+                       Arc<NetworkGraph>,
+                       Arc<dyn chain::Access + Send + Sync>,
+                       Arc<FilesystemLogger>,
+               >,
+       >,
        inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
        ldk_data_dir: String, logger: Arc<FilesystemLogger>, network: Network,
 ) {
@@ -585,17 +591,22 @@ fn send_payment(
        payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash,
        payment_secret: Option<PaymentSecret>, payee_features: Option<InvoiceFeatures>,
        route_hints: Vec<&RouteHint>,
-       router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
+       router: Arc<
+               NetGraphMsgHandler<
+                       Arc<NetworkGraph>,
+                       Arc<dyn chain::Access + Send + Sync>,
+                       Arc<FilesystemLogger>,
+               >,
+       >,
        channel_manager: Arc<ChannelManager>, payment_storage: PaymentInfoStorage,
        logger: Arc<FilesystemLogger>,
 ) {
-       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::<Vec<_>>()),
@@ -633,17 +644,22 @@ fn send_payment(
 
 fn keysend(
        payee: PublicKey, amt_msat: u64,
-       router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
+       router: Arc<
+               NetGraphMsgHandler<
+                       Arc<NetworkGraph>,
+                       Arc<dyn chain::Access + Send + Sync>,
+                       Arc<FilesystemLogger>,
+               >,
+       >,
        channel_manager: Arc<ChannelManager>, payment_storage: PaymentInfoStorage,
        logger: Arc<FilesystemLogger>,
 ) {
-       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<_>>()),
                &vec![],
index 0229873380b6f06dfde5885dca4b4915ac2a6975..7846ad6d40afa3595210d6489a5baea4eda8734f 100644 (file)
@@ -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::<Arc<dyn chain::Access + Send + Sync>>,
                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(),
        );