This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Ensure stakes are always sorted before generating a leader_schedule #3016
Closed
Conversation
This file contains 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
Codecov Report
@@ Coverage Diff @@
## master #3016 +/- ##
========================================
+ Coverage 76.9% 76.9% +<.1%
========================================
Files 130 130
Lines 19888 19917 +29
========================================
+ Hits 15294 15319 +25
- Misses 4594 4598 +4 |
garious
suggested changes
Feb 28, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see this fixed, but hurts to see an attempt to bring back code from earlier this week without its unit-tests. The original code was commented as well...
fn sort_stakes(stakes: &mut Vec<(Pubkey, u64)>) {
// Sort first by stake. If stakes are the same, sort by pubkey to ensure a
// deterministic result.
// Note: Use unstable sort, because we dedup right after to remove the equal elements.
stakes.sort_unstable_by(|(pubkey0, stake0), (pubkey1, stake1)| {
if stake0 == stake1 {
pubkey0.cmp(&pubkey1)
} else {
stake0.cmp(&stake1)
}
});
// Now that it's sorted, we can do an O(n) dedup.
stakes.dedup();
}
#[test]
fn test_sort_stakes_basic() {
let pubkey0 = Keypair::new().pubkey();
let pubkey1 = Keypair::new().pubkey();
let mut stakes = vec![(pubkey0, 2), (pubkey1, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 1), (pubkey0, 2)]);
}
#[test]
fn test_sort_stakes_with_dup() {
let pubkey0 = Keypair::new().pubkey();
let pubkey1 = Keypair::new().pubkey();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 2), (pubkey0, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey0, 1), (pubkey1, 2)]);
}
#[test]
fn test_sort_stakes_with_equal_stakes() {
let pubkey0 = Pubkey::default();
let pubkey1 = Keypair::new().pubkey();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey0, 1), (pubkey1, 1)]);
}
}
sagar-solana
force-pushed
the
sort_stakes
branch
from
March 1, 2019 00:12
f197927
to
c8a7442
Compare
@garious, sorry about that, it was a hotfix pr for something Rob needed :( |
Everything in this PR was already included in #2992 |
behzadnouri
added a commit
to behzadnouri/solana
that referenced
this pull request
Sep 30, 2024
max_bytes for outgoing push messages is pretty outdated and does not allow gossip to function properly with current testnet cluster size. In particular it does not allow to clear out queue of pending push messages unless the new_push_messages function is called very frequently which involves repeatedly locking/unlocking CRDS table. Additionally leaving gossip entries in the queue for the next round will add delay to propagating push messages which can compound as messages go through several hops.
yihau
pushed a commit
to yihau/solana
that referenced
this pull request
Oct 2, 2024
…a-labs#3016) (solana-labs#3038) reworks max number of outgoing push messages (solana-labs#3016) max_bytes for outgoing push messages is pretty outdated and does not allow gossip to function properly with current testnet cluster size. In particular it does not allow to clear out queue of pending push messages unless the new_push_messages function is called very frequently which involves repeatedly locking/unlocking CRDS table. Additionally leaving gossip entries in the queue for the next round will add delay to propagating push messages which can compound as messages go through several hops. (cherry picked from commit 489f483) Co-authored-by: behzad nouri <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Stakes need to be sorted, otherwise leader schedule becomes non-deterministic based on when stakes were first added to accounts.
Summary of Changes
Sort stakes before generating a leader schedule.