Semantically sort subheadings
[ldk-sample] / src / cli.rs
index 197c0ecf607a763f88873099d44da96982bd188f..d53b74bbd98609279923b3b104639f3d4b8a1f68 100644 (file)
@@ -1,31 +1,30 @@
 use crate::disk;
 use crate::hex_utils;
 use crate::{
-       ChannelManager, FilesystemLogger, HTLCStatus, InvoicePayer, MillisatAmount, PaymentInfo,
-       PaymentInfoStorage, PeerManager,
+       ChannelManager, HTLCStatus, InvoicePayer, MillisatAmount, NetworkGraph, OnionMessenger,
+       PaymentInfo, PaymentInfoStorage, PeerManager,
 };
+use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
-use bitcoin::secp256k1::key::PublicKey;
-use lightning::chain::keysinterface::{KeysInterface, KeysManager};
+use bitcoin::secp256k1::PublicKey;
+use lightning::chain::keysinterface::{KeysInterface, KeysManager, Recipient};
 use lightning::ln::msgs::NetAddress;
-use lightning::ln::PaymentHash;
-use lightning::routing::network_graph::NetworkGraph;
-use lightning::routing::router;
-use lightning::routing::router::{Payee, RouteParameters};
-use lightning::routing::scorer::Scorer;
-use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig};
+use lightning::ln::{PaymentHash, PaymentPreimage};
+use lightning::onion_message::Destination;
+use lightning::routing::gossip::NodeId;
+use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
 use lightning::util::events::EventHandler;
 use lightning_invoice::payment::PaymentError;
 use lightning_invoice::{utils, Currency, Invoice};
 use std::env;
 use std::io;
-use std::io::{BufRead, Write};
+use std::io::Write;
 use std::net::{IpAddr, SocketAddr, ToSocketAddrs};
 use std::ops::Deref;
 use std::path::Path;
 use std::str::FromStr;
