Skip to content

Commit 5feef25

Browse files
authored
Merge pull request #1460 from TheBlueMatt/2022-04-liquidity-log
Provide a utility to log the ProbabilisticScorer's contents
2 parents e3a305c + 75c3df0 commit 5feef25

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lightning/src/routing/scoring.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,33 @@ 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+
pub 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+
let log_direction = |source, target| {
636+
if let Some((directed_info, _)) = chan_debug.as_directed_to(target) {
637+
let amt = directed_info.effective_capacity().as_msat();
638+
let dir_liq = liq.as_directed(source, target, amt, self.params.liquidity_offset_half_life);
639+
log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})",
640+
source, target, 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, source, target);
643+
}
644+
};
645+
646+
log_direction(&chan_debug.node_one, &chan_debug.node_two);
647+
log_direction(&chan_debug.node_two, &chan_debug.node_one);
648+
} else {
649+
log_debug!(self.logger, "No network graph entry for SCID {}", scid);
650+
}
651+
}
652+
}
626653
}
627654

628655
impl ProbabilisticScoringParameters {

0 commit comments

Comments
 (0)