Skip to content

Commit 90d6260

Browse files
author
Antoine Riard
committed
Add log_networkmap macros and others for routing bug track
1 parent fef946c commit 90d6260

File tree

2 files changed

+88
-21
lines changed

2 files changed

+88
-21
lines changed

src/ln/router.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@ pub struct Route {
3535
pub hops: Vec<RouteHop>,
3636
}
3737

38-
struct DirectionalChannelInfo {
39-
src_node_id: PublicKey,
40-
last_update: u32,
41-
enabled: bool,
42-
cltv_expiry_delta: u16,
43-
htlc_minimum_msat: u64,
44-
fee_base_msat: u32,
45-
fee_proportional_millionths: u32,
38+
pub struct DirectionalChannelInfo {
39+
pub src_node_id: PublicKey,
40+
pub last_update: u32,
41+
pub enabled: bool,
42+
pub cltv_expiry_delta: u16,
43+
pub htlc_minimum_msat: u64,
44+
pub fee_base_msat: u32,
45+
pub fee_proportional_millionths: u32,
4646
}
4747

48-
struct ChannelInfo {
49-
features: GlobalFeatures,
50-
one_to_two: DirectionalChannelInfo,
51-
two_to_one: DirectionalChannelInfo,
48+
pub struct ChannelInfo {
49+
pub features: GlobalFeatures,
50+
pub one_to_two: DirectionalChannelInfo,
51+
pub two_to_one: DirectionalChannelInfo,
5252
}
5353

54-
struct NodeInfo {
54+
pub struct NodeInfo {
5555
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
5656
channels: Vec<(u64, Sha256dHash)>,
5757
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
58-
channels: Vec<u64>,
58+
pub channels: Vec<u64>,
5959

60-
lowest_inbound_channel_fee_base_msat: u32,
61-
lowest_inbound_channel_fee_proportional_millionths: u32,
60+
pub lowest_inbound_channel_fee_base_msat: u32,
61+
pub lowest_inbound_channel_fee_proportional_millionths: u32,
6262

6363
features: GlobalFeatures,
6464
last_update: u32,
@@ -67,14 +67,14 @@ struct NodeInfo {
6767
addresses: Vec<NetAddress>,
6868
}
6969

70-
struct NetworkMap {
70+
pub struct NetworkMap {
7171
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
7272
channels: HashMap<(u64, Sha256dHash), ChannelInfo>,
7373
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
74-
channels: HashMap<u64, ChannelInfo>,
74+
pub channels: HashMap<u64, ChannelInfo>,
7575

76-
our_node_id: PublicKey,
77-
nodes: HashMap<PublicKey, NodeInfo>,
76+
pub our_node_id: PublicKey,
77+
pub nodes: HashMap<PublicKey, NodeInfo>,
7878
}
7979

8080
impl NetworkMap {

src/util/macro_logger.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use chain::transaction::OutPoint;
33
use bitcoin::util::hash::Sha256dHash;
44
use secp256k1::key::PublicKey;
55

6-
use ln::router::Route;
6+
use ln::router::{Route, NetworkMap, ChannelInfo, NodeInfo, DirectionalChannelInfo};
77

88
use std;
99

@@ -67,6 +67,73 @@ macro_rules! log_route {
6767
}
6868
}
6969

70+
pub(crate) struct DebugDirectionalChannelInfo<'a>(pub &'a DirectionalChannelInfo);
71+
impl<'a> std::fmt::Display for DebugDirectionalChannelInfo<'a> {
72+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
73+
write!(f, " node id {} last_update {} enabled {} cltv_expiry_delta {} htlc_minimum_msat {} fee_base_msat {} fee_proportional_millionths {}\n", log_pubkey!(self.0.src_node_id), self.0.last_update, self.0.enabled, self.0.cltv_expiry_delta, self.0.htlc_minimum_msat, self.0.fee_base_msat, self.0.fee_proportional_millionths)?;
74+
Ok(())
75+
}
76+
}
77+
macro_rules! log_directionalchannelinfo {
78+
($obj: expr) => {
79+
::util::macro_logger::DebugDirectionalChannelInfo(&$obj)
80+
}
81+
}
82+
83+
pub(crate) struct DebugChannelInfo<'a>(pub &'a ChannelInfo);
84+
impl<'a> std::fmt::Display for DebugChannelInfo<'a> {
85+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
86+
//TODO: GlobalFeatures
87+
write!(f, " one_to_two {}", log_directionalchannelinfo!(self.0.one_to_two))?;
88+
write!(f, " two_to_one {}", log_directionalchannelinfo!(self.0.two_to_one))?;
89+
Ok(())
90+
}
91+
}
92+
macro_rules! log_channelinfo {
93+
($obj: expr) => {
94+
::util::macro_logger::DebugChannelInfo(&$obj)
95+
}
96+
}
97+
98+
pub(crate) struct DebugNodeInfo<'a>(pub &'a NodeInfo);
99+
impl<'a> std::fmt::Display for DebugNodeInfo<'a> {
100+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
101+
write!(f, " Channels\n")?;
102+
for c in self.0.channels.iter() {
103+
write!(f, " {}\n", c)?;
104+
}
105+
write!(f, " lowest_inbound_channel_fee_base_msat {}\n", self.0.lowest_inbound_channel_fee_base_msat)?;
106+
write!(f, " lowest_inbound_channel_fee_proportional_millionths {}\n", self.0.lowest_inbound_channel_fee_proportional_millionths)?;
107+
//TODO: GlobalFeatures, last_update, rgb, alias, addresses
108+
Ok(())
109+
}
110+
}
111+
macro_rules! log_nodeinfo {
112+
($obj: expr) => {
113+
::util::macro_logger::DebugNodeInfo(&$obj)
114+
}
115+
}
116+
117+
pub(crate) struct DebugNetworkMap<'a>(pub &'a NetworkMap);
118+
impl<'a> std::fmt::Display for DebugNetworkMap<'a> {
119+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
120+
write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.0.our_node_id))?;
121+
for (key, val) in self.0.channels.iter() {
122+
write!(f, " {} :\n {}\n", key, log_channelinfo!(val))?;
123+
}
124+
write!(f, "[Nodes]\n")?;
125+
for (key, val) in self.0.nodes.iter() {
126+
write!(f, " {} :\n {}\n", log_pubkey!(key), log_nodeinfo!(val))?;
127+
}
128+
Ok(())
129+
}
130+
}
131+
macro_rules! log_networkmap {
132+
($obj: expr) => {
133+
::util::macro_logger::DebugNetworkMap(&$obj)
134+
}
135+
}
136+
70137
macro_rules! log_internal {
71138
($self: ident, $lvl:expr, $($arg:tt)+) => (
72139
&$self.logger.log(&Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));

0 commit comments

Comments
 (0)