refactor: leader schedule generation#4662
Merged
Merged
Conversation
6681859 to
d2e5ead
Compare
778b92c to
568c040
Compare
568c040 to
d19fad1
Compare
AshwinSekar
approved these changes
Feb 5, 2025
| // deterministic result. | ||
| // Note: Use unstable sort, because we dedup right after to remove the equal elements. | ||
| stakes.sort_unstable_by(|(l_pubkey, l_stake), (r_pubkey, r_stake)| { | ||
| if r_stake == l_stake { |
There was a problem hiding this comment.
nit: you could compare the tuples directly:
(r_stake, r_pubkey).cmp(&(l_stake, l_pubkey))
Author
There was a problem hiding this comment.
This PR just moves this sort_stakes function from another file, I'm fine with leaving it as is
|
|
||
| // Note: passing in zero stakers will cause a panic. | ||
| fn stake_weighted_slot_leaders( | ||
| mut keyed_stakes: Vec<(&Pubkey, u64)>, |
There was a problem hiding this comment.
nit: you could avoid the intermediate collection here by taking in an iter (flipped) Iterator<Item = (u64, &Pubkey)> and using the iter variants in sort_stakes:
stakes.sorted_unstable().dedup().reverse()
Author
There was a problem hiding this comment.
IterTools often allocates internally in its helper methods FYI:
fn sorted_unstable(..) {
let mut v = Vec::from_iter(self);
v.sort_unstable();
v.into_iter()
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Need to do a little refactoring before modifying the leader schedule in a follow up change (#4597)
Summary of Changes
Refactored leader schedule generation code so that parts can be shared with the new vote account keyed leader schedule algorithm
Fixes #