Skip to content

Commit 5a6378b

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 f673427 commit 5a6378b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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(
@@ -2154,7 +2155,9 @@ impl<'a> PaymentPath<'a> {
21542155

21552156
if let Some(hop_contribution) = hop_max_final_value_contribution {
21562157
let hop_contribution: u64 = hop_contribution.try_into().unwrap_or(u64::MAX);
2157-
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+
}
21582161
} else { debug_assert!(false); }
21592162
}
21602163

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

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

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

0 commit comments

Comments
 (0)