Update payment error messages to better match reality
[ldk-sample] / src / main.rs
index 21dfb284a81eeae3e9b1366a41e55fc4cd891378..f51528b7b57832b3caf279b2f7fd856b6377de87 100644 (file)
@@ -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;
                        });
                }
        });