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