Skip to content

Commit 8462362

Browse files
author
Antoine Riard
committed
Add Display trait on network structs for routing bug track
1 parent 327828d commit 8462362

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

src/ln/router.rs

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::cmp;
1212
use std::sync::{RwLock,Arc};
1313
use std::collections::{HashMap,BinaryHeap};
1414
use std::collections::hash_map::Entry;
15+
use std;
1516

1617
/// A hop in a route
1718
#[derive(Clone)]
@@ -35,31 +36,46 @@ pub struct Route {
3536
pub hops: Vec<RouteHop>,
3637
}
3738

38-
//Here, DirectionalChannelInfo, ChannelInfo, NodeInfo and NetworkMap are pub(crate) only for log_* macros access
39-
pub(crate) struct DirectionalChannelInfo {
40-
pub(crate) src_node_id: PublicKey,
41-
pub(crate) last_update: u32,
42-
pub(crate) enabled: bool,
43-
pub(crate) cltv_expiry_delta: u16,
44-
pub(crate) htlc_minimum_msat: u64,
45-
pub(crate) fee_base_msat: u32,
46-
pub(crate) fee_proportional_millionths: u32,
39+
struct DirectionalChannelInfo {
40+
src_node_id: PublicKey,
41+
last_update: u32,
42+
enabled: bool,
43+
cltv_expiry_delta: u16,
44+
htlc_minimum_msat: u64,
45+
fee_base_msat: u32,
46+
fee_proportional_millionths: u32,
4747
}
4848

49-
pub(crate) struct ChannelInfo {
50-
pub(crate) features: GlobalFeatures,
51-
pub(crate) one_to_two: DirectionalChannelInfo,
52-
pub(crate) two_to_one: DirectionalChannelInfo,
49+
impl std::fmt::Display for DirectionalChannelInfo {
50+
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)?;
52+
Ok(())
53+
}
5354
}
5455

55-
pub(crate) struct NodeInfo {
56+
struct ChannelInfo {
57+
features: GlobalFeatures,
58+
one_to_two: DirectionalChannelInfo,
59+
two_to_one: DirectionalChannelInfo,
60+
}
61+
62+
impl std::fmt::Display for ChannelInfo {
63+
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)?;
67+
Ok(())
68+
}
69+
}
70+
71+
struct NodeInfo {
5672
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
5773
channels: Vec<(u64, Sha256dHash)>,
5874
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
59-
pub(crate) channels: Vec<u64>,
75+
channels: Vec<u64>,
6076

61-
pub(crate) lowest_inbound_channel_fee_base_msat: u32,
62-
pub(crate) lowest_inbound_channel_fee_proportional_millionths: u32,
77+
lowest_inbound_channel_fee_base_msat: u32,
78+
lowest_inbound_channel_fee_proportional_millionths: u32,
6379

6480
features: GlobalFeatures,
6581
last_update: u32,
@@ -68,14 +84,41 @@ pub(crate) struct NodeInfo {
6884
addresses: Vec<NetAddress>,
6985
}
7086

71-
pub(crate) struct NetworkMap {
87+
impl std::fmt::Display for NodeInfo {
88+
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
96+
Ok(())
97+
}
98+
}
99+
100+
struct NetworkMap {
72101
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
73102
channels: HashMap<(u64, Sha256dHash), ChannelInfo>,
74103
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
75-
pub(crate) channels: HashMap<u64, ChannelInfo>,
104+
channels: HashMap<u64, ChannelInfo>,
76105

77-
pub(crate) our_node_id: PublicKey,
78-
pub(crate) nodes: HashMap<PublicKey, NodeInfo>,
106+
our_node_id: PublicKey,
107+
nodes: HashMap<PublicKey, NodeInfo>,
108+
}
109+
110+
impl std::fmt::Display for NetworkMap {
111+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
112+
write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.our_node_id))?;
113+
for (key, val) in self.channels.iter() {
114+
write!(f, " {} :\n {}\n", key, val)?;
115+
}
116+
write!(f, "[Nodes]\n")?;
117+
for (key, val) in self.nodes.iter() {
118+
write!(f, " {} :\n {}\n", log_pubkey!(key), val)?;
119+
}
120+
Ok(())
121+
}
79122
}
80123

81124
impl NetworkMap {

src/util/macro_logger.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ macro_rules! log_funding_channel_id {
5252
}
5353
}
5454

55+
#[allow(dead_code)]
5556
pub(crate) struct DebugRoute<'a>(pub &'a Route);
5657
impl<'a> std::fmt::Display for DebugRoute<'a> {
5758
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
@@ -61,6 +62,7 @@ impl<'a> std::fmt::Display for DebugRoute<'a> {
6162
Ok(())
6263
}
6364
}
65+
#[allow(unused_macros)]
6466
macro_rules! log_route {
6567
($obj: expr) => {
6668
::util::macro_logger::DebugRoute(&$obj)

0 commit comments

Comments
 (0)