@@ -951,7 +951,10 @@ impl<'a> CandidateRouteHop<'a> {
951
951
liquidity_msat : details. next_outbound_htlc_limit_msat ,
952
952
} ,
953
953
CandidateRouteHop :: PublicHop { info, .. } => info. effective_capacity ( ) ,
954
- CandidateRouteHop :: PrivateHop { .. } => EffectiveCapacity :: Infinite ,
954
+ CandidateRouteHop :: PrivateHop { hint } => {
955
+ hint. htlc_maximum_msat . map_or ( EffectiveCapacity :: Infinite ,
956
+ |max| EffectiveCapacity :: HintMaxHTLC { amount_msat : max } )
957
+ } ,
955
958
}
956
959
}
957
960
}
@@ -965,6 +968,7 @@ fn max_htlc_from_capacity(capacity: EffectiveCapacity, max_channel_saturation_po
965
968
EffectiveCapacity :: Unknown => EffectiveCapacity :: Unknown . as_msat ( ) ,
966
969
EffectiveCapacity :: AdvertisedMaxHTLC { amount_msat } =>
967
970
amount_msat. checked_shr ( saturation_shift) . unwrap_or ( 0 ) ,
971
+ EffectiveCapacity :: HintMaxHTLC { amount_msat } => amount_msat,
968
972
EffectiveCapacity :: Total { capacity_msat, htlc_maximum_msat } =>
969
973
cmp:: min ( capacity_msat. checked_shr ( saturation_shift) . unwrap_or ( 0 ) , htlc_maximum_msat) ,
970
974
}
@@ -5906,6 +5910,57 @@ mod tests {
5906
5910
assert ! ( route. is_ok( ) ) ;
5907
5911
}
5908
5912
5913
+ #[ test]
5914
+ fn respect_route_hint_max_htlc ( ) {
5915
+ // Make sure that any max_htlc provided in the route hints of the payment params is respected in
5916
+ // the final route.
5917
+ let ( secp_ctx, network_graph, _, _, logger) = build_graph ( ) ;
5918
+ let netgraph = network_graph. read_only ( ) ;
5919
+ let ( _, our_id, _, nodes) = get_nodes ( & secp_ctx) ;
5920
+ let scorer = ln_test_utils:: TestScorer :: new ( ) ;
5921
+ let keys_manager = ln_test_utils:: TestKeysInterface :: new ( & [ 0u8 ; 32 ] , Network :: Testnet ) ;
5922
+ let random_seed_bytes = keys_manager. get_secure_random_bytes ( ) ;
5923
+ let config = UserConfig :: default ( ) ;
5924
+
5925
+ let max_htlc_msat = 50_000 ;
5926
+ let route_hint_1 = RouteHint ( vec ! [ RouteHintHop {
5927
+ src_node_id: nodes[ 2 ] ,
5928
+ short_channel_id: 42 ,
5929
+ fees: RoutingFees {
5930
+ base_msat: 100 ,
5931
+ proportional_millionths: 0 ,
5932
+ } ,
5933
+ cltv_expiry_delta: 10 ,
5934
+ htlc_minimum_msat: None ,
5935
+ htlc_maximum_msat: Some ( max_htlc_msat) ,
5936
+ } ] ) ;
5937
+ let dest_node_id = ln_test_utils:: pubkey ( 42 ) ;
5938
+ let payment_params = PaymentParameters :: from_node_id ( dest_node_id, 42 )
5939
+ . with_route_hints ( vec ! [ route_hint_1. clone( ) ] ) . unwrap ( )
5940
+ . with_bolt11_features ( channelmanager:: provided_invoice_features ( & config) ) . unwrap ( ) ;
5941
+
5942
+ // Make sure we'll error if our route hints don't have enough liquidity according to their
5943
+ // max_htlc.
5944
+ if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route ( & our_id,
5945
+ & payment_params, & netgraph, None , max_htlc_msat + 1 , Arc :: clone ( & logger) , & scorer, & ( ) ,
5946
+ & random_seed_bytes)
5947
+ {
5948
+ assert_eq ! ( err, "Failed to find a sufficient route to the given destination" ) ;
5949
+ } else { panic ! ( ) ; }
5950
+
5951
+ // Make sure we'll split an MPP payment across route hints if their max_htlcs warrant it.
5952
+ let mut route_hint_2 = route_hint_1. clone ( ) ;
5953
+ route_hint_2. 0 [ 0 ] . short_channel_id = 43 ;
5954
+ let payment_params = PaymentParameters :: from_node_id ( dest_node_id, 42 )
5955
+ . with_route_hints ( vec ! [ route_hint_1, route_hint_2] ) . unwrap ( )
5956
+ . with_bolt11_features ( channelmanager:: provided_invoice_features ( & config) ) . unwrap ( ) ;
5957
+ let route = get_route ( & our_id, & payment_params, & netgraph, None , max_htlc_msat + 1 ,
5958
+ Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) . unwrap ( ) ;
5959
+ assert_eq ! ( route. paths. len( ) , 2 ) ;
5960
+ assert ! ( route. paths[ 0 ] . hops. last( ) . unwrap( ) . fee_msat <= max_htlc_msat) ;
5961
+ assert ! ( route. paths[ 1 ] . hops. last( ) . unwrap( ) . fee_msat <= max_htlc_msat) ;
5962
+ }
5963
+
5909
5964
#[ test]
5910
5965
fn blinded_route_ser ( ) {
5911
5966
let blinded_path_1 = BlindedPath {
0 commit comments