Skip to content

Commit 50bcfda

Browse files
author
Antoine Riard
committed
Add log_networkmap macros and others for routing bug track
1 parent 4cbd36f commit 50bcfda

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

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)