Skip to content

Commit 056d5da

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 056d5da

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Diff for: lightning/src/routing/router.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -2122,13 +2122,14 @@ impl<'a> PaymentPath<'a> {
21222122
value_msat + extra_contribution_msat
21232123
}
21242124

2125-
// Returns the maximum contribution that this path can make to the final value of the payment. May
2126-
// be slightly lower than the actual max due to rounding errors when aggregating fees along the
2127-
// path.
2128-
fn compute_max_final_value_contribution(
2125+
/// Returns the hop which most limited our maximum contribution as well as the maximum
2126+
/// contribution this path can make to the final value of the payment.
2127+
/// May be slightly lower than the actual max due to rounding errors when aggregating fees
2128+
/// along the path.
2129+
fn max_final_value_msat(
21292130
&self, used_liquidities: &HashMap<CandidateHopId, u64>, channel_saturation_pow_half: u8
2130-
) -> u64 {
2131-
let mut max_path_contribution = u64::MAX;
2131+
) -> (usize, u64) {
2132+
let mut max_path_contribution = (0, u64::MAX);
21322133
for (idx, (hop, _)) in self.hops.iter().enumerate() {
21332134
let hop_effective_capacity_msat = hop.candidate.effective_capacity();
21342135
let hop_max_msat = max_htlc_from_capacity(
@@ -2155,7 +2156,9 @@ impl<'a> PaymentPath<'a> {
21552156

21562157
if let Some(hop_contribution) = hop_max_final_value_contribution {
21572158
let hop_contribution: u64 = hop_contribution.try_into().unwrap_or(u64::MAX);
2158-
max_path_contribution = core::cmp::min(hop_contribution, max_path_contribution);
2159+
if hop_contribution <= max_path_contribution.1 {
2160+
max_path_contribution = (idx, hop_contribution);
2161+
}
21592162
} else { debug_assert!(false); }
21602163
}
21612164

@@ -3311,9 +3314,8 @@ where L::Target: Logger {
33113314
// recompute the fees again, so that if that's the case, we match the currently
33123315
// underpaid htlc_minimum_msat with fees.
33133316
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-
);
3317+
let (lowest_value_contrib_hop, max_path_contribution_msat) =
3318+
payment_path.max_final_value_msat(&used_liquidities, channel_saturation_pow_half);
33173319
let desired_value_contribution = cmp::min(max_path_contribution_msat, final_value_msat);
33183320
value_contribution_msat = payment_path.update_value_and_recompute_fees(desired_value_contribution);
33193321

@@ -3349,6 +3351,8 @@ where L::Target: Logger {
33493351
*used_liquidities.entry(CandidateHopId::Clear((scid, false))).or_default() = exhausted;
33503352
*used_liquidities.entry(CandidateHopId::Clear((scid, true))).or_default() = exhausted;
33513353
}
3354+
} else {
3355+
log_trace!(logger, "Path was limited to {}msat by hop {}", max_path_contribution_msat, lowest_value_contrib_hop);
33523356
}
33533357

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

0 commit comments

Comments
 (0)