Skip to content

Commit 031e46e

Browse files
committed
Log as channel liquidities are/not updated in ProbabilisticScorer
1 parent f2cf24c commit 031e46e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

lightning/src/routing/scoring.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use util::ser::{Readable, ReadableArgs, Writeable, Writer};
6161
use util::logger::Logger;
6262

6363
use prelude::*;
64+
use core::fmt;
6465
use core::cell::{RefCell, RefMut};
6566
use core::ops::{Deref, DerefMut};
6667
use core::time::Duration;
@@ -790,22 +791,29 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
790791

791792
impl<L: DerefMut<Target = u64>, T: Time, U: DerefMut<Target = T>> DirectedChannelLiquidity<L, T, U> {
792793
/// Adjusts the channel liquidity balance bounds when failing to route `amount_msat`.
793-
fn failed_at_channel(&mut self, amount_msat: u64) {
794+
fn failed_at_channel<Log: Deref>(&mut self, amount_msat: u64, chan_descr: fmt::Arguments, logger: &Log) where Log::Target: Logger {
794795
if amount_msat < self.max_liquidity_msat() {
796+
log_debug!(logger, "Setting max liquidity of {} to {}", chan_descr, amount_msat);
795797
self.set_max_liquidity_msat(amount_msat);
798+
} else {
799+
log_trace!(logger, "Max liquidity of {} already more than {}", chan_descr, amount_msat);
796800
}
797801
}
798802

799803
/// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream.
800-
fn failed_downstream(&mut self, amount_msat: u64) {
804+
fn failed_downstream<Log: Deref>(&mut self, amount_msat: u64, chan_descr: fmt::Arguments, logger: &Log) where Log::Target: Logger {
801805
if amount_msat > self.min_liquidity_msat() {
806+
log_debug!(logger, "Setting min liquidity of {} to {}", chan_descr, amount_msat);
802807
self.set_min_liquidity_msat(amount_msat);
808+
} else {
809+
log_trace!(logger, "Min liquidity of {} already less than {}", chan_descr, amount_msat);
803810
}
804811
}
805812

806813
/// Adjusts the channel liquidity balance bounds when successfully routing `amount_msat`.
807-
fn successful(&mut self, amount_msat: u64) {
814+
fn successful<Log: Deref>(&mut self, amount_msat: u64, chan_descr: fmt::Arguments, logger: &Log) where Log::Target: Logger {
808815
let max_liquidity_msat = self.max_liquidity_msat().checked_sub(amount_msat).unwrap_or(0);
816+
log_debug!(logger, "Subtracting {} from max liquidity of {} (setting it to {})", amount_msat, chan_descr, max_liquidity_msat);
809817
self.set_max_liquidity_msat(max_liquidity_msat);
810818
}
811819

@@ -848,6 +856,7 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
848856
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
849857
let amount_msat = path.split_last().map(|(hop, _)| hop.fee_msat).unwrap_or(0);
850858
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
859+
log_trace!(self.logger, "Scoring path through to SCID {} as having failed at {} msat", short_channel_id, amount_msat);
851860
let network_graph = self.network_graph.read_only();
852861
for hop in path {
853862
let target = NodeId::from_pubkey(&hop.pubkey);
@@ -863,22 +872,27 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
863872
.entry(hop.short_channel_id)
864873
.or_insert_with(ChannelLiquidity::new)
865874
.as_directed_mut(source, &target, capacity_msat, liquidity_offset_half_life)
866-
.failed_at_channel(amount_msat);
875+
.failed_at_channel(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
867876
break;
868877
}
869878

870879
self.channel_liquidities
871880
.entry(hop.short_channel_id)
872881
.or_insert_with(ChannelLiquidity::new)
873882
.as_directed_mut(source, &target, capacity_msat, liquidity_offset_half_life)
874-
.failed_downstream(amount_msat);
883+
.failed_downstream(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
884+
} else {
885+
log_debug!(self.logger, "Not able to penalize channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop).",
886+
hop.short_channel_id);
875887
}
876888
}
877889
}
878890

879891
fn payment_path_successful(&mut self, path: &[&RouteHop]) {
880892
let amount_msat = path.split_last().map(|(hop, _)| hop.fee_msat).unwrap_or(0);
881893
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
894+
log_trace!(self.logger, "Scoring path through SCID {} as having succeeded at {} msat.",
895+
path.split_last().map(|(hop, _)| hop.short_channel_id).unwrap_or(0), amount_msat);
882896
let network_graph = self.network_graph.read_only();
883897
for hop in path {
884898
let target = NodeId::from_pubkey(&hop.pubkey);
@@ -893,7 +907,10 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
893907
.entry(hop.short_channel_id)
894908
.or_insert_with(ChannelLiquidity::new)
895909
.as_directed_mut(source, &target, capacity_msat, liquidity_offset_half_life)
896-
.successful(amount_msat);
910+
.successful(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
911+
} else {
912+
log_debug!(self.logger, "Not able to learn for channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop).",
913+
hop.short_channel_id);
897914
}
898915
}
899916
}

0 commit comments

Comments
 (0)