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

Randomize leader election #3693

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/hotshot/src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use hotshot_types::{
},
PeerConfig,
};
#[cfg(feature = "randomized-leader-election")]
use rand::{rngs::StdRng, Rng};

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -136,9 +135,14 @@ impl<TYPES: NodeType> Membership<TYPES> for GeneralStaticCommittee<TYPES> {
)))]
/// Index the vector of public keys with the current view number
fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey {
let index = usize::try_from(*view_number % self.eligible_leaders.len() as u64).unwrap();
let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number);
let randomized_view_number: usize = rng.gen();
let index = randomized_view_number % self.eligible_leaders.len();
let res = self.eligible_leaders[index].clone();
TYPES::SignatureKey::public_key(&res)
// let index = *view_number as usize % self.eligible_leaders.len();
// let res = self.eligible_leaders[index].clone();
// TYPES::SignatureKey::public_key(&res)
}

#[cfg(feature = "fixed-leader-election")]
Expand All @@ -150,7 +154,7 @@ impl<TYPES: NodeType> Membership<TYPES> for GeneralStaticCommittee<TYPES> {
{
panic!("fixed_leader_for_gpuvid is not set correctly.");
}
let index = usize::try_from(*view_number % self.fixed_leader_for_gpuvid as u64).unwrap();
let index = *view_number as usize % self.fixed_leader_for_gpuvid;
let res = self.eligible_leaders[index].clone();
TYPES::SignatureKey::public_key(&res)
}
Expand Down
Loading