Skip to content

Commit d254510

Browse files
committed
f DRY directional logging
1 parent b45c5ed commit d254510

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

lightning/src/routing/scoring.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//! [`find_route`]: crate::routing::router::find_route
5656
5757
use ln::msgs::DecodeError;
58-
use routing::network_graph::{NetworkGraph, NodeId};
58+
use routing::network_graph::{ChannelUpdateInfo, NetworkGraph, NodeId};
5959
use routing::router::RouteHop;
6060
use util::ser::{Readable, ReadableArgs, Writeable, Writer};
6161
use util::logger::Logger;
@@ -632,26 +632,21 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> ProbabilisticScorerUsin
632632
let graph = self.network_graph.read_only();
633633
for (scid, liq) in self.channel_liquidities.iter() {
634634
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.params.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.params.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);
635+
let log_direction = |dir: &Option<ChannelUpdateInfo>, sender, recipient| {
636+
if let Some(dir_debug) = dir {
637+
let amount = chan_debug.capacity_sats.map(|v| v*1000).or(dir_debug.htlc_maximum_msat);
638+
if let Some(amt) = amount {
639+
let dir_liq = liq.as_directed(sender, recipient, amt, self.params.liquidity_offset_half_life);
640+
log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})",
641+
sender, recipient, scid, dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat());
642+
} else {
643+
log_debug!(self.logger, "No amount known for SCID {} from {:?} to {:?}", scid, sender, recipient);
644+
}
653645
}
654-
}
646+
};
647+
648+
log_direction(&chan_debug.one_to_two, &chan_debug.node_one, &chan_debug.node_two);
649+
log_direction(&chan_debug.two_to_one, &chan_debug.node_two, &chan_debug.node_one);
655650
} else {
656651
log_debug!(self.logger, "No network graph entry for SCID {}", scid);
657652
}

0 commit comments

Comments
 (0)