Skip to content

Commit acfc0bf

Browse files
committed
Select best route by lowest total cost
Selecting only by fees rather than cost (fees plus penalty) may result in preferring higher cost routes over lower cost ones.
1 parent 30b6873 commit acfc0bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ impl<'a> PaymentPath<'a> {
511511
return result;
512512
}
513513

514+
fn get_cost_msat(&self) -> u64 {
515+
self.get_total_fee_paid_msat().saturating_add(self.get_path_penalty_msat())
516+
}
517+
514518
// If the amount transferred by the path is updated, the fees should be adjusted. Any other way
515519
// to change fees may result in an inconsistency.
516520
//
@@ -1548,8 +1552,8 @@ where L::Target: Logger {
15481552
}
15491553

15501554
// 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>());
1555+
// Select the best route by lowest total cost.
1556+
drawn_routes.sort_unstable_by_key(|paths| paths.iter().map(|path| path.get_cost_msat()).sum::<u64>());
15531557
let mut selected_paths = Vec::<Vec<Result<RouteHop, LightningError>>>::new();
15541558
for payment_path in drawn_routes.first().unwrap() {
15551559
let mut path = payment_path.hops.iter().map(|(payment_hop, node_features)| {

0 commit comments

Comments
 (0)