-use std::sync::{Arc, Mutex};
+use std::sync::Arc;
 use std::time::Duration;
 
 pub(crate) struct LdkUserInfo {
@@ -88,8 +87,9 @@ pub(crate) fn parse_startup_args() -> Result<LdkUserInfo, ()> {
        let network: Network = match env::args().skip(arg_idx).next().as_ref().map(String::as_str) {
                Some("testnet") => Network::Testnet,
                Some("regtest") => Network::Regtest,
+               Some("signet") => Network::Signet,
                Some(net) => {
-                       panic!("Unsupported network provided. Options are: `regtest`, `testnet`. Got {}", net);
+                       panic!("Unsupported network provided. Options are: `regtest`, `testnet`, and `signet`. Got {}", net);
                }
                None => Network::Testnet,
        };
@@ -143,22 +143,28 @@ pub(crate) fn parse_startup_args() -> Result<LdkUserInfo, ()> {
 pub(crate) async fn poll_for_user_input<E: EventHandler>(
        invoice_payer: Arc<InvoicePayer<E>>, peer_manager: Arc<PeerManager>,
        channel_manager: Arc<ChannelManager>, keys_manager: Arc<KeysManager>,
-       network_graph: Arc<NetworkGraph>, scorer: Arc<Mutex<Scorer>>,
+       network_graph: Arc<NetworkGraph>, onion_messenger: Arc<OnionMessenger>,
        inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
-       ldk_data_dir: String, logger: Arc<FilesystemLogger>, network: Network,
+       ldk_data_dir: String, network: Network,
 ) {
-       println!("LDK startup successful. To view available commands: \"help\".");
+       println!(
+               "LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
+       );
        println!("LDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
        println!("Local Node ID is {}.", channel_manager.get_our_node_id());
-       let stdin = io::stdin();
-       let mut line_reader = stdin.lock().lines();
        loop {
                print!("> ");
                io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print
-               let line = match line_reader.next() {
-                       Some(l) => l.unwrap(),
-                       None => break,
-               };
+               let mut line = String::new();
+               if let Err(e) = io::stdin().read_line(&mut line) {
+                       break println!("ERROR: {e:#}");
+               }
+
+               if line.len() == 0 {
+                       // We hit EOF / Ctrl-D
+                       break;
+               }
+
                let mut words = line.split_whitespace();
                if let Some(word) = words.next() {
                        match word {
@@ -253,7 +259,6 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                Some(amt) => amt,
                                                None => {
                                                        println!("ERROR: keysend requires an amount in millisatoshis: `keysend <dest_pubkey> <amt_msat>`");
-
                                                        continue;
                                                }
                                        };
@@ -265,13 +270,11 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                }
                                        };
                                        keysend(
+                                               &*invoice_payer,
                                                dest_pubkey,
                                                amt_msat,
-                                               network_graph.clone(),
-                                               channel_manager.clone(),
+                                               &*keys_manager,
                                                outbound_payments.clone(),
-                                               logger.clone(),
-                                               scorer.clone(),
                                        );
                                }
                                "getinvoice" => {
@@ -286,12 +289,26 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                println!("ERROR: getinvoice provided payment amount was not a number");
                                                continue;
                                        }
+
+                                       let expiry_secs_str = words.next();
+                                       if expiry_secs_str.is_none() {
+                                               println!("ERROR: getinvoice requires an expiry in seconds");
+                                               continue;
+                                       }
+
+                                       let expiry_secs: Result<u32, _> = expiry_secs_str.unwrap().parse();
+                                       if expiry_secs.is_err() {
+                                               println!("ERROR: getinvoice provided expiry was not a number");
+                                               continue;
+                                       }
+
                                        get_invoice(
                                                amt_msat.unwrap(),
                                                inbound_payments.clone(),
                                                channel_manager.clone(),
                                                keys_manager.clone(),
                                                network,
+                                               expiry_secs.unwrap(),
                                        );
                                }
                                "connectpeer" => {
@@ -315,44 +332,86 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                println!("SUCCESS: connected to peer {}", pubkey);
                                        }
                                }
-                               "listchannels" => list_channels(channel_manager.clone()),
+                               "listchannels" => list_channels(&channel_manager, &network_graph),
                                "listpayments" => {
                                        list_payments(inbound_payments.clone(), outbound_payments.clone())
                                }
                                "closechannel" => {
                                        let channel_id_str = words.next();
                                        if channel_id_str.is_none() {
-                                               println!("ERROR: closechannel requires a channel ID: `closechannel <channel_id>`");
+                                               println!("ERROR: closechannel requires a channel ID: `closechannel <channel_id> <peer_pubkey>`");
                                                continue;
                                        }
                                        let channel_id_vec = hex_utils::to_vec(channel_id_str.unwrap());
-                                       if channel_id_vec.is_none() {
-                                               println!("ERROR: couldn't parse channel_id as hex");
+                                       if channel_id_vec.is_none() || channel_id_vec.as_ref().unwrap().len() != 32 {
+                                               println!("ERROR: couldn't parse channel_id");
                                                continue;
                                        }
                                        let mut channel_id = [0; 32];
                                        channel_id.copy_from_slice(&channel_id_vec.unwrap());
-                                       close_channel(channel_id, channel_manager.clone());
+
+                                       let peer_pubkey_str = words.next();
+                                       if peer_pubkey_str.is_none() {
+                                               println!("ERROR: closechannel requires a peer pubkey: `closechannel <channel_id> <peer_pubkey>`");
+                                               continue;
+                                       }
+                                       let peer_pubkey_vec = match hex_utils::to_vec(peer_pubkey_str.unwrap()) {
+                                               Some(peer_pubkey_vec) => peer_pubkey_vec,
+                                               None => {
+                                                       println!("ERROR: couldn't parse peer_pubkey");
+                                                       continue;
+                                               }
+                                       };
+                                       let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
+                                               Ok(peer_pubkey) => peer_pubkey,
+                                               Err(_) => {
+                                                       println!("ERROR: couldn't parse peer_pubkey");
+                                                       continue;
+                                               }
+                                       };
+
+                                       close_channel(channel_id, peer_pubkey, channel_manager.clone());
                                }
                                "forceclosechannel" => {
                                        let channel_id_str = words.next();
                                        if channel_id_str.is_none() {
-                                               println!("ERROR: forceclosechannel requires a channel ID: `forceclosechannel <channel_id>`");
+                                               println!("ERROR: forceclosechannel requires a channel ID: `forceclosechannel <channel_id> <peer_pubkey>`");
                                                continue;
                                        }
                                        let channel_id_vec = hex_utils::to_vec(channel_id_str.unwrap());
-                                       if channel_id_vec.is_none() {
-                                               println!("ERROR: couldn't parse channel_id as hex");
+                                       if channel_id_vec.is_none() || channel_id_vec.as_ref().unwrap().len() != 32 {
+                                               println!("ERROR: couldn't parse channel_id");
                                                continue;
                                        }
                                        let mut channel_id = [0; 32];
                                        channel_id.copy_from_slice(&channel_id_vec.unwrap());
-                                       force_close_channel(channel_id, channel_manager.clone());
+
+                                       let peer_pubkey_str = words.next();
+                                       if peer_pubkey_str.is_none() {
+                                               println!("ERROR: forceclosechannel requires a peer pubkey: `forceclosechannel <channel_id> <peer_pubkey>`");
+                                               continue;
+                                       }
+                                       let peer_pubkey_vec = match hex_utils::to_vec(peer_pubkey_str.unwrap()) {
+                                               Some(peer_pubkey_vec) => peer_pubkey_vec,
+                                               None => {
+                                                       println!("ERROR: couldn't parse peer_pubkey");
+                                                       continue;
+                                               }
+                                       };
+                                       let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
+                                               Ok(peer_pubkey) => peer_pubkey,
+                                               Err(_) => {
+                                                       println!("ERROR: couldn't parse peer_pubkey");
+                                                       continue;
+                                               }
+                                       };
+
+                                       force_close_channel(channel_id, peer_pubkey, channel_manager.clone());
                                }
-                               "nodeinfo" => node_info(channel_manager.clone(), peer_manager.clone()),
+                               "nodeinfo" => node_info(&channel_manager, &peer_manager),
                                "listpeers" => list_peers(peer_manager.clone()),
                                "signmessage" => {
-                                       const MSG_STARTPOS: usize = "signmsg".len() + 1;
+                                       const MSG_STARTPOS: usize = "signmessage".len() + 1;
                                        if line.as_bytes().len() <= MSG_STARTPOS {
                                                println!("ERROR: signmsg requires a message");
                                                continue;
@@ -361,10 +420,53 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
                                                "{:?}",
                                                lightning::util::message_signing::sign(
                                                        &line.as_bytes()[MSG_STARTPOS..],
-                                                       &keys_manager.get_node_secret()
+                                                       &keys_manager.get_node_secret(Recipient::Node).unwrap()
                                                )
                                        );
                                }
+                               "sendonionmessage" => {
+                                       let path_pks_str = words.next();
+                                       if path_pks_str.is_none() {
+                                               println!(
+                                                       "ERROR: sendonionmessage requires at least one node id for the path"
+                                               );
+                                               continue;
+                                       }
+                                       let mut node_pks = Vec::new();
+                                       let mut errored = false;
+                                       for pk_str in path_pks_str.unwrap().split(",") {
+                                               let node_pubkey_vec = match hex_utils::to_vec(pk_str) {
+                                                       Some(peer_pubkey_vec) => peer_pubkey_vec,
+                                                       None => {
+                                                               println!("ERROR: couldn't parse peer_pubkey");
+                                                               errored = true;
+                                                               break;
+                                                       }
+                                               };
+                                               let node_pubkey = match PublicKey::from_slice(&node_pubkey_vec) {
+                                                       Ok(peer_pubkey) => peer_pubkey,
+                                                       Err(_) => {
+                                                               println!("ERROR: couldn't parse peer_pubkey");
+                                                               errored = true;
+                                                               break;
+                                                       }
+                                               };
+                                               node_pks.push(node_pubkey);
+                                       }
+                                       if errored {
+                                               continue;
+                                       }
+                                       let destination_pk = node_pks.pop().unwrap();
+                                       match onion_messenger.send_onion_message(
+                                               &node_pks,
+                                               Destination::Node(destination_pk),
+                                               None,
+                                       ) {
+                                               Ok(()) => println!("SUCCESS: forwarded onion message to first hop"),
+                                               Err(e) => println!("ERROR: failed to send onion message: {:?}", e),
+                                       }
+                               }
+                               "quit" | "exit" => break,
                                _ => println!("Unknown command. See `\"help\" for available commands."),
                        }
                }
@@ -372,24 +474,43 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
 }
 
 fn help() {
-       println!("openchannel pubkey@host:port <amt_satoshis>");
-       println!("sendpayment <invoice>");
-       println!("getinvoice <amt_millisatoshis>");
-       println!("connectpeer pubkey@host:port");
-       println!("listchannels");
-       println!("listpayments");
-       println!("closechannel <channel_id>");
-       println!("forceclosechannel <channel_id>");
-       println!("nodeinfo");
-       println!("listpeers");
-       println!("signmessage <message>");
+       let package_version = env!("CARGO_PKG_VERSION");
+       let package_name = env!("CARGO_PKG_NAME");
+       println!("\nVERSION:");
+       println!("  {} v{}", package_name, package_version);
+       println!("\nUSAGE:");
+       println!("  Command [arguments]");
+       println!("\nCOMMANDS:");
+       println!("  help\tShows a list of commands.");
+       println!("  quit\tClose the application.");
+       println!("\n  Channels:");
+       println!("      openchannel pubkey@host:port <amt_satoshis> [--public]");
+       println!("      closechannel <channel_id> <peer_pubkey>");
+       println!("      forceclosechannel <channel_id> <peer_pubkey>");
+       println!("      listchannels");
+       println!("\n  Peers:");
+       println!("      connectpeer pubkey@host:port");
+       println!("      listpeers");
+       println!("\n  Payments:");
+       println!("      sendpayment <invoice>");
+       println!("      keysend <dest_pubkey> <amt_msats>");
+       println!("      listpayments");
+       println!("\n  Invoices:");
+       println!("      getinvoice <amt_msats> <expiry_secs>");
+       println!("\n  Other:");
+       println!("      signmessage <message>");
+       println!("      sendonionmessage <node_id_1,node_id_2,..,destination_node_id>");
+       println!("      nodeinfo");
 }
 
