Skip to content

Commit d4c6b10

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 acfc0bf commit d4c6b10

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,21 @@ 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
920927
// bother considering this channel.
921928
// Since we're choosing amount_to_transfer_over_msat as maximum possible, it can
922929
// be only reduced later (not increased), so this channel should just be skipped
923930
// as not sufficient.
924-
if !over_path_minimum_msat && doesnt_exceed_cltv_delta_limit {
931+
if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit && may_overpay_to_meet_path_minimum_msat {
925932
hit_minimum_limit = true;
926-
} else if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit {
933+
} else if contributes_sufficient_value && doesnt_exceed_cltv_delta_limit && over_path_minimum_msat {
927934
// Note that low contribution here (limited by available_liquidity_msat)
928935
// might violate htlc_minimum_msat on the hops which are next along the
929936
// payment path (upstream to the payee). To avoid that, we recompute

0 commit comments

Comments
 (0)