Skip to content

Commit 08038d7

Browse files
committed
Clean up excess \ns in route debug, use all debug encoders
1 parent 6fb687d commit 08038d7

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/ln/router.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct DirectionalChannelInfo {
4848

4949
impl std::fmt::Display for DirectionalChannelInfo {
5050
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
51-
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)?;
51+
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)?;
5252
Ok(())
5353
}
5454
}
@@ -61,9 +61,7 @@ struct ChannelInfo {
6161

6262
impl std::fmt::Display for ChannelInfo {
6363
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
64-
//TODO: GlobalFeatures
65-
write!(f, " one_to_two {}", self.one_to_two)?;
66-
write!(f, " two_to_one {}", self.two_to_one)?;
64+
write!(f, "features: {}, one_to_two: {}, two_to_one: {}", log_bytes!(self.features.encode()), self.one_to_two, self.two_to_one)?;
6765
Ok(())
6866
}
6967
}
@@ -86,13 +84,7 @@ struct NodeInfo {
8684

8785
impl std::fmt::Display for NodeInfo {
8886
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
89-
write!(f, " Channels\n")?;
90-
for c in self.channels.iter() {
91-
write!(f, " {}\n", c)?;
92-
}
93-
write!(f, " lowest_inbound_channel_fee_base_msat {}\n", self.lowest_inbound_channel_fee_base_msat)?;
94-
write!(f, " lowest_inbound_channel_fee_proportional_millionths {}\n", self.lowest_inbound_channel_fee_proportional_millionths)?;
95-
//TODO: GlobalFeatures, last_update, rgb, alias, addresses
87+
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[..])?;
9688
Ok(())
9789
}
9890
}
@@ -111,11 +103,11 @@ impl std::fmt::Display for NetworkMap {
111103
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
112104
write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.our_node_id))?;
113105
for (key, val) in self.channels.iter() {
114-
write!(f, " {} :\n {}\n", key, val)?;
106+
write!(f, " {}: {}\n", key, val)?;
115107
}
116108
write!(f, "[Nodes]\n")?;
117109
for (key, val) in self.nodes.iter() {
118-
write!(f, " {} :\n {}\n", log_pubkey!(key), val)?;
110+
write!(f, " {}: {}\n", log_pubkey!(key), val)?;
119111
}
120112
Ok(())
121113
}
@@ -414,6 +406,12 @@ impl Router {
414406
}
415407
}
416408

409+
/// Dumps the entire network view of this Router to the logger provided in the constructor at
410+
/// level Trace
411+
pub fn trace_state(&self) {
412+
log_trace!(self, "{}", self.network_map.read().unwrap());
413+
}
414+
417415
/// Get network addresses by node id
418416
pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
419417
let network = self.network_map.read().unwrap();
@@ -610,9 +608,9 @@ impl Router {
610608
}
611609
res.last_mut().unwrap().fee_msat = final_value_msat;
612610
res.last_mut().unwrap().cltv_expiry_delta = final_cltv;
613-
return Ok(Route {
614-
hops: res
615-
});
611+
let route = Route { hops: res };
612+
log_trace!(self, "Got route: {}", log_route!(route));
613+
return Ok(route);
616614
}
617615

618616
match network.nodes.get(&pubkey) {

src/util/macro_logger.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! log_pubkey {
2222
}
2323
}
2424

25-
pub(crate) struct DebugBytes<'a>(pub &'a [u8; 32]);
25+
pub(crate) struct DebugBytes<'a>(pub &'a [u8]);
2626
impl<'a> std::fmt::Display for DebugBytes<'a> {
2727
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
2828
for i in self.0 {
@@ -52,17 +52,15 @@ macro_rules! log_funding_channel_id {
5252
}
5353
}
5454

55-
#[allow(dead_code)]
5655
pub(crate) struct DebugRoute<'a>(pub &'a Route);
5756
impl<'a> std::fmt::Display for DebugRoute<'a> {
5857
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
59-
for (i,h) in self.0.hops.iter().enumerate() {
60-
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)?;
58+
for h in self.0.hops.iter() {
59+
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)?;
6160
}
6261
Ok(())
6362
}
6463
}
65-
#[allow(unused_macros)]
6664
macro_rules! log_route {
6765
($obj: expr) => {
6866
::util::macro_logger::DebugRoute(&$obj)

0 commit comments

Comments
 (0)