Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable stake and randomized leader selection #2638

Merged
merged 9 commits into from
Feb 24, 2025
Merged

Conversation

ss-es
Copy link
Contributor

@ss-es ss-es commented Feb 18, 2025

This PR:

Adds variable stake and randomized leader selection

This PR does not:

Key places to review:

U512::from_little_endian(&raw_breakpoint) % U512::from(cdf.last().unwrap().1);

// and drop the top 32 bytes, downcasting to a U256
let breakpoint: U256 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks correct.
Do you mind adding what you posted on Zulip about the design in the code doc? (even though the code itself is self-explanatory, sometimes reading natural language in code doc is nice.

Comment on lines 206 to 211
pub fn select_randomized_leader<SignatureKey, Entry: StakeTableEntryType<SignatureKey> + Clone>(
cdf: Vec<(Entry, U256)>,
stake_table_hash: [u8; 32],
drb: [u8; 32],
view: u64,
) -> Entry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a method of stake table struct or trait, something like StakeTable.next_leader() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will be! I wanted to separate the raw logic into its own function, but the trait that handles the stake table will implement leader selection by calling this.

we just have multiple implementations that may or may not use this leader selection for tests etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up just creating a wrapper type for all the DRB-related information we want to store between views, and the implementation now uses this opaquely!

@ss-es ss-es marked this pull request as ready for review February 24, 2025 17:59
@ss-es ss-es merged commit 36d8702 into main Feb 24, 2025
52 checks passed
@ss-es ss-es deleted the ss/variable-stake branch February 24, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants