From 8654e595db2be23339ad2b6af2afef5028f30dbc Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Wed, 15 Nov 2023 16:33:59 +0100 Subject: [PATCH] Add height to votes and update tests (#67) Co-authored-by: Anca Zamfir --- Code/common/src/context.rs | 2 + Code/common/src/height.rs | 2 +- Code/common/src/vote.rs | 3 + Code/driver/src/driver.rs | 6 +- Code/round/src/message.rs | 18 ++++-- Code/round/src/state.rs | 6 +- Code/round/src/state_machine.rs | 16 ++++-- Code/test/src/context.rs | 18 ++++-- Code/test/src/vote.rs | 23 +++++++- Code/test/tests/driver.rs | 97 ++++++++++++++++++++++++--------- Code/test/tests/round.rs | 4 +- Code/test/tests/vote_keeper.rs | 30 +++++----- 12 files changed, 161 insertions(+), 64 deletions(-) diff --git a/Code/common/src/context.rs b/Code/common/src/context.rs index 3f848e3c0..565f6b7c4 100644 --- a/Code/common/src/context.rs +++ b/Code/common/src/context.rs @@ -40,6 +40,7 @@ where /// Build a new prevote vote by the validator with the given address, /// for the value identified by the given value id, at the given round. fn new_prevote( + height: Self::Height, round: Round, value_id: Option>, address: Self::Address, @@ -48,6 +49,7 @@ where /// Build a new precommit vote by the validator with the given address, /// for the value identified by the given value id, at the given round. fn new_precommit( + height: Self::Height, round: Round, value_id: Option>, address: Self::Address, diff --git a/Code/common/src/height.rs b/Code/common/src/height.rs index 511f69503..973ee3b61 100644 --- a/Code/common/src/height.rs +++ b/Code/common/src/height.rs @@ -9,6 +9,6 @@ use core::fmt::Debug; pub trait Height where // TODO: Require Copy as well? - Self: Clone + Debug + PartialEq + Eq + PartialOrd + Ord, + Self: Default + Clone + Debug + PartialEq + Eq + PartialOrd + Ord, { } diff --git a/Code/common/src/vote.rs b/Code/common/src/vote.rs index a67190a26..dd5d41f70 100644 --- a/Code/common/src/vote.rs +++ b/Code/common/src/vote.rs @@ -21,6 +21,9 @@ where Self: Clone + Debug + Eq, Ctx: Context, { + /// The height for which the vote is for. + fn height(&self) -> Ctx::Height; + /// The round for which the vote is for. fn round(&self) -> Round; diff --git a/Code/driver/src/driver.rs b/Code/driver/src/driver.rs index 116862ecb..d7e044fe4 100644 --- a/Code/driver/src/driver.rs +++ b/Code/driver/src/driver.rs @@ -146,8 +146,10 @@ where }; assert!(self.round < round); - self.round_states - .insert(round, RoundState::default().new_round(round)); + self.round_states.insert( + round, + RoundState::default().new_round(self.height.clone(), round), + ); self.round = round; Ok(self.apply_event(round, event)) diff --git a/Code/round/src/message.rs b/Code/round/src/message.rs index 5e40369dd..877677f9e 100644 --- a/Code/round/src/message.rs +++ b/Code/round/src/message.rs @@ -25,12 +25,22 @@ impl Message { Message::Proposal(Ctx::new_proposal(height, round, value, pol_round)) } - pub fn prevote(round: Round, value_id: Option>, address: Ctx::Address) -> Self { - Message::Vote(Ctx::new_prevote(round, value_id, address)) + pub fn prevote( + height: Ctx::Height, + round: Round, + value_id: Option>, + address: Ctx::Address, + ) -> Self { + Message::Vote(Ctx::new_prevote(height, round, value_id, address)) } - pub fn precommit(round: Round, value_id: Option>, address: Ctx::Address) -> Self { - Message::Vote(Ctx::new_precommit(round, value_id, address)) + pub fn precommit( + height: Ctx::Height, + round: Round, + value_id: Option>, + address: Ctx::Address, + ) -> Self { + Message::Vote(Ctx::new_precommit(height, round, value_id, address)) } pub fn schedule_timeout(round: Round, step: TimeoutStep) -> Self { diff --git a/Code/round/src/state.rs b/Code/round/src/state.rs index d6d63ae5d..50d6879b7 100644 --- a/Code/round/src/state.rs +++ b/Code/round/src/state.rs @@ -34,6 +34,7 @@ pub struct State where Ctx: Context, { + pub height: Ctx::Height, pub round: Round, pub step: Step, pub proposal: Option, @@ -47,6 +48,7 @@ where { pub fn new() -> Self { Self { + height: Ctx::Height::default(), round: Round::INITIAL, step: Step::NewRound, proposal: None, @@ -55,8 +57,9 @@ where } } - pub fn new_round(self, round: Round) -> Self { + pub fn new_round(self, height: Ctx::Height, round: Round) -> Self { Self { + height, round, step: Step::NewRound, ..self @@ -105,6 +108,7 @@ where #[cfg_attr(coverage_nightly, coverage(off))] fn clone(&self) -> Self { Self { + height: self.height.clone(), round: self.round, step: self.step, proposal: self.proposal.clone(), diff --git a/Code/round/src/state_machine.rs b/Code/round/src/state_machine.rs index 595af5bc0..cf51be128 100644 --- a/Code/round/src/state_machine.rs +++ b/Code/round/src/state_machine.rs @@ -173,7 +173,7 @@ where None => Some(proposed), // not locked, prevote the value }; - let message = Message::prevote(state.round, value, address.clone()); + let message = Message::prevote(state.height.clone(), state.round, value, address.clone()); Transition::to(state.with_step(Step::Prevote)).with_message(message) } @@ -184,7 +184,7 @@ pub fn prevote_nil(state: State, address: &Ctx::Address) -> Transition where Ctx: Context, { - let message = Message::prevote(state.round, None, address.clone()); + let message = Message::prevote(state.height.clone(), state.round, None, address.clone()); Transition::to(state.with_step(Step::Prevote)).with_message(message) } @@ -211,7 +211,12 @@ where } let value = proposal.value(); - let message = Message::precommit(state.round, Some(value.id()), address.clone()); + let message = Message::precommit( + state.height.clone(), + state.round, + Some(value.id()), + address.clone(), + ); let current_value = match state.proposal { Some(ref proposal) => proposal.value().clone(), @@ -238,7 +243,7 @@ pub fn precommit_nil(state: State, address: &Ctx::Address) -> Transiti where Ctx: Context, { - let message = Message::precommit(state.round, None, address.clone()); + let message = Message::precommit(state.height.clone(), state.round, None, address.clone()); Transition::to(state.with_step(Step::Precommit)).with_message(message) } @@ -326,7 +331,8 @@ pub fn round_skip(state: State, round: Round) -> Transition where Ctx: Context, { - Transition::to(state.new_round(round)).with_message(Message::NewRound(round)) + Transition::to(state.clone().new_round(state.height.clone(), round)) + .with_message(Message::NewRound(round)) } /// We received +2/3 precommits for a value - commit and decide that value! diff --git a/Code/test/src/context.rs b/Code/test/src/context.rs index f61eba295..28ff263be 100644 --- a/Code/test/src/context.rs +++ b/Code/test/src/context.rs @@ -47,11 +47,21 @@ impl Context for TestContext { Proposal::new(height, round, value, pol_round) } - fn new_prevote(round: Round, value_id: Option, address: Address) -> Vote { - Vote::new_prevote(round, value_id, address) + fn new_prevote( + height: Height, + round: Round, + value_id: Option, + address: Address, + ) -> Vote { + Vote::new_prevote(height, round, value_id, address) } - fn new_precommit(round: Round, value_id: Option, address: Address) -> Vote { - Vote::new_precommit(round, value_id, address) + fn new_precommit( + height: Height, + round: Round, + value_id: Option, + address: Address, + ) -> Vote { + Vote::new_precommit(height, round, value_id, address) } } diff --git a/Code/test/src/vote.rs b/Code/test/src/vote.rs index d8a1a9aeb..dd33175e9 100644 --- a/Code/test/src/vote.rs +++ b/Code/test/src/vote.rs @@ -2,30 +2,43 @@ use signature::Signer; use malachite_common::{Round, SignedVote, VoteType}; -use crate::{Address, PrivateKey, TestContext, ValueId}; +use crate::{Address, Height, PrivateKey, TestContext, ValueId}; /// A vote for a value in a round #[derive(Clone, Debug, PartialEq, Eq)] pub struct Vote { pub typ: VoteType, + pub height: Height, pub round: Round, pub value: Option, pub validator_address: Address, } impl Vote { - pub fn new_prevote(round: Round, value: Option, validator_address: Address) -> Self { + pub fn new_prevote( + height: Height, + round: Round, + value: Option, + validator_address: Address, + ) -> Self { Self { typ: VoteType::Prevote, + height, round, value, validator_address, } } - pub fn new_precommit(round: Round, value: Option, address: Address) -> Self { + pub fn new_precommit( + height: Height, + round: Round, + value: Option, + address: Address, + ) -> Self { Self { typ: VoteType::Precommit, + height, round, value, validator_address: address, @@ -61,6 +74,10 @@ impl Vote { } impl malachite_common::Vote for Vote { + fn height(&self) -> Height { + self.height + } + fn round(&self) -> Round { self.round } diff --git a/Code/test/tests/driver.rs b/Code/test/tests/driver.rs index bec1bbb13..81588032b 100644 --- a/Code/test/tests/driver.rs +++ b/Code/test/tests/driver.rs @@ -96,6 +96,7 @@ fn driver_steps_proposer() { expected_output: Some(Message::Propose(proposal.clone())), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Propose, proposal: None, @@ -107,10 +108,12 @@ fn driver_steps_proposer() { desc: "Receive our own proposal, prevote for it (v1)", input_event: None, expected_output: Some(Message::Vote( - Vote::new_prevote(Round::new(0), Some(value.id()), my_addr).signed(&my_sk), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), my_addr) + .signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -124,6 +127,7 @@ fn driver_steps_proposer() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -134,11 +138,13 @@ fn driver_steps_proposer() { TestStep { desc: "v2 prevotes for our proposal", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value.id()), addr2).signed(&sk2), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr2) + .signed(&sk2), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -149,13 +155,16 @@ fn driver_steps_proposer() { TestStep { desc: "v3 prevotes for our proposal, we get +2/3 prevotes, precommit for it (v1)", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value.id()), addr3).signed(&sk3), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr3) + .signed(&sk3), )), expected_output: Some(Message::Vote( - Vote::new_precommit(Round::new(0), Some(value.id()), my_addr).signed(&my_sk), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), my_addr) + .signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -175,6 +184,7 @@ fn driver_steps_proposer() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -191,11 +201,13 @@ fn driver_steps_proposer() { TestStep { desc: "v2 precommits for our proposal", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), Some(value.id()), addr2).signed(&sk2), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), addr2) + .signed(&sk2), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -212,11 +224,13 @@ fn driver_steps_proposer() { TestStep { desc: "v3 precommits for our proposal, we get +2/3 precommits, decide it (v1)", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), Some(value.id()), addr3).signed(&sk3), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), addr3) + .signed(&sk3), )), expected_output: Some(Message::Decide(Round::new(0), value)), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Commit, proposal: Some(proposal.clone()), @@ -256,7 +270,6 @@ fn driver_steps_proposer() { #[test] fn driver_steps_not_proposer_valid() { let value = Value::new(9999); - let value_id = value.id(); let sel = RotateProposer::default(); let env = TestEnv::new(move |_, _| Some(value)); @@ -292,6 +305,7 @@ fn driver_steps_not_proposer_valid() { expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(0)))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Propose, proposal: None, @@ -303,10 +317,12 @@ fn driver_steps_not_proposer_valid() { desc: "Receive a proposal, prevote for it (v2)", input_event: Some(Event::Proposal(proposal.clone(), Validity::Valid)), expected_output: Some(Message::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), my_addr).signed(&my_sk), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), my_addr) + .signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -320,6 +336,7 @@ fn driver_steps_not_proposer_valid() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -330,11 +347,13 @@ fn driver_steps_not_proposer_valid() { TestStep { desc: "v1 prevotes for its own proposal", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), addr1).signed(&sk1), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr1) + .signed(&sk1), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: Some(proposal.clone()), @@ -345,13 +364,16 @@ fn driver_steps_not_proposer_valid() { TestStep { desc: "v3 prevotes for v1's proposal, it gets +2/3 prevotes, precommit for it (v2)", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), addr3).signed(&sk3), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr3) + .signed(&sk3), )), expected_output: Some(Message::Vote( - Vote::new_precommit(Round::new(0), Some(value_id), my_addr).signed(&my_sk), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), my_addr) + .signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -371,6 +393,7 @@ fn driver_steps_not_proposer_valid() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -387,11 +410,13 @@ fn driver_steps_not_proposer_valid() { TestStep { desc: "v1 precommits its proposal", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), Some(value_id), addr1).signed(&sk1), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), addr1) + .signed(&sk1), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: Some(proposal.clone()), @@ -408,11 +433,13 @@ fn driver_steps_not_proposer_valid() { TestStep { desc: "v3 precommits for v1's proposal, it gets +2/3 precommits, decide it", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), Some(value_id), addr3).signed(&sk3), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), addr3) + .signed(&sk3), )), expected_output: Some(Message::Decide(Round::new(0), value)), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Commit, proposal: Some(proposal.clone()), @@ -452,7 +479,6 @@ fn driver_steps_not_proposer_valid() { #[test] fn driver_steps_not_proposer_invalid() { let value = Value::new(9999); - let value_id = value.id(); let sel = RotateProposer::default(); let env = TestEnv::new(move |_, _| Some(value)); @@ -488,6 +514,7 @@ fn driver_steps_not_proposer_invalid() { expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(0)))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Propose, proposal: None, @@ -499,10 +526,11 @@ fn driver_steps_not_proposer_invalid() { desc: "Receive an invalid proposal, prevote for nil (v2)", input_event: Some(Event::Proposal(proposal.clone(), Validity::Invalid)), expected_output: Some(Message::Vote( - Vote::new_prevote(Round::new(0), None, my_addr).signed(&my_sk), + Vote::new_prevote(Height::new(1),Round::new(0), None, my_addr).signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -516,6 +544,7 @@ fn driver_steps_not_proposer_invalid() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -526,11 +555,12 @@ fn driver_steps_not_proposer_invalid() { TestStep { desc: "v1 prevotes for its own proposal", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), addr1).signed(&sk1), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr1).signed(&sk1), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -541,11 +571,12 @@ fn driver_steps_not_proposer_invalid() { TestStep { desc: "v3 prevotes for v1's proposal, we have polka for any, schedule prevote timeout (v2)", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), addr3).signed(&sk3), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr3).signed(&sk3), )), expected_output: Some(Message::ScheduleTimeout(Timeout::prevote(Round::new(0)))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -557,10 +588,11 @@ fn driver_steps_not_proposer_invalid() { desc: "prevote timeout elapses, we precommit for nil (v2)", input_event: Some(Event::TimeoutElapsed(Timeout::prevote(Round::new(0)))), expected_output: Some(Message::Vote( - Vote::new_precommit(Round::new(0), None, my_addr).signed(&my_sk), + Vote::new_precommit(Height::new(1), Round::new(0), None, my_addr).signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: None, @@ -594,7 +626,6 @@ fn driver_steps_not_proposer_invalid() { #[test] fn driver_steps_not_proposer_timeout_multiple_rounds() { let value = Value::new(9999); - let value_id = value.id(); let sel = RotateProposer::default(); let env = TestEnv::new(move |_, _| Some(value)); @@ -629,6 +660,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(0)))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Propose, proposal: None, @@ -641,11 +673,12 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { desc: "Receive a propose timeout, prevote for nil (v3)", input_event: Some(Event::TimeoutElapsed(Timeout::propose(Round::new(0)))), expected_output: Some(Message::Vote( - Vote::new_prevote(Round::new(0), None, my_addr).signed(&my_sk), + Vote::new_prevote(Height::new(1), Round::new(0), None, my_addr).signed(&my_sk), )), expected_round: Round::new(0), new_state: State { round: Round::new(0), + height: Height::new(1), step: Step::Prevote, proposal: None, locked: None, @@ -659,6 +692,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -670,11 +704,13 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { TestStep { desc: "v1 prevotes for its own proposal", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value_id), addr1).signed(&sk1), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), addr1) + .signed(&sk1), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Prevote, proposal: None, @@ -686,13 +722,14 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { TestStep { desc: "v2 prevotes for nil, we get +2/3 prevotes, precommit for nil", input_event: Some(Event::Vote( - Vote::new_prevote(Round::new(0), None, addr2).signed(&sk2), + Vote::new_prevote(Height::new(1), Round::new(0), None, addr2).signed(&sk2), )), expected_output: Some(Message::Vote( - Vote::new_precommit(Round::new(0), None, my_addr).signed(&my_sk), + Vote::new_precommit(Height::new(1), Round::new(0), None, my_addr).signed(&my_sk), )), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: None, @@ -707,6 +744,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: None, @@ -718,11 +756,13 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { TestStep { desc: "v1 precommits its proposal", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), Some(value_id), addr1).signed(&sk1), + Vote::new_precommit(Height::new(1), Round::new(0), Some(value.id()), addr1) + .signed(&sk1), )), expected_output: None, expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: None, @@ -734,11 +774,12 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { TestStep { desc: "v2 precommits for nil", input_event: Some(Event::Vote( - Vote::new_precommit(Round::new(0), None, addr2).signed(&sk2), + Vote::new_precommit(Height::new(1), Round::new(0), None, addr2).signed(&sk2), )), expected_output: Some(Message::ScheduleTimeout(Timeout::precommit(Round::new(0)))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(0), step: Step::Precommit, proposal: None, @@ -753,6 +794,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { expected_output: Some(Message::NewRound(Round::new(1))), expected_round: Round::new(0), new_state: State { + height: Height::new(1), round: Round::new(1), step: Step::NewRound, proposal: None, @@ -766,6 +808,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() { expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(1)))), expected_round: Round::new(1), new_state: State { + height: Height::new(1), round: Round::new(1), step: Step::Propose, proposal: None, @@ -886,7 +929,7 @@ fn driver_steps_validator_not_found() { // v2 prevotes for some proposal, we cannot find it in the validator set => error let output = block_on(driver.execute(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value.id()), v2.address).signed(&sk2), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), v2.address).signed(&sk2), ))); assert_eq!(output, Err(Error::ValidatorNotFound(v2.address))); @@ -922,7 +965,7 @@ fn driver_steps_invalid_signature() { // v2 prevotes for some proposal, with an invalid signature, // ie. signed by v1 instead of v2, just a way of forging an invalid signature let output = block_on(driver.execute(Event::Vote( - Vote::new_prevote(Round::new(0), Some(value.id()), v2.address).signed(&sk1), + Vote::new_prevote(Height::new(1), Round::new(0), Some(value.id()), v2.address).signed(&sk1), ))); assert!(matches!(output, Err(Error::InvalidVoteSignature(_, _)))); diff --git a/Code/test/tests/round.rs b/Code/test/tests/round.rs index 819d5fa3d..34b02d566 100644 --- a/Code/test/tests/round.rs +++ b/Code/test/tests/round.rs @@ -37,7 +37,7 @@ fn test_prevote() { let value = Value::new(42); let height = Height::new(1); - let state: State = State::default().new_round(Round::new(1)); + let state: State = State::default().new_round(height, Round::new(1)); let data = RoundData::new(Round::new(1), &height, &ADDRESS); let transition = apply_event(state, &data, Event::NewRound); @@ -67,6 +67,6 @@ fn test_prevote() { assert_eq!(transition.next_state.step, Step::Prevote); assert_eq!( transition.message.unwrap(), - Message::prevote(Round::new(1), Some(value.id()), ADDRESS) + Message::prevote(Height::new(1), Round::new(1), Some(value.id()), ADDRESS) ); } diff --git a/Code/test/tests/vote_keeper.rs b/Code/test/tests/vote_keeper.rs index 8dedc2b3c..47d8f4eca 100644 --- a/Code/test/tests/vote_keeper.rs +++ b/Code/test/tests/vote_keeper.rs @@ -1,7 +1,7 @@ use malachite_common::Round; use malachite_vote::keeper::{Message, VoteKeeper}; -use malachite_test::{Address, TestContext, ValueId, Vote}; +use malachite_test::{Address, Height, TestContext, ValueId, Vote}; const ADDRESS1: Address = Address::new([41; 20]); const ADDRESS2: Address = Address::new([42; 20]); @@ -12,15 +12,15 @@ const ADDRESS4: Address = Address::new([44; 20]); fn prevote_apply_nil() { let mut keeper: VoteKeeper = VoteKeeper::new(3); - let vote = Vote::new_prevote(Round::new(0), None, ADDRESS1); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), None, ADDRESS1); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_prevote(Round::new(0), None, ADDRESS2); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), None, ADDRESS2); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_prevote(Round::new(0), None, ADDRESS3); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), None, ADDRESS3); let msg = keeper.apply_vote(vote, 1); assert_eq!(msg, Some(Message::PolkaNil)); } @@ -29,15 +29,15 @@ fn prevote_apply_nil() { fn precommit_apply_nil() { let mut keeper: VoteKeeper = VoteKeeper::new(3); - let vote = Vote::new_precommit(Round::new(0), None, ADDRESS1); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), None, ADDRESS1); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_precommit(Round::new(0), None, ADDRESS2); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), None, ADDRESS2); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_precommit(Round::new(0), None, ADDRESS3); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), None, ADDRESS3); let msg = keeper.apply_vote(vote, 1); assert_eq!(msg, Some(Message::PrecommitAny)); } @@ -49,19 +49,19 @@ fn prevote_apply_single_value() { let v = ValueId::new(1); let val = Some(v); - let vote = Vote::new_prevote(Round::new(0), val, ADDRESS1); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), val, ADDRESS1); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_prevote(Round::new(0), val, ADDRESS2); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), val, ADDRESS2); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote_nil = Vote::new_prevote(Round::new(0), None, ADDRESS3); + let vote_nil = Vote::new_prevote(Height::new(1), Round::new(0), None, ADDRESS3); let msg = keeper.apply_vote(vote_nil, 1); assert_eq!(msg, Some(Message::PolkaAny)); - let vote = Vote::new_prevote(Round::new(0), val, ADDRESS4); + let vote = Vote::new_prevote(Height::new(1), Round::new(0), val, ADDRESS4); let msg = keeper.apply_vote(vote, 1); assert_eq!(msg, Some(Message::PolkaValue(v))); } @@ -73,19 +73,19 @@ fn precommit_apply_single_value() { let v = ValueId::new(1); let val = Some(v); - let vote = Vote::new_precommit(Round::new(0), val, ADDRESS1); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), val, ADDRESS1); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote = Vote::new_precommit(Round::new(0), val, ADDRESS2); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), val, ADDRESS2); let msg = keeper.apply_vote(vote.clone(), 1); assert_eq!(msg, None); - let vote_nil = Vote::new_precommit(Round::new(0), None, ADDRESS3); + let vote_nil = Vote::new_precommit(Height::new(1), Round::new(0), None, ADDRESS3); let msg = keeper.apply_vote(vote_nil, 1); assert_eq!(msg, Some(Message::PrecommitAny)); - let vote = Vote::new_precommit(Round::new(0), val, ADDRESS4); + let vote = Vote::new_precommit(Height::new(1), Round::new(0), val, ADDRESS4); let msg = keeper.apply_vote(vote, 1); assert_eq!(msg, Some(Message::PrecommitValue(v))); }