Skip to content

Commit

Permalink
Add height to ProposerSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 22, 2024
1 parent 378c152 commit 363b6f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
10 changes: 7 additions & 3 deletions code/driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ where
}

/// Return the proposer for the current round.
pub fn get_proposer(&self, round: Round) -> Result<&Ctx::Validator, Error<Ctx>> {
pub fn get_proposer(
&self,
height: Ctx::Height,
round: Round,
) -> Result<&Ctx::Validator, Error<Ctx>> {
let address = self
.proposer_selector
.select_proposer(round, &self.validator_set);
.select_proposer(height, round, &self.validator_set);

let proposer = self
.validator_set
Expand Down Expand Up @@ -267,7 +271,7 @@ where
let round_state = core::mem::take(&mut self.round_state);
let current_step = round_state.step;

let proposer = self.get_proposer(round_state.round)?;
let proposer = self.get_proposer(round_state.height, round_state.round)?;
let info = Info::new(input_round, &self.address, proposer.address());

// Apply the input to the round state machine
Expand Down
7 changes: 6 additions & 1 deletion code/driver/src/proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ where
/// # Important
/// This function must be deterministic!
/// For a given round and validator set, it must always return the same proposer.
fn select_proposer(&self, round: Round, validator_set: &Ctx::ValidatorSet) -> Ctx::Address;
fn select_proposer(
&self,
height: Ctx::Height,
round: Round,
validator_set: &Ctx::ValidatorSet,
) -> Ctx::Address;
}
14 changes: 12 additions & 2 deletions code/test/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ use crate::{
pub struct RotateProposer;

impl ProposerSelector<TestContext> for RotateProposer {
fn select_proposer(&self, round: Round, validator_set: &ValidatorSet) -> Address {
fn select_proposer(
&self,
_height: Height,
round: Round,
validator_set: &ValidatorSet,
) -> Address {
let proposer_index = round.as_i64() as usize % validator_set.validators.len();
validator_set.validators[proposer_index].address
}
Expand All @@ -31,7 +36,12 @@ impl FixedProposer {
}

impl ProposerSelector<TestContext> for FixedProposer {
fn select_proposer(&self, _round: Round, _validator_set: &ValidatorSet) -> Address {
fn select_proposer(
&self,
_height: Height,
_round: Round,
_validator_set: &ValidatorSet,
) -> Address {
self.proposer
}
}
Expand Down

0 comments on commit 363b6f5

Please sign in to comment.