From 5ee88ad9f2c9634eb5a1a5131614047028aba757 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 23 Aug 2018 14:17:02 -0400 Subject: [PATCH] Clean up excess \ns in route debug, use all debug encoders --- src/ln/router.rs | 30 ++++++++++++++---------------- src/util/macro_logger.rs | 8 +++----- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/ln/router.rs b/src/ln/router.rs index 9ef5b7a7..0e6194c3 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -48,7 +48,7 @@ struct DirectionalChannelInfo { impl std::fmt::Display for DirectionalChannelInfo { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - write!(f, " node id {} last_update {} enabled {} cltv_expiry_delta {} htlc_minimum_msat {} fee_base_msat {} fee_proportional_millionths {}\n", log_pubkey!(self.src_node_id), self.last_update, self.enabled, self.cltv_expiry_delta, self.htlc_minimum_msat, self.fee_base_msat, self.fee_proportional_millionths)?; + write!(f, "src_node_id {}, last_update {}, enabled {}, cltv_expiry_delta {}, htlc_minimum_msat {}, fee_base_msat {}, fee_proportional_millionths {}", log_pubkey!(self.src_node_id), self.last_update, self.enabled, self.cltv_expiry_delta, self.htlc_minimum_msat, self.fee_base_msat, self.fee_proportional_millionths)?; Ok(()) } } @@ -61,9 +61,7 @@ struct ChannelInfo { impl std::fmt::Display for ChannelInfo { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - //TODO: GlobalFeatures - write!(f, " one_to_two {}", self.one_to_two)?; - write!(f, " two_to_one {}", self.two_to_one)?; + write!(f, "features: {}, one_to_two: {}, two_to_one: {}", log_bytes!(self.features.encode()), self.one_to_two, self.two_to_one)?; Ok(()) } } @@ -86,13 +84,7 @@ struct NodeInfo { impl std::fmt::Display for NodeInfo { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - write!(f, " Channels\n")?; - for c in self.channels.iter() { - write!(f, " {}\n", c)?; - } - write!(f, " lowest_inbound_channel_fee_base_msat {}\n", self.lowest_inbound_channel_fee_base_msat)?; - write!(f, " lowest_inbound_channel_fee_proportional_millionths {}\n", self.lowest_inbound_channel_fee_proportional_millionths)?; - //TODO: GlobalFeatures, last_update, rgb, alias, addresses + write!(f, "features: {}, last_update: {}, lowest_inbound_channel_fee_base_msat: {}, lowest_inbound_channel_fee_proportional_millionths: {}, channels: {:?}", log_bytes!(self.features.encode()), self.last_update, self.lowest_inbound_channel_fee_base_msat, self.lowest_inbound_channel_fee_proportional_millionths, &self.channels[..])?; Ok(()) } } @@ -111,11 +103,11 @@ impl std::fmt::Display for NetworkMap { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.our_node_id))?; for (key, val) in self.channels.iter() { - write!(f, " {} :\n {}\n", key, val)?; + write!(f, " {}: {}\n", key, val)?; } write!(f, "[Nodes]\n")?; for (key, val) in self.nodes.iter() { - write!(f, " {} :\n {}\n", log_pubkey!(key), val)?; + write!(f, " {}: {}\n", log_pubkey!(key), val)?; } Ok(()) } @@ -414,6 +406,12 @@ impl Router { } } + /// Dumps the entire network view of this Router to the logger provided in the constructor at + /// level Trace + pub fn trace_state(&self) { + log_trace!(self, "{}", self.network_map.read().unwrap()); + } + /// Get network addresses by node id pub fn get_addresses(&self, pubkey: &PublicKey) -> Option> { let network = self.network_map.read().unwrap(); @@ -610,9 +608,9 @@ impl Router { } res.last_mut().unwrap().fee_msat = final_value_msat; res.last_mut().unwrap().cltv_expiry_delta = final_cltv; - return Ok(Route { - hops: res - }); + let route = Route { hops: res }; + log_trace!(self, "Got route: {}", log_route!(route)); + return Ok(route); } match network.nodes.get(&pubkey) { diff --git a/src/util/macro_logger.rs b/src/util/macro_logger.rs index 465126fa..47ba876d 100644 --- a/src/util/macro_logger.rs +++ b/src/util/macro_logger.rs @@ -22,7 +22,7 @@ macro_rules! log_pubkey { } } -pub(crate) struct DebugBytes<'a>(pub &'a [u8; 32]); +pub(crate) struct DebugBytes<'a>(pub &'a [u8]); impl<'a> std::fmt::Display for DebugBytes<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { for i in self.0 { @@ -52,17 +52,15 @@ macro_rules! log_funding_channel_id { } } -#[allow(dead_code)] pub(crate) struct DebugRoute<'a>(pub &'a Route); impl<'a> std::fmt::Display for DebugRoute<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - for (i,h) in self.0.hops.iter().enumerate() { - write!(f, "Hop {}\n pubkey {}\n short_channel_id {}\n fee_msat {}\n cltv_expiry_delta {}\n\n", i, log_pubkey!(h.pubkey), h.short_channel_id, h.fee_msat, h.cltv_expiry_delta)?; + for h in self.0.hops.iter() { + write!(f, "node_id: {}, short_channel_id: {}, fee_msat: {}, cltv_expiry_delta: {}\n", log_pubkey!(h.pubkey), h.short_channel_id, h.fee_msat, h.cltv_expiry_delta)?; } Ok(()) } } -#[allow(unused_macros)] macro_rules! log_route { ($obj: expr) => { ::util::macro_logger::DebugRoute(&$obj) -- 2.30.2