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
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();
}
};
+ // 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
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;
});
}
});
peer_addr,
peer_manager.clone(),
event_ntfn_sender.clone(),
- );
+ )
+ .await;
}
}
}
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(),
event_ntfn_sender,
ldk_data_dir.clone(),
logger.clone(),
- args.network,
+ network,
)
.await;
}