Skip to content

Commit

Permalink
Remove NewRoundProposer event in favor of check within the state ma…
Browse files Browse the repository at this point in the history
…chine (#79)
  • Loading branch information
romac committed Nov 24, 2023
1 parent c990985 commit 2e390cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
10 changes: 1 addition & 9 deletions Code/driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,9 @@ where
height: Ctx::Height,
round: Round,
) -> Result<Option<RoundMessage<Ctx>>, Error<Ctx>> {
let proposer = self.get_proposer(round)?;

let event = if proposer.address() == &self.address {
RoundEvent::NewRoundProposer
} else {
RoundEvent::NewRound
};

self.round_state = RoundState::new(height, round);

self.apply_event(round, event)
self.apply_event(round, RoundEvent::NewRound)
}

async fn apply_propose_value(
Expand Down
5 changes: 2 additions & 3 deletions Code/round/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ pub enum Event<Ctx>
where
Ctx: Context,
{
NewRound, // Start a new round, not as proposer.L20
NewRoundProposer, // Start a new round and wait for a value to propose.L14
NewRound, // Start a new round, either as proposer or not. L14/L20
ProposeValue(Ctx::Value), // Propose a value.L14
Proposal(Ctx::Proposal), // Receive a proposal. L22 + L23 (valid)
Proposal(Ctx::Proposal), // Receive a proposal. L22 + L23 (valid)
ProposalAndPolkaPrevious(Ctx::Proposal), // Recieved a proposal and a polka value from a previous round. L28 + L29 (valid)
ProposalInvalid, // Receive an invalid proposal. L26 + L32 (invalid)
PolkaValue(ValueId<Ctx>), // Receive +2/3 prevotes for valueId. L44
Expand Down
5 changes: 4 additions & 1 deletion Code/round/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ where

match (state.step, event) {
// From NewRound. Event must be for current round.
(Step::NewRound, Event::NewRoundProposer) if this_round => {

// We are the proposer
(Step::NewRound, Event::NewRound) if this_round && info.is_proposer() => {
propose_valid_or_get_value(state) // L18
}
// We are not the proposer
(Step::NewRound, Event::NewRound) if this_round => schedule_timeout_propose(state), // L11/L20

// From Propose. Event must be for current round.
Expand Down
7 changes: 5 additions & 2 deletions Code/test/tests/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use malachite_round::state::{State, Step};
use malachite_round::state_machine::{apply_event, Info};

const ADDRESS: Address = Address::new([42; 20]);
const OTHER_ADDRESS: Address = Address::new([21; 20]);

#[test]
fn test_propose() {
Expand All @@ -20,9 +21,10 @@ fn test_propose() {
..Default::default()
};

// We are the proposer
let data = Info::new(round, &ADDRESS, &ADDRESS);

let transition = apply_event(state.clone(), &data, Event::NewRoundProposer);
let transition = apply_event(state.clone(), &data, Event::NewRound);

state.step = Step::Propose;
assert_eq!(transition.next_state, state);
Expand Down Expand Up @@ -53,7 +55,8 @@ fn test_prevote() {
..Default::default()
};

let data = Info::new(Round::new(1), &ADDRESS, &ADDRESS);
// We are not the proposer
let data = Info::new(Round::new(1), &ADDRESS, &OTHER_ADDRESS);

let transition = apply_event(state, &data, Event::NewRound);

Expand Down

0 comments on commit 2e390cb

Please sign in to comment.