Skip to content

Commit 8ddfe66

Browse files
TheBlueMattjkczyz
authored andcommitted
Don't consider a path as having hit HTLC-min if it isn't sufficient
During the first pass of path finding, we seek a single path with the exact payment amount, and only seek additional paths if (a) no single path can carry the entire balance of the payment or (b) we found a good path, but along the way we found candidate paths with the potential to result in a lower total fee. This commit fixes the behavior of (b) -- we were previously considering some paths to be candidates for a lower fee when in fact they never would have worked. This caused us to re-run Dijkstra's when it might not have been beneficial.
1 parent f9cdf93 commit 8ddfe66

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lightning/src/routing/router.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,20 @@ where L::Target: Logger {
916916
let over_path_minimum_msat = amount_to_transfer_over_msat >= $candidate.htlc_minimum_msat() &&
917917
amount_to_transfer_over_msat >= $next_hops_path_htlc_minimum_msat;
918918

919+
#[allow(unused_comparisons)] // $next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains
920+
let may_overpay_to_meet_path_minimum_msat =
921+
((amount_to_transfer_over_msat < $candidate.htlc_minimum_msat() &&
922+
recommended_value_msat > $candidate.htlc_minimum_msat()) ||
923+
(amount_to_transfer_over_msat < $next_hops_path_htlc_minimum_msat &&
924+
recommended_value_msat > $next_hops_path_htlc_minimum_msat));
925+
919926
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn't
920-
// bother considering this channel.
921-
// Since we're choosing amount_to_transfer_over_msat as maximum possible, it can
922-
// be only reduced later (not increased), so this channel should just be skipped
923-
// as not sufficient.
924-
if !over_path_minimum_msat && doesnt_exceed_cltv_delta_limit {
927+
// bother considering this channel. If retrying with recommended_value_msat may
928+
// allow us to hit the HTLC minimum limit, set htlc_minimum_limit so that we go
929+
// around again with a higher amount.
930+
if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit && may_overpay_to_meet_path_minimum_msat {
925931
hit_minimum_limit = true;
926-
} else if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit {
932+
} else if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit && over_path_minimum_msat {
927933
// Note that low contribution here (limited by available_liquidity_msat)
928934
// might violate htlc_minimum_msat on the hops which are next along the
929935
// payment path (upstream to the payee). To avoid that, we recompute

0 commit comments

Comments
 (0)