Clean up excess \ns in route debug, use all debug encoders 2018-08-114-rebase
authorMatt Corallo <git@bluematt.me>
Thu, 23 Aug 2018 18:17:02 +0000 (14:17 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 23 Aug 2018 18:52:43 +0000 (14:52 -0400)
src/ln/router.rs
src/util/macro_logger.rs

index 9ef5b7a7ada8fcf617a63d9c5ac115323b003f82..0e6194c3586a35089cdda35299b3e6705c9b4cc1 100644 (file)
@@ -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<Vec<NetAddress>> {
                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) {
index 465126fa25062fd103a630b167c927c2e6fafe47..47ba876dcfa13a64df7c3d59b5f660372e39b7f0 100644 (file)
@@ -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)