@@ -2628,21 +2628,22 @@ where L::Target: Logger {
2628
2628
// Make sure we would never create a route with more paths than we allow.
2629
2629
debug_assert ! ( paths. len( ) <= payment_params. max_path_count. into( ) ) ;
2630
2630
2631
- // Make sure we would never create a route whose total fees exceed max_total_routing_fee_msat.
2632
- if let Some ( max_total_routing_fee_msat) = route_params. max_total_routing_fee_msat {
2633
- if paths. iter ( ) . map ( |p| p. fee_msat ( ) ) . sum :: < u64 > ( ) > max_total_routing_fee_msat {
2634
- return Err ( LightningError { err : format ! ( "Failed to find route that adheres to the maximum total fee limit of {}msat" ,
2635
- max_total_routing_fee_msat) , action : ErrorAction :: IgnoreError } ) ;
2636
- }
2637
- }
2638
-
2639
2631
if let Some ( node_features) = payment_params. payee . node_features ( ) {
2640
2632
for path in paths. iter_mut ( ) {
2641
2633
path. hops . last_mut ( ) . unwrap ( ) . node_features = node_features. clone ( ) ;
2642
2634
}
2643
2635
}
2644
2636
2645
2637
let route = Route { paths, route_params : Some ( route_params. clone ( ) ) } ;
2638
+
2639
+ // Make sure we would never create a route whose total fees exceed max_total_routing_fee_msat.
2640
+ if let Some ( max_total_routing_fee_msat) = route_params. max_total_routing_fee_msat {
2641
+ if route. get_total_fees ( ) > max_total_routing_fee_msat {
2642
+ return Err ( LightningError { err : format ! ( "Failed to find route that adheres to the maximum total fee limit of {}msat" ,
2643
+ max_total_routing_fee_msat) , action : ErrorAction :: IgnoreError } ) ;
2644
+ }
2645
+ }
2646
+
2646
2647
log_info ! ( logger, "Got route: {}" , log_route!( route) ) ;
2647
2648
Ok ( route)
2648
2649
}
@@ -3266,11 +3267,22 @@ mod tests {
3266
3267
excess_data : Vec :: new ( )
3267
3268
} ) ;
3268
3269
3269
- // Now check that we'll find a path if the htlc_minimum is overrun substantially.
3270
+ // Now check that we'll fail to find a path if we fail to find a path if the htlc_minimum
3271
+ // is overrun. Note that the fees are actually calculated on 3*payment amount as that's
3272
+ // what we try to find a route for, so this test only just happens to work out to exactly
3273
+ // the fee limit.
3270
3274
let mut route_params = RouteParameters :: from_payment_params_and_value (
3271
3275
payment_params. clone ( ) , 5_000 ) ;
3272
- // TODO: This can even overrun the fee limit set by the recipient!
3273
3276
route_params. max_total_routing_fee_msat = Some ( 9_999 ) ;
3277
+ if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route ( & our_id,
3278
+ & route_params, & network_graph. read_only ( ) , None , Arc :: clone ( & logger) , & scorer,
3279
+ & Default :: default ( ) , & random_seed_bytes) {
3280
+ assert_eq ! ( err, "Failed to find route that adheres to the maximum total fee limit of 9999msat" ) ;
3281
+ } else { panic ! ( ) ; }
3282
+
3283
+ let mut route_params = RouteParameters :: from_payment_params_and_value (
3284
+ payment_params. clone ( ) , 5_000 ) ;
3285
+ route_params. max_total_routing_fee_msat = Some ( 10_000 ) ;
3274
3286
let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
3275
3287
Arc :: clone ( & logger) , & scorer, & Default :: default ( ) , & random_seed_bytes) . unwrap ( ) ;
3276
3288
assert_eq ! ( route. get_total_fees( ) , 10_000 ) ;
0 commit comments