From: Elias Rohrer Date: Mon, 11 Sep 2023 11:50:10 +0000 (+0200) Subject: Probe up to second-to-last hop if last was provided by route hint X-Git-Tag: v0.0.117-alpha1~6^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=30e47ca56cd7ab2ed46a79bd5b0567e79a7d7941;p=rust-lightning Probe up to second-to-last hop if last was provided by route hint If the last hop was provided by route hint we assume it's not an announced channel. If furthermore only a single route hint is provided we refrain from probing through all the way to the end and instead probe up to the second-to-last channel. Optimally we'd do this not based on above mentioned assumption but rather by checking inclusion in our network graph. However, we don't have access to our graph in `ChannelManager`. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 1b971dce..2748062c 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3539,7 +3539,29 @@ where let mut used_liquidity_map = HashMap::with_capacity(first_hops.len()); let mut res = Vec::new(); - for path in route.paths { + + for mut path in route.paths { + // If the last hop is probably an unannounced channel we refrain from probing all the + // way through to the end and instead probe up to the second-to-last channel. + while let Some(last_path_hop) = path.hops.last() { + if last_path_hop.maybe_announced_channel { + // We found a potentially announced last hop. + break; + } else { + // Drop the last hop, as it's likely unannounced. + log_debug!( + self.logger, + "Avoided sending payment probe all the way to last hop {} as it is likely unannounced.", + last_path_hop.short_channel_id + ); + let final_value_msat = path.final_value_msat(); + path.hops.pop(); + if let Some(new_last) = path.hops.last_mut() { + new_last.fee_msat += final_value_msat; + } + } + } + if path.hops.len() < 2 { log_debug!( self.logger,