Skip to content

Commit 2a87d5e

Browse files
committed
Provide a utility to log the ProbabilisticScorer's contents
I wrote this when debugging a user's scorer and figured it may be useful upstream.
1 parent 62edee5 commit 2a87d5e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lightning/src/routing/scoring.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,40 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> ProbabilisticScorerUsin
623623
assert!(self.channel_liquidities.insert(short_channel_id, liquidity).is_none());
624624
self
625625
}
626+
627+
/// Dump the contents of this scorer into the configured logger.
628+
///
629+
/// Note that this writes roughly one line per channel for which we have a liquidity estimate,
630+
/// which may be a substantial amount of log output.
631+
fn debug_log_liquidity_stats(&self) {
632+
let graph = self.network_graph.read_only();
633+
for (scid, liq) in self.channel_liquidities.iter() {
634+
if let Some(chan_debug) = graph.channels().get(scid) {
635+
if let Some(dir_debug) = &chan_debug.one_to_two {
636+
let amount = chan_debug.capacity_sats.map(|v| v*1000).or(dir_debug.htlc_maximum_msat);
637+
if let Some(amt) = amount {
638+
let dir_liq = liq.as_directed(&chan_debug.node_one, &chan_debug.node_two, amt, self.liquidity_offset_half_life);
639+
log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})",
640+
chan_debug.node_one, chan_debug.node_two, scid, dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat());
641+
} else {
642+
log_debug!(self.logger, "No amount known for SCID {} from {:?} to {:?}", scid, chan_debug.node_one, chan_debug.node_two);
643+
}
644+
}
645+
if let Some(dir_debug) = &chan_debug.two_to_one {
646+
let amount = chan_debug.capacity_sats.map(|v| v*1000).or(dir_debug.htlc_maximum_msat);
647+
if let Some(amt) = amount {
648+
let dir_liq = liq.as_directed(&chan_debug.node_two, &chan_debug.node_one, amt, self.liquidity_offset_half_life);
649+
log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})",
650+
chan_debug.node_two, chan_debug.node_one, scid, dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat());
651+
} else {
652+
log_debug!(self.logger, "No amount known for SCID {} from {:?} to {:?}", scid, chan_debug.node_two, chan_debug.node_one);
653+
}
654+
}
655+
} else {
656+
log_debug!(self.logger, "No network graph entry for SCID {}", scid);
657+
}
658+
}
659+
}
626660
}
627661

628662
impl ProbabilisticScoringParameters {

0 commit comments

Comments
 (0)