Skip to content

Commit 65d8210

Browse files
author
Antoine Riard
committed
Add log_networkmap macros and others for routing bug track
1 parent 165d4ff commit 65d8210

File tree

2 files changed

+98
-21
lines changed

2 files changed

+98
-21
lines changed

src/ln/router.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,31 @@ 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+
//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,
4647
}
4748

48-
struct ChannelInfo {
49-
features: GlobalFeatures,
50-
one_to_two: DirectionalChannelInfo,
51-
two_to_one: DirectionalChannelInfo,
49+
pub(crate) struct ChannelInfo {
50+
pub(crate) features: GlobalFeatures,
51+
pub(crate) one_to_two: DirectionalChannelInfo,
52+
pub(crate) two_to_one: DirectionalChannelInfo,
5253
}
5354

54-
struct NodeInfo {
55+
pub(crate) struct NodeInfo {
5556
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
5657
channels: Vec<(u64, Sha256dHash)>,
5758
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
58-
channels: Vec<u64>,
59+
pub(crate) channels: Vec<u64>,
5960

60-
lowest_inbound_channel_fee_base_msat: u32,
61-
lowest_inbound_channel_fee_proportional_millionths: u32,
61+
pub(crate) lowest_inbound_channel_fee_base_msat: u32,
62+
pub(crate) lowest_inbound_channel_fee_proportional_millionths: u32,
6263

6364
features: GlobalFeatures,
6465
last_update: u32,
@@ -67,14 +68,14 @@ struct NodeInfo {
6768
addresses: Vec<NetAddress>,
6869
}
6970

70-
struct NetworkMap {
71+
pub(crate) struct NetworkMap {
7172
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
7273
channels: HashMap<(u64, Sha256dHash), ChannelInfo>,
7374
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
74-
channels: HashMap<u64, ChannelInfo>,
75+
pub(crate) channels: HashMap<u64, ChannelInfo>,
7576

76-
our_node_id: PublicKey,
77-
nodes: HashMap<PublicKey, NodeInfo>,
77+
pub(crate) our_node_id: PublicKey,
78+
pub(crate) nodes: HashMap<PublicKey, NodeInfo>,
7879
}
7980

8081
impl NetworkMap {

src/util/macro_logger.rs

Lines changed: 77 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

@@ -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,11 +62,86 @@ 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)
6769
}
6870
}
71+
#[allow(dead_code)]
72+
pub(crate) struct DebugDirectionalChannelInfo<'a>(pub &'a DirectionalChannelInfo);
73+
impl<'a> std::fmt::Display for DebugDirectionalChannelInfo<'a> {
74+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
75+
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)?;
76+
Ok(())
77+
}
78+
}
79+
#[allow(unused_macros)]
80+
macro_rules! log_directionalchannelinfo {
81+
($obj: expr) => {
82+
::util::macro_logger::DebugDirectionalChannelInfo(&$obj)
83+
}
84+
}
85+
86+
#[allow(dead_code)]
87+
pub(crate) struct DebugChannelInfo<'a>(pub &'a ChannelInfo);
88+
impl<'a> std::fmt::Display for DebugChannelInfo<'a> {
89+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
90+
//TODO: GlobalFeatures
91+
write!(f, " one_to_two {}", log_directionalchannelinfo!(self.0.one_to_two))?;
92+
write!(f, " two_to_one {}", log_directionalchannelinfo!(self.0.two_to_one))?;
93+
Ok(())
94+
}
95+
}
96+
#[allow(unused_macros)]
97+
macro_rules! log_channelinfo {
98+
($obj: expr) => {
99+
::util::macro_logger::DebugChannelInfo(&$obj)
100+
}
101+
}
102+
103+
#[allow(dead_code)]
104+
pub(crate) struct DebugNodeInfo<'a>(pub &'a NodeInfo);
105+
impl<'a> std::fmt::Display for DebugNodeInfo<'a> {
106+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
107+
write!(f, " Channels\n")?;
108+
for c in self.0.channels.iter() {
109+
write!(f, " {}\n", c)?;
110+
}
111+
write!(f, " lowest_inbound_channel_fee_base_msat {}\n", self.0.lowest_inbound_channel_fee_base_msat)?;
112+
write!(f, " lowest_inbound_channel_fee_proportional_millionths {}\n", self.0.lowest_inbound_channel_fee_proportional_millionths)?;
113+
//TODO: GlobalFeatures, last_update, rgb, alias, addresses
114+
Ok(())
115+
}
116+
}
117+
#[allow(unused_macros)]
118+
macro_rules! log_nodeinfo {
119+
($obj: expr) => {
120+
::util::macro_logger::DebugNodeInfo(&$obj)
121+
}
122+
}
123+
124+
#[allow(dead_code)]
125+
pub(crate) struct DebugNetworkMap<'a>(pub &'a NetworkMap);
126+
impl<'a> std::fmt::Display for DebugNetworkMap<'a> {
127+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
128+
write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.0.our_node_id))?;
129+
for (key, val) in self.0.channels.iter() {
130+
write!(f, " {} :\n {}\n", key, log_channelinfo!(val))?;
131+
}
132+
write!(f, "[Nodes]\n")?;
133+
for (key, val) in self.0.nodes.iter() {
134+
write!(f, " {} :\n {}\n", log_pubkey!(key), log_nodeinfo!(val))?;
135+
}
136+
Ok(())
137+
}
138+
}
139+
#[allow(unused_macros)]
140+
macro_rules! log_networkmap {
141+
($obj: expr) => {
142+
::util::macro_logger::DebugNetworkMap(&$obj)
143+
}
144+
}
69145

70146
macro_rules! log_internal {
71147
($self: ident, $lvl:expr, $($arg:tt)+) => (

0 commit comments

Comments
 (0)