-
Notifications
You must be signed in to change notification settings - Fork 103
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
Conversation
hotshot-types/src/traits/election.rs
Outdated
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 = { |
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.
Should we use this instead?
https://docs.rs/primitive-types/latest/primitive_types/struct.U256.html#impl-TryFrom%3CU512%3E-for-U256
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.
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.
hotshot-types/src/traits/election.rs
Outdated
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 { |
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.
shouldn't this be a method of stake table struct or trait, something like StakeTable.next_leader()
?
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.
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
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.
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!
This PR:
Adds variable stake and randomized leader selection
This PR does not:
Key places to review: