From f561efbba58419cab7b9bf362166e4228dcb094e Mon Sep 17 00:00:00 2001 From: Dominic Leutenegger Date: Wed, 4 Oct 2023 13:20:21 +0200 Subject: [PATCH] Expose `log_debug_info` method --- examples/3l-node/cli.rs | 8 ++++++++ src/lib.rs | 27 ++++++++++++++++++++++++++- src/lipalightninglib.udl | 6 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/examples/3l-node/cli.rs b/examples/3l-node/cli.rs index 7c7f64e1..7a13ae10 100644 --- a/examples/3l-node/cli.rs +++ b/examples/3l-node/cli.rs @@ -152,6 +152,11 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) { Err(e) => println!("{}", e.red()), } } + "logdebug" => { + if let Err(e) = node.log_debug_info() { + println!("{}", e.to_string().red()); + } + } "foreground" => { node.foreground(); } @@ -226,6 +231,7 @@ fn setup_editor(history_path: &Path) -> Editor { "paymentuuid", )); hints.insert(CommandHint::new("sweep
", "sweep")); + hints.insert(CommandHint::new("logdebug", "logdebug")); hints.insert(CommandHint::new("foreground", "foreground")); hints.insert(CommandHint::new("background", "background")); hints.insert(CommandHint::new("stop", "stop")); @@ -263,6 +269,8 @@ fn help() { println!(); println!(" sweep
"); println!(); + println!(" logdebug"); + println!(); println!(" foreground"); println!(" background"); println!(); diff --git a/src/lib.rs b/src/lib.rs index a551d85e..b5a9c486 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,7 +63,7 @@ use email_address::EmailAddress; use honey_badger::secrets::{generate_keypair, KeyPair}; use honey_badger::{Auth, AuthLevel, CustomTermsAndConditions}; use iban::Iban; -use log::trace; +use log::{info, trace}; use logger::init_logger_once; use num_enum::TryFromPrimitive; use perro::Error::RuntimeError; @@ -854,6 +854,31 @@ impl LightningNode { .txid .to_hex()) } + + pub fn log_debug_info(&self) -> Result<()> { + let peers = self + .rt + .handle() + .block_on(self.sdk.execute_dev_command("listpeers".to_string())) + .map_to_runtime_error( + RuntimeErrorCode::NodeUnavailable, + "Couldn't execute `listpeers` command", + )?; + + let peer_channels = self + .rt + .handle() + .block_on(self.sdk.execute_dev_command("listpeerchannels".to_string())) + .map_to_runtime_error( + RuntimeErrorCode::NodeUnavailable, + "Couldn't execute `listpeerchannels` command", + )?; + + info!("List of peers:\n{}", peers); + info!("List of peer channels:\n{}", peer_channels); + + Ok(()) + } } fn to_offer(topup_info: TopupInfo, current_rate: &Option) -> OfferInfo { diff --git a/src/lipalightninglib.udl b/src/lipalightninglib.udl index 2614b9e5..beccdffa 100644 --- a/src/lipalightninglib.udl +++ b/src/lipalightninglib.udl @@ -174,6 +174,12 @@ interface LightningNode { // Returns the txid of the sweeping transaction. [Throws=LnError] string sweep(string address, u32 onchain_fee); + + // Prints additional debug information to the logs. + // + // Throws an error in case that the necessary information can't be received. + [Throws=LnError] + void log_debug_info(); }; // An object that holds all configuration needed to start a LightningNode instance.