@@ -511,6 +511,10 @@ impl<'a> PaymentPath<'a> {
511
511
return result;
512
512
}
513
513
514
+ fn get_cost_msat ( & self ) -> u64 {
515
+ self . get_total_fee_paid_msat ( ) . saturating_add ( self . get_path_penalty_msat ( ) )
516
+ }
517
+
514
518
// If the amount transferred by the path is updated, the fees should be adjusted. Any other way
515
519
// to change fees may result in an inconsistency.
516
520
//
@@ -1502,9 +1506,8 @@ where L::Target: Logger {
1502
1506
// prefer lower cost paths.
1503
1507
cur_route. sort_unstable_by ( |a, b| {
1504
1508
a. get_value_msat ( ) . cmp ( & b. get_value_msat ( ) )
1505
- // Reverse ordering for fees, so we drop higher-fee paths first
1506
- . then_with ( || b. get_total_fee_paid_msat ( ) . saturating_add ( b. get_path_penalty_msat ( ) )
1507
- . cmp ( & a. get_total_fee_paid_msat ( ) . saturating_add ( a. get_path_penalty_msat ( ) ) ) )
1509
+ // Reverse ordering for cost, so we drop higher-cost paths first
1510
+ . then_with ( || b. get_cost_msat ( ) . cmp ( & a. get_cost_msat ( ) ) )
1508
1511
} ) ;
1509
1512
1510
1513
// We should make sure that at least 1 path left.
@@ -1548,8 +1551,8 @@ where L::Target: Logger {
1548
1551
}
1549
1552
1550
1553
// Step (9).
1551
- // Select the best route by lowest total fee .
1552
- drawn_routes. sort_unstable_by_key ( |paths| paths. iter ( ) . map ( |path| path. get_total_fee_paid_msat ( ) ) . sum :: < u64 > ( ) ) ;
1554
+ // Select the best route by lowest total cost .
1555
+ drawn_routes. sort_unstable_by_key ( |paths| paths. iter ( ) . map ( |path| path. get_cost_msat ( ) ) . sum :: < u64 > ( ) ) ;
1553
1556
let mut selected_paths = Vec :: < Vec < Result < RouteHop , LightningError > > > :: new ( ) ;
1554
1557
for payment_path in drawn_routes. first ( ) . unwrap ( ) {
1555
1558
let mut path = payment_path. hops . iter ( ) . map ( |( payment_hop, node_features) | {
0 commit comments