Skip to content

Commit 36af946

Browse files
committed
Improve logging for ignored candiate hops
Previously, we barely gave any hints why we excluded certain hops during pathfinding. Here, we introduce more verbose logging by a) accounting how much candidates we ignored for which reasons and b) logging any first/last/blinded hops we end up ignoring. Fixes #1646.
1 parent dbb9ea3 commit 36af946

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

lightning/src/routing/router.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,14 @@ impl<'a> fmt::Display for LoggedCandidateHop<'a> {
13271327
" and blinding point ".fmt(f)?;
13281328
hint.1.blinding_point.fmt(f)
13291329
},
1330+
CandidateRouteHop::FirstHop { .. } => {
1331+
"first hop with SCID ".fmt(f)?;
1332+
self.0.short_channel_id().unwrap().fmt(f)
1333+
},
1334+
CandidateRouteHop::PrivateHop { .. } => {
1335+
"route hint with SCID ".fmt(f)?;
1336+
self.0.short_channel_id().unwrap().fmt(f)
1337+
},
13301338
_ => {
13311339
"SCID ".fmt(f)?;
13321340
self.0.short_channel_id().unwrap().fmt(f)
@@ -1638,6 +1646,12 @@ where L::Target: Logger {
16381646
log_trace!(logger, "Building path from {} to payer {} for value {} msat.",
16391647
LoggedPayeePubkey(payment_params.payee.node_id()), our_node_pubkey, final_value_msat);
16401648

1649+
// Remember how many candidates we ignored to allow for some logging afterwards.
1650+
let mut num_ignored_value_contribution = 0;
1651+
let mut num_ignored_path_length_limit = 0;
1652+
let mut num_ignored_cltv_delta_limit = 0;
1653+
let mut num_ignored_previously_failed = 0;
1654+
16411655
macro_rules! add_entry {
16421656
// Adds entry which goes from $src_node_id to $dest_node_id over the $candidate hop.
16431657
// $next_hops_fee_msat represents the fees paid for using all the channels *after* this one,
@@ -1712,13 +1726,37 @@ where L::Target: Logger {
17121726
let payment_failed_on_this_channel = scid_opt.map_or(false,
17131727
|scid| payment_params.previously_failed_channels.contains(&scid));
17141728

1729+
let should_log_candidate = match $candidate {
1730+
CandidateRouteHop::FirstHop { .. } => true,
1731+
CandidateRouteHop::PrivateHop { .. } => true,
1732+
CandidateRouteHop::Blinded { .. } => true,
1733+
_ => false,
1734+
};
1735+
17151736
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn't
17161737
// bother considering this channel. If retrying with recommended_value_msat may
17171738
// allow us to hit the HTLC minimum limit, set htlc_minimum_limit so that we go
17181739
// around again with a higher amount.
1719-
if !contributes_sufficient_value || exceeds_max_path_length ||
1720-
exceeds_cltv_delta_limit || payment_failed_on_this_channel {
1721-
// Path isn't useful, ignore it and move on.
1740+
if !contributes_sufficient_value {
1741+
if should_log_candidate {
1742+
log_trace!(logger, "Ignoring {} due to insufficient value contribution.", LoggedCandidateHop(&$candidate));
1743+
}
1744+
num_ignored_value_contribution += 1;
1745+
} else if exceeds_max_path_length {
1746+
if should_log_candidate {
1747+
log_trace!(logger, "Ignoring {} due to exceeding max. path length limit.", LoggedCandidateHop(&$candidate));
1748+
}
1749+
num_ignored_path_length_limit += 1;
1750+
} else if exceeds_cltv_delta_limit {
1751+
if should_log_candidate {
1752+
log_trace!(logger, "Ignoring {} due to exceeding CLTV delta limit.", LoggedCandidateHop(&$candidate));
1753+
}
1754+
num_ignored_cltv_delta_limit += 1;
1755+
} else if payment_failed_on_this_channel {
1756+
if should_log_candidate {
1757+
log_trace!(logger, "Ignoring {} due to a failed previous payment attempt.", LoggedCandidateHop(&$candidate));
1758+
}
1759+
num_ignored_previously_failed += 1;
17221760
} else if may_overpay_to_meet_path_minimum_msat {
17231761
hit_minimum_limit = true;
17241762
} else if over_path_minimum_msat {
@@ -2320,6 +2358,12 @@ where L::Target: Logger {
23202358
}
23212359
}
23222360

2361+
let num_ignored_total = num_ignored_value_contribution + num_ignored_path_length_limit +
2362+
num_ignored_cltv_delta_limit + num_ignored_previously_failed;
2363+
if num_ignored_total > 0 {
2364+
log_trace!(logger, "Ignored {} candidate hops due to insufficient value contrib., {} due to path length limit, {} due to CLTV delta limit, {} due to previous payment failure. Total: {} ignored candidates.", num_ignored_value_contribution, num_ignored_path_length_limit, num_ignored_cltv_delta_limit, num_ignored_previously_failed, num_ignored_total);
2365+
}
2366+
23232367
// Step (5).
23242368
if payment_paths.len() == 0 {
23252369
return Err(LightningError{err: "Failed to find a path to the given destination".to_owned(), action: ErrorAction::IgnoreError});

0 commit comments

Comments
 (0)