-fn node_info(channel_manager: Arc<ChannelManager>, peer_manager: Arc<PeerManager>) {
+fn node_info(channel_manager: &Arc<ChannelManager>, peer_manager: &Arc<PeerManager>) {
        println!("\t{{");
        println!("\t\t node_pubkey: {}", channel_manager.get_our_node_id());
-       println!("\t\t num_channels: {}", channel_manager.list_channels().len());
-       println!("\t\t num_usable_channels: {}", channel_manager.list_usable_channels().len());
+       let chans = channel_manager.list_channels();
+       println!("\t\t num_channels: {}", chans.len());
+       println!("\t\t num_usable_channels: {}", chans.iter().filter(|c| c.is_usable).count());
+       let local_balance_msat = chans.iter().map(|c| c.balance_msat).sum::<u64>();
+       println!("\t\t local_balance_msat: {}", local_balance_msat);
        println!("\t\t num_peers: {}", peer_manager.get_peer_node_ids().len());
        println!("\t}},");
 }
@@ -402,7 +523,7 @@ fn list_peers(peer_manager: Arc<PeerManager>) {
        println!("\t}},");
 }
 
-fn list_channels(channel_manager: Arc<ChannelManager>) {
+fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<NetworkGraph>) {
        print!("[");
        for chan_info in channel_manager.list_channels() {
                println!("");
@@ -411,20 +532,27 @@ fn list_channels(channel_manager: Arc<ChannelManager>) {
                if let Some(funding_txo) = chan_info.funding_txo {
                        println!("\t\tfunding_txid: {},", funding_txo.txid);
                }
+
                println!(
                        "\t\tpeer_pubkey: {},",
                        hex_utils::hex_str(&chan_info.counterparty.node_id.serialize())
                );
+               if let Some(node_info) = network_graph
+                       .read_only()
+                       .nodes()
+                       .get(&NodeId::from_pubkey(&chan_info.counterparty.node_id))
+               {
+                       if let Some(announcement) = &node_info.announcement_info {
+                               println!("\t\tpeer_alias: {}", announcement.alias);
+                       }
+               }
+
                if let Some(id) = chan_info.short_channel_id {
                        println!("\t\tshort_channel_id: {},", id);
                }
-               println!("\t\tis_confirmed_onchain: {},", chan_info.is_funding_locked);
+               println!("\t\tis_channel_ready: {},", chan_info.is_channel_ready);
                println!("\t\tchannel_value_satoshis: {},", chan_info.channel_value_satoshis);
-               println!(
-                       "\t\tlocal_balance_msat: {},",
-                       chan_info.outbound_capacity_msat
-                               + chan_info.unspendable_punishment_reserve.unwrap_or(0) * 1000
-               );
+               println!("\t\tlocal_balance_msat: {},", chan_info.balance_msat);
                if chan_info.is_usable {
                        println!("\t\tavailable_balance_for_send_msat: {},", chan_info.outbound_capacity_msat);
                        println!("\t\tavailable_balance_for_recv_msat: {},", chan_info.inbound_capacity_msat);
@@ -486,6 +614,16 @@ pub(crate) async fn connect_peer_if_necessary(
                        return Ok(());
                }
        }
+       let res = do_connect_peer(pubkey, peer_addr, peer_manager).await;
+       if res.is_err() {
+               println!("ERROR: failed to connect to peer");
+       }
+       res
+}
+
+pub(crate) async fn do_connect_peer(
+       pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc<PeerManager>,
+) -> Result<(), ()> {
        match lightning_net_tokio::connect_outbound(Arc::clone(&peer_manager), pubkey, peer_addr).await
        {
                Some(connection_closed_future) => {
@@ -493,24 +631,19 @@ pub(crate) async fn connect_peer_if_necessary(
                        loop {
                                match futures::poll!(&mut connection_closed_future) {
                                        std::task::Poll::Ready(_) => {
-                                               println!("ERROR: Peer disconnected before we finished the handshake");
                                                return Err(());
                                        }
                                        std::task::Poll::Pending => {}
                                }
                                // Avoid blocking the tokio context by sleeping a bit
                                match peer_manager.get_peer_node_ids().iter().find(|id| **id == pubkey) {
-                                       Some(_) => break,
+                                       Some(_) => return Ok(()),
                                        None => tokio::time::sleep(Duration::from_millis(10)).await,
                                }
                        }
                }
-               None => {
-                       println!("ERROR: failed to connect to peer");
-                       return Err(());
-               }
+               None => Err(()),
        }
-       Ok(())
 }
 
 fn open_channel(
@@ -518,12 +651,15 @@ fn open_channel(
        channel_manager: Arc<ChannelManager>,
 ) -> Result<(), ()> {
        let config = UserConfig {
-               peer_channel_config_limits: ChannelHandshakeLimits {
+               channel_handshake_limits: ChannelHandshakeLimits {
                        // lnd's max to_self_delay is 2016, so we want to be compatible.
                        their_to_self_delay: 2016,
                        ..Default::default()
                },
-               channel_options: ChannelConfig { announced_channel, ..Default::default() },
+               channel_handshake_config: ChannelHandshakeConfig {
+                       announced_channel,
+                       ..Default::default()
+               },
                ..Default::default()
        };
 
@@ -581,40 +717,47 @@ fn send_payment<E: EventHandler>(
        );
 }
 
-fn keysend(
-       payee_pubkey: PublicKey, amt_msat: u64, network_graph: Arc<NetworkGraph>,
-       channel_manager: Arc<ChannelManager>, payment_storage: PaymentInfoStorage,
-       logger: Arc<FilesystemLogger>, scorer: Arc<Mutex<Scorer>>,
+fn keysend<E: EventHandler, K: KeysInterface>(
+       invoice_payer: &InvoicePayer<E>, payee_pubkey: PublicKey, amt_msat: u64, keys: &K,
+       payment_storage: PaymentInfoStorage,
 ) {
-       let first_hops = channel_manager.list_usable_channels();
-       let payer_pubkey = channel_manager.get_our_node_id();
-
-       let payee = Payee::for_keysend(payee_pubkey);
-       let params = RouteParameters { payee, final_value_msat: amt_msat, final_cltv_expiry_delta: 40 };
-
-       let route = match router::find_route(
-               &payer_pubkey,
-               &params,
-               &network_graph,
-               Some(&first_hops.iter().collect::<Vec<_>>()),
-               logger,
-               &scorer.lock().unwrap(),
+       let payment_preimage = keys.get_secure_random_bytes();
+
+       let status = match invoice_payer.pay_pubkey(
+               payee_pubkey,
+               PaymentPreimage(payment_preimage),
+               amt_msat,
+               40,
        ) {
-               Ok(r) => r,
-               Err(e) => {
+               Ok(_payment_id) => {
+                       println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
+                       print!("> ");
+                       HTLCStatus::Pending
+               }
+               Err(PaymentError::Invoice(e)) => {
+                       println!("ERROR: invalid payee: {}", e);
+                       print!("> ");
+                       return;
+               }
+               Err(PaymentError::Routing(e)) => {
                        println!("ERROR: failed to find route: {}", e.err);
+                       print!("> ");
                        return;
                }
+               Err(PaymentError::Sending(e)) => {
+                       println!("ERROR: failed to send payment: {:?}", e);
+                       print!("> ");
+                       HTLCStatus::Failed
+               }
        };
 
        let mut payments = payment_storage.lock().unwrap();
-       let payment_hash = channel_manager.send_spontaneous_payment(&route, None).unwrap().0;
        payments.insert(
-               payment_hash,
+               PaymentHash(Sha256::hash(&payment_preimage).into_inner()),
                PaymentInfo {
                        preimage: None,
                        secret: None,
-                       status: HTLCStatus::Pending,
+                       status,
                        amt_msat: MillisatAmount(Some(amt_msat)),
                },
        );
@@ -622,14 +765,14 @@ fn keysend(
 
 fn get_invoice(
        amt_msat: u64, payment_storage: PaymentInfoStorage, channel_manager: Arc<ChannelManager>,
-       keys_manager: Arc<KeysManager>, network: Network,
+       keys_manager: Arc<KeysManager>, network: Network, expiry_secs: u32,
 ) {
        let mut payments = payment_storage.lock().unwrap();
        let currency = match network {
                Network::Bitcoin => Currency::Bitcoin,
                Network::Testnet => Currency::BitcoinTestnet,
                Network::Regtest => Currency::Regtest,
-               Network::Signet => panic!("Signet unsupported"),
+               Network::Signet => Currency::Signet,
        };
        let invoice = match utils::create_invoice_from_channelmanager(
                &channel_manager,
@@ -637,6 +780,7 @@ fn get_invoice(
                currency,
                Some(amt_msat),
                "ldk-tutorial-node".to_string(),
+               expiry_secs,
        ) {
                Ok(inv) => {
                        println!("SUCCESS: generated invoice: {}", inv);
@@ -660,15 +804,19 @@ fn get_invoice(
        );
 }
 
-fn close_channel(channel_id: [u8; 32], channel_manager: Arc<ChannelManager>) {
-       match channel_manager.close_channel(&channel_id) {
+fn close_channel(
+       channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
+) {
+       match channel_manager.close_channel(&channel_id, &counterparty_node_id) {
                Ok(()) => println!("EVENT: initiating channel close"),
                Err(e) => println!("ERROR: failed to close channel: {:?}", e),
        }
 }
 
-fn force_close_channel(channel_id: [u8; 32], channel_manager: Arc<ChannelManager>) {
-       match channel_manager.force_close_channel(&channel_id) {
+fn force_close_channel(
+       channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
+) {
+       match channel_manager.force_close_broadcasting_latest_txn(&channel_id, &counterparty_node_id) {
                Ok(()) => println!("EVENT: initiating channel force-close"),
                Err(e) => println!("ERROR: failed to force-close channel: {:?}", e),
        }
@@ -680,7 +828,7 @@ pub(crate) fn parse_peer_info(
        let mut pubkey_and_addr = peer_pubkey_and_ip_addr.split("@");
        let pubkey = pubkey_and_addr.next();
        let peer_addr_str = pubkey_and_addr.next();
-       if peer_addr_str.is_none() || peer_addr_str.is_none() {
+       if peer_addr_str.is_none() {
                return Err(std::io::Error::new(
                        std::io::ErrorKind::Other,
                        "ERROR: incorrectly formatted peer info. Should be formatted as: `pubkey@host:port`",