Skip to content

Commit 7a801a3

Browse files
Get max HTLC from CandidateRouteHop instead of EffectiveCapacity
With the addition of blinded route hints, we can't assume that any provided route hint has enough capacity for the entire payment anymore. Blinded route hints provided a max_htlc_msat, so use that in routing.
1 parent 1d0e55e commit 7a801a3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lightning/src/routing/router.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -957,16 +957,23 @@ impl<'a> CandidateRouteHop<'a> {
957957
}
958958

959959
#[inline]
960-
fn max_htlc_from_capacity(capacity: EffectiveCapacity, max_channel_saturation_power_of_half: u8) -> u64 {
960+
fn max_htlc_from_route_candidate(candidate: &CandidateRouteHop, max_channel_saturation_power_of_half: u8) -> u64 {
961961
let saturation_shift: u32 = max_channel_saturation_power_of_half as u32;
962-
match capacity {
963-
EffectiveCapacity::ExactLiquidity { liquidity_msat } => liquidity_msat,
964-
EffectiveCapacity::Infinite => u64::max_value(),
965-
EffectiveCapacity::Unknown => EffectiveCapacity::Unknown.as_msat(),
966-
EffectiveCapacity::MaximumHTLC { amount_msat } =>
967-
amount_msat.checked_shr(saturation_shift).unwrap_or(0),
968-
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat } =>
969-
cmp::min(capacity_msat.checked_shr(saturation_shift).unwrap_or(0), htlc_maximum_msat),
962+
match candidate {
963+
CandidateRouteHop::FirstHop { details } => details.next_outbound_htlc_limit_msat,
964+
CandidateRouteHop::PublicHop { info, .. } => {
965+
match info.effective_capacity() {
966+
EffectiveCapacity::MaximumHTLC { amount_msat } =>
967+
amount_msat.checked_shr(saturation_shift).unwrap_or(0),
968+
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat } =>
969+
cmp::min(capacity_msat.checked_shr(saturation_shift).unwrap_or(0), htlc_maximum_msat),
970+
_ => {
971+
debug_assert!(false);
972+
EffectiveCapacity::Unknown.as_msat()
973+
}
974+
}
975+
},
976+
CandidateRouteHop::PrivateHop { hint } => hint.htlc_maximum_msat.unwrap_or(u64::max_value()),
970977
}
971978
}
972979

@@ -1479,7 +1486,7 @@ where L::Target: Logger {
14791486
if $src_node_id != $dest_node_id {
14801487
let short_channel_id = $candidate.short_channel_id();
14811488
let effective_capacity = $candidate.effective_capacity();
1482-
let htlc_maximum_msat = max_htlc_from_capacity(effective_capacity, channel_saturation_pow_half);
1489+
let htlc_maximum_msat = max_htlc_from_route_candidate(&$candidate, channel_saturation_pow_half);
14831490

14841491
// It is tricky to subtract $next_hops_fee_msat from available liquidity here.
14851492
// It may be misleading because we might later choose to reduce the value transferred
@@ -2023,8 +2030,7 @@ where L::Target: Logger {
20232030
.entry((hop.candidate.short_channel_id(), *prev_hop < hop.node_id))
20242031
.and_modify(|used_liquidity_msat| *used_liquidity_msat += spent_on_hop_msat)
20252032
.or_insert(spent_on_hop_msat);
2026-
let hop_capacity = hop.candidate.effective_capacity();
2027-
let hop_max_msat = max_htlc_from_capacity(hop_capacity, channel_saturation_pow_half);
2033+
let hop_max_msat = max_htlc_from_route_candidate(&hop.candidate, channel_saturation_pow_half);
20282034
if *used_liquidity_msat == hop_max_msat {
20292035
// If this path used all of this channel's available liquidity, we know
20302036
// this path will not be selected again in the next loop iteration.

0 commit comments

Comments
 (0)