Skip to content

Commit 1ff1208

Browse files
committed
Log which hop in a path was the most limiting in capacity
Its generally rather difficult to debug the pathfinding logic from a log, and sadly because we cannot feasibly log each step in a pathfinding search there's relatively few options we have for improving this. However, one specific question we occasionally get is "why did the pathfinder decide to use MPP"? While we similarly cannot practically log every possible path the pathfinder could have taken to explain why a specific path which required MPP was taken, we can at least explain which hop in the path was the most limited, which we do here.
1 parent 209cb2a commit 1ff1208

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lightning/src/routing/router.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2125,10 +2125,10 @@ impl<'a> PaymentPath<'a> {
21252125
// Returns the maximum contribution that this path can make to the final value of the payment. May
21262126
// be slightly lower than the actual max due to rounding errors when aggregating fees along the
21272127
// path.
2128-
fn compute_max_final_value_contribution(
2128+
fn max_final_value_msat(
21292129
&self, used_liquidities: &HashMap<CandidateHopId, u64>, channel_saturation_pow_half: u8
2130-
) -> u64 {
2131-
let mut max_path_contribution = u64::MAX;
2130+
) -> (u64, usize) {
2131+
let mut max_path_contribution = (0, u64::MAX);
21322132
for (idx, (hop, _)) in self.hops.iter().enumerate() {
21332133
let hop_effective_capacity_msat = hop.candidate.effective_capacity();
21342134
let hop_max_msat = max_htlc_from_capacity(
@@ -2155,7 +2155,9 @@ impl<'a> PaymentPath<'a> {
21552155

21562156
if let Some(hop_contribution) = hop_max_final_value_contribution {
21572157
let hop_contribution: u64 = hop_contribution.try_into().unwrap_or(u64::MAX);
2158-
max_path_contribution = core::cmp::min(hop_contribution, max_path_contribution);
2158+
if hop_contribution <= max_path_contribution.1 {
2159+
max_path_contribution = (idx, hop_contribution);
2160+
}
21592161
} else { debug_assert!(false); }
21602162
}
21612163

@@ -3311,9 +3313,8 @@ where L::Target: Logger {
33113313
// recompute the fees again, so that if that's the case, we match the currently
33123314
// underpaid htlc_minimum_msat with fees.
33133315
debug_assert_eq!(payment_path.get_value_msat(), value_contribution_msat);
3314-
let max_path_contribution_msat = payment_path.compute_max_final_value_contribution(
3315-
&used_liquidities, channel_saturation_pow_half
3316-
);
3316+
let (lowest_value_contrib_hop, max_path_contribution_msat) =
3317+
payment_path.max_final_value_msat(&used_liquidities, channel_saturation_pow_half);
33173318
let desired_value_contribution = cmp::min(max_path_contribution_msat, final_value_msat);
33183319
value_contribution_msat = payment_path.update_value_and_recompute_fees(desired_value_contribution);
33193320

@@ -3349,6 +3350,8 @@ where L::Target: Logger {
33493350
*used_liquidities.entry(CandidateHopId::Clear((scid, false))).or_default() = exhausted;
33503351
*used_liquidities.entry(CandidateHopId::Clear((scid, true))).or_default() = exhausted;
33513352
}
3353+
} else {
3354+
log_trace!(logger, "Path was limited to {}msat by hop {}", max_path_contribution_msat, lowest_value_contrib_hop);
33523355
}
33533356

33543357
// Track the total amount all our collected paths allow to send so that we know

0 commit comments

Comments
 (0)