Skip to content

Commit 8ca8d88

Browse files
committed
Use cached sort when iterating over path.
1 parent 84fa714 commit 8ca8d88

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lightning/src/routing/router.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ where L::Target: Logger {
14421442
}
14431443

14441444
// Sort by total fees and take the best paths.
1445-
payment_paths.sort_by_key(|path| path.get_total_fee_paid_msat());
1445+
payment_paths.sort_by_cached_key(|path| path.get_total_fee_paid_msat());
14461446
if payment_paths.len() > 50 {
14471447
payment_paths.truncate(50);
14481448
}
@@ -1522,7 +1522,7 @@ where L::Target: Logger {
15221522
// Now, subtract the overpaid value from the most-expensive path.
15231523
// TODO: this could also be optimized by also sorting by feerate_per_sat_routed,
15241524
// so that the sender pays less fees overall. And also htlc_minimum_msat.
1525-
cur_route.sort_by_key(|path| { path.hops.iter().map(|hop| hop.0.candidate.fees().proportional_millionths as u64).sum::<u64>() });
1525+
cur_route.sort_by_cached_key(|path| { path.hops.iter().map(|hop| hop.0.candidate.fees().proportional_millionths as u64).sum::<u64>() });
15261526
let expensive_payment_path = cur_route.first_mut().unwrap();
15271527

15281528
// We already dropped all the small value paths above, meaning all the
@@ -1538,7 +1538,7 @@ where L::Target: Logger {
15381538

15391539
// Step (9).
15401540
// Select the best route by lowest total fee.
1541-
drawn_routes.sort_by_key(|paths| paths.iter().map(|path| path.get_total_fee_paid_msat()).sum::<u64>());
1541+
drawn_routes.sort_by_cached_key(|paths| paths.iter().map(|path| path.get_total_fee_paid_msat()).sum::<u64>());
15421542
let mut selected_paths = Vec::<Vec<Result<RouteHop, LightningError>>>::new();
15431543
for payment_path in drawn_routes.first().unwrap() {
15441544
let mut path = payment_path.hops.iter().map(|(payment_hop, node_features)| {

0 commit comments

Comments
 (0)