Skip to content

Commit 1db53a9

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 543c5bf commit 1db53a9

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

lightning/src/routing/router.rs

+47-3
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,14 @@ impl<'a> fmt::Display for LoggedCandidateHop<'a> {
13331333
" and blinding point ".fmt(f)?;
13341334
hint.1.blinding_point.fmt(f)
13351335
},
1336+
CandidateRouteHop::FirstHop { .. } => {
1337+
"first hop with SCID ".fmt(f)?;
1338+
self.0.short_channel_id().unwrap().fmt(f)
1339+
},
1340+
CandidateRouteHop::PrivateHop { .. } => {
1341+
"route hint with SCID ".fmt(f)?;
1342+
self.0.short_channel_id().unwrap().fmt(f)
1343+
},
13361344
_ => {
13371345
"SCID ".fmt(f)?;
13381346
self.0.short_channel_id().unwrap().fmt(f)
@@ -1640,6 +1648,12 @@ where L::Target: Logger {
16401648
log_trace!(logger, "Building path from {} to payer {} for value {} msat.",
16411649
LoggedPayeePubkey(payment_params.payee.node_id()), our_node_pubkey, final_value_msat);
16421650

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

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

2363+
let num_ignored_total = num_ignored_value_contribution + num_ignored_path_length_limit +
2364+
num_ignored_cltv_delta_limit + num_ignored_previously_failed;
2365+
if num_ignored_total > 0 {
2366+
log_trace!(logger, "Ignored {} candidate hops due to insufficient value contribution, {} 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);
2367+
}
2368+
23252369
// Step (5).
23262370
if payment_paths.len() == 0 {
23272371
return Err(LightningError{err: "Failed to find a path to the given destination".to_owned(), action: ErrorAction::IgnoreError});

0 commit comments

Comments
 (0)