X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fscoring.rs;h=3d10a14c6f2cf7c7d63403ef07f70f8c05ee2e59;hb=72e9f53be7b9b44ce8fb1a817a3af6a98db79755;hp=e0f9189bf35e066aa551f2b94190a01ad20707eb;hpb=e6c702f78635021715fc3bb0ac353835c12b5d65;p=rust-lightning diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index e0f9189b..3d10a14c 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -623,6 +623,33 @@ impl, L: Deref, T: Time> ProbabilisticScorerUsin assert!(self.channel_liquidities.insert(short_channel_id, liquidity).is_none()); self } + + /// Dump the contents of this scorer into the configured logger. + /// + /// Note that this writes roughly one line per channel for which we have a liquidity estimate, + /// which may be a substantial amount of log output. + pub fn debug_log_liquidity_stats(&self) { + let graph = self.network_graph.read_only(); + for (scid, liq) in self.channel_liquidities.iter() { + if let Some(chan_debug) = graph.channels().get(scid) { + let log_direction = |source, target| { + if let Some((directed_info, _)) = chan_debug.as_directed_to(target) { + let amt = directed_info.effective_capacity().as_msat(); + let dir_liq = liq.as_directed(source, target, amt, self.params.liquidity_offset_half_life); + log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})", + source, target, scid, dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat()); + } else { + log_debug!(self.logger, "No amount known for SCID {} from {:?} to {:?}", scid, source, target); + } + }; + + log_direction(&chan_debug.node_one, &chan_debug.node_two); + log_direction(&chan_debug.node_two, &chan_debug.node_one); + } else { + log_debug!(self.logger, "No network graph entry for SCID {}", scid); + } + } + } } impl ProbabilisticScoringParameters { @@ -858,12 +885,16 @@ impl, L: Deref, T: Time> Score for Probabilistic let liquidity_offset_half_life = self.params.liquidity_offset_half_life; log_trace!(self.logger, "Scoring path through to SCID {} as having failed at {} msat", short_channel_id, amount_msat); let network_graph = self.network_graph.read_only(); - for hop in path { + for (hop_idx, hop) in path.iter().enumerate() { let target = NodeId::from_pubkey(&hop.pubkey); let channel_directed_from_source = network_graph.channels() .get(&hop.short_channel_id) .and_then(|channel| channel.as_directed_to(&target)); + if hop.short_channel_id == short_channel_id && hop_idx == 0 { + log_warn!(self.logger, "Payment failed at the first hop - we do not attempt to learn channel info in such cases as we can directly observe local state.\n\tBecause we know the local state, we should generally not see failures here - this may be an indication that your channel peer on channel {} is broken and you may wish to close the channel.", hop.short_channel_id); + } + // Only score announced channels. if let Some((channel, source)) = channel_directed_from_source { let capacity_msat = channel.effective_capacity().as_msat();