Skip to content

Commit

Permalink
Sort channels by explicit balance in finding path
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jan 8, 2025
1 parent 2facf08 commit fb4691e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,24 @@ where
// the weight algorithm in find_path does not considering capacity,
// so the channel with larger capacity maybe have the same weight with the channel with smaller capacity
// so we sort by capacity reverse order to make sure we try channel with larger capacity firstly
channels.sort_by(|(_, _, a, _), (_, _, b, _)| {
b.capacity().cmp(&a.capacity()).then(
b.channel_last_update_time()
.cmp(&a.channel_last_update_time()),
)
});
channels.sort_by(
|(_, _, a_channel_info, a_channel_update_info),
(_, _, b_channel_info, b_channel_update_info)| {
b_channel_update_info
.receivable_balance
.cmp(&a_channel_update_info.receivable_balance)
.then(
b_channel_info
.capacity()
.cmp(&a_channel_info.capacity())
.then(
b_channel_info
.channel_last_update_time()
.cmp(&a_channel_info.channel_last_update_time()),
),
)
},
);
channels.into_iter()
}

Expand Down

0 comments on commit fb4691e

Please sign in to comment.