@@ -2122,16 +2122,19 @@ impl<'a> PaymentPath<'a> {
21222122 return result;
21232123 }
21242124
2125- fn get_cost ( & self ) -> u128 {
2126- let fee_cost = self . get_fee_cost_msat ( ) ;
2125+ /// Gets the cost (fees plus scorer penalty in msats) of the path divided by the value we
2126+ /// can/will send over the path. This is also the heap score during our Dijkstra's walk.
2127+ fn get_cost_per_msat ( & self ) -> u128 {
2128+ let fee_cost = self . get_cost_msat ( ) ;
21272129 if fee_cost == u64:: MAX {
21282130 u64:: MAX . into ( )
21292131 } else {
21302132 ( ( fee_cost as u128 ) << 64 ) / self . get_value_msat ( ) as u128
21312133 }
21322134 }
21332135
2134- fn get_fee_cost_msat ( & self ) -> u64 {
2136+ /// Gets the fees plus scorer penalty in msats of the path.
2137+ fn get_cost_msat ( & self ) -> u64 {
21352138 self . get_total_fee_paid_msat ( ) . saturating_add ( self . get_path_penalty_msat ( ) )
21362139 }
21372140
@@ -3574,7 +3577,7 @@ where L::Target: Logger {
35743577 // First, sort by the cost-per-value of the path, dropping the paths that cost the most for
35753578 // the value they contribute towards the payment amount.
35763579 // We sort in descending order as we will remove from the front in `retain`, next.
3577- selected_route. sort_unstable_by ( |a, b| b. get_cost ( ) . cmp ( & a. get_cost ( ) ) ) ;
3580+ selected_route. sort_unstable_by ( |a, b| b. get_cost_per_msat ( ) . cmp ( & a. get_cost_per_msat ( ) ) ) ;
35783581
35793582 // We should make sure that at least 1 path left.
35803583 let mut paths_left = selected_route. len ( ) ;
@@ -3600,7 +3603,7 @@ where L::Target: Logger {
36003603 selected_route. sort_unstable_by ( |a, b| {
36013604 let a_f = a. hops . iter ( ) . map ( |hop| hop. 0 . candidate . fees ( ) . proportional_millionths as u64 ) . sum :: < u64 > ( ) ;
36023605 let b_f = b. hops . iter ( ) . map ( |hop| hop. 0 . candidate . fees ( ) . proportional_millionths as u64 ) . sum :: < u64 > ( ) ;
3603- a_f. cmp ( & b_f) . then_with ( || b. get_fee_cost_msat ( ) . cmp ( & a. get_fee_cost_msat ( ) ) )
3606+ a_f. cmp ( & b_f) . then_with ( || b. get_cost_msat ( ) . cmp ( & a. get_cost_msat ( ) ) )
36043607 } ) ;
36053608 let expensive_payment_path = selected_route. first_mut ( ) . unwrap ( ) ;
36063609
0 commit comments