From 2e390cb85edaf4e62e22063d29b402a499b10dc9 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 24 Nov 2023 10:01:48 +0100 Subject: [PATCH] Remove `NewRoundProposer` event in favor of check within the state machine (#79) --- Code/driver/src/driver.rs | 10 +--------- Code/round/src/events.rs | 5 ++--- Code/round/src/state_machine.rs | 5 ++++- Code/test/tests/round.rs | 7 +++++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Code/driver/src/driver.rs b/Code/driver/src/driver.rs index 86a86357b..966a1948a 100644 --- a/Code/driver/src/driver.rs +++ b/Code/driver/src/driver.rs @@ -121,17 +121,9 @@ where height: Ctx::Height, round: Round, ) -> Result>, Error> { - 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( diff --git a/Code/round/src/events.rs b/Code/round/src/events.rs index 544edfc00..77c6fff40 100644 --- a/Code/round/src/events.rs +++ b/Code/round/src/events.rs @@ -5,10 +5,9 @@ pub enum Event 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), // Receive +2/3 prevotes for valueId. L44 diff --git a/Code/round/src/state_machine.rs b/Code/round/src/state_machine.rs index c77eda7b3..4dfa72308 100644 --- a/Code/round/src/state_machine.rs +++ b/Code/round/src/state_machine.rs @@ -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. diff --git a/Code/test/tests/round.rs b/Code/test/tests/round.rs index 9a14b692f..0952ff747 100644 --- a/Code/test/tests/round.rs +++ b/Code/test/tests/round.rs @@ -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() { @@ -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); @@ -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);