Skip to content

Commit

Permalink
Improve ValidatorSet::get_proposer
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 3, 2023
1 parent 10677dc commit 5cdc87c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Code/common/src/validator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
fn total_voting_power(&self) -> VotingPower;

/// The proposer in the validator set.
fn get_proposer(&self) -> Ctx::Validator;
fn get_proposer(&self) -> &Ctx::Validator;

/// Get the validator with the given public key.
fn get_by_public_key(&self, public_key: &PublicKey<Ctx>) -> Option<&Ctx::Validator>;
Expand Down
10 changes: 6 additions & 4 deletions Code/test/src/validator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ impl ValidatorSet {
vals.dedup();
}

pub fn get_proposer(&self) -> Validator {
pub fn get_proposer(&self) -> &Validator {
// TODO: Proper implementation
assert!(!self.validators.is_empty());
let proposer = self.validators[self.proposer.load(Ordering::Relaxed)].clone();

let idx = self.proposer.load(Ordering::Relaxed) % self.validators.len();
self.proposer.fetch_add(1, Ordering::Relaxed);
proposer

&self.validators[idx]
}
}

Expand All @@ -151,7 +153,7 @@ impl malachite_common::ValidatorSet<TestContext> for ValidatorSet {
self.get_by_public_key(public_key)
}

fn get_proposer(&self) -> Validator {
fn get_proposer(&self) -> &Validator {
self.get_proposer()
}

Expand Down

0 comments on commit 5cdc87c

Please sign in to comment.