@@ -957,16 +957,23 @@ impl<'a> CandidateRouteHop<'a> {
957
957
}
958
958
959
959
#[ 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 {
961
961
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 ( ) ) ,
970
977
}
971
978
}
972
979
@@ -1479,7 +1486,7 @@ where L::Target: Logger {
1479
1486
if $src_node_id != $dest_node_id {
1480
1487
let short_channel_id = $candidate. short_channel_id( ) ;
1481
1488
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) ;
1483
1490
1484
1491
// It is tricky to subtract $next_hops_fee_msat from available liquidity here.
1485
1492
// It may be misleading because we might later choose to reduce the value transferred
@@ -2023,8 +2030,7 @@ where L::Target: Logger {
2023
2030
. entry ( ( hop. candidate . short_channel_id ( ) , * prev_hop < hop. node_id ) )
2024
2031
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += spent_on_hop_msat)
2025
2032
. 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) ;
2028
2034
if * used_liquidity_msat == hop_max_msat {
2029
2035
// If this path used all of this channel's available liquidity, we know
2030
2036
// this path will not be selected again in the next loop iteration.
0 commit comments