diff --git a/Code/common/src/validator_set.rs b/Code/common/src/validator_set.rs index 408b1517b..092ac4dc8 100644 --- a/Code/common/src/validator_set.rs +++ b/Code/common/src/validator_set.rs @@ -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) -> Option<&Ctx::Validator>; diff --git a/Code/test/src/validator_set.rs b/Code/test/src/validator_set.rs index 23b88a107..a5cd18e81 100644 --- a/Code/test/src/validator_set.rs +++ b/Code/test/src/validator_set.rs @@ -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] } } @@ -151,7 +153,7 @@ impl malachite_common::ValidatorSet for ValidatorSet { self.get_by_public_key(public_key) } - fn get_proposer(&self) -> Validator { + fn get_proposer(&self) -> &Validator { self.get_proposer() }