X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain.rs;h=b9104ede73c68b6b497b62be6cd60ad22ddb4d8c;hb=5e92169f4083d53a6c21ab8cf5c903eb9e9b527d;hp=b024e9354ef220429fea58c841688dde7b2b1a28;hpb=6199433ab8f13e4f78b12e13a683eb33c999114b;p=ldk-sample diff --git a/src/main.rs b/src/main.rs index b024e93..b9104ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,10 +168,10 @@ async fn handle_ldk_events( let status = match loop_channel_manager.claim_funds(payment_preimage.unwrap()) { true => { println!( - "\nEVENT: received payment from payment hash {} of {} millisatoshis", - hex_utils::hex_str(&payment_hash.0), - amt - ); + "\nEVENT: received payment from payment hash {} of {} millisatoshis", + hex_utils::hex_str(&payment_hash.0), + amt + ); print!("> "); io::stdout().flush().unwrap(); HTLCStatus::Succeeded @@ -220,9 +220,9 @@ async fn handle_ldk_events( hex_utils::hex_str(&payment_hash.0) ); if rejected_by_dest { - println!("rejected by destination node"); + println!("re-attempting the payment will not succeed"); } else { - println!("route failed"); + println!("payment may be retried"); } print!("> "); io::stdout().flush().unwrap(); @@ -290,6 +290,22 @@ async fn start_ldk() { } }; + // Check that the bitcoind we've connected to is running the network we expect + let bitcoind_chain = bitcoind_client.get_blockchain_info().await.chain; + if bitcoind_chain + != match args.network { + bitcoin::Network::Bitcoin => "main", + bitcoin::Network::Testnet => "test", + bitcoin::Network::Regtest => "regtest", + bitcoin::Network::Signet => "signet", + } { + println!( + "Chain argument ({}) didn't match bitcoind chain ({})", + args.network, bitcoind_chain + ); + return; + } + // ## Setup // Step 1: Initialize the FeeEstimator @@ -466,14 +482,20 @@ async fn start_ldk() { let event_notifier = event_ntfn_sender.clone(); let listening_port = args.ldk_peer_listening_port; tokio::spawn(async move { - let listener = std::net::TcpListener::bind(format!("0.0.0.0:{}", listening_port)).unwrap(); + let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", listening_port)) + .await + .expect("Failed to bind to listen port - is something else already listening on it?"); loop { let peer_mgr = peer_manager_connection_handler.clone(); let notifier = event_notifier.clone(); - let tcp_stream = listener.accept().unwrap().0; + let tcp_stream = listener.accept().await.unwrap().0; tokio::spawn(async move { - lightning_net_tokio::setup_inbound(peer_mgr.clone(), notifier.clone(), tcp_stream) - .await; + lightning_net_tokio::setup_inbound( + peer_mgr.clone(), + notifier.clone(), + tcp_stream.into_std().unwrap(), + ) + .await; }); } }); @@ -547,7 +569,8 @@ async fn start_ldk() { peer_addr, peer_manager.clone(), event_ntfn_sender.clone(), - ); + ) + .await; } } } @@ -555,6 +578,26 @@ async fn start_ldk() { Err(e) => println!("ERROR: errored reading channel peer info from disk: {:?}", e), } + // Regularly broadcast our node_announcement. This is only required (or possible) if we have + // some public channels, and is only useful if we have public listen address(es) to announce. + // In a production environment, this should occur only after the announcement of new channels + // to avoid churn in the global network graph. + let chan_manager = Arc::clone(&channel_manager); + let network = args.network; + if args.ldk_announced_listen_addr.is_some() { + tokio::spawn(async move { + let mut interval = tokio::time::interval(Duration::from_secs(60)); + loop { + interval.tick().await; + chan_manager.broadcast_node_announcement( + [0; 3], + args.ldk_announced_node_name, + vec![args.ldk_announced_listen_addr.as_ref().unwrap().clone()], + ); + } + }); + } + // Start the CLI. cli::poll_for_user_input( peer_manager.clone(), @@ -566,7 +609,7 @@ async fn start_ldk() { event_ntfn_sender, ldk_data_dir.clone(), logger.clone(), - args.network, + network, ) .await; }