@@ -137,8 +137,6 @@ pub(crate) struct SingleHeightConsensus {
137137 state_machine : StateMachine ,
138138 // Tracks rounds for which we started validating a proposal to avoid duplicate validations.
139139 pending_validation_rounds : HashSet < Round > ,
140- last_prevote : Option < Vote > ,
141- last_precommit : Option < Vote > ,
142140}
143141
144142impl SingleHeightConsensus {
@@ -154,14 +152,7 @@ impl SingleHeightConsensus {
154152 let n_validators =
155153 u64:: try_from ( validators. len ( ) ) . expect ( "Should have way less than u64::MAX validators" ) ;
156154 let state_machine = StateMachine :: new ( height, id, n_validators, is_observer, quorum_type) ;
157- Self {
158- validators,
159- timeouts,
160- state_machine,
161- pending_validation_rounds : HashSet :: new ( ) ,
162- last_prevote : None ,
163- last_precommit : None ,
164- }
155+ Self { validators, timeouts, state_machine, pending_validation_rounds : HashSet :: new ( ) }
165156 }
166157
167158 pub ( crate ) fn current_round ( & self ) -> Round {
@@ -242,7 +233,7 @@ impl SingleHeightConsensus {
242233 self . handle_timeout ( context, event) . await
243234 }
244235 StateMachineEvent :: Prevote ( vote) => {
245- let Some ( last_vote) = & self . last_prevote else {
236+ let Some ( last_vote) = self . state_machine . last_self_prevote ( ) else {
246237 return Err ( ConsensusError :: InternalInconsistency (
247238 "No prevote to send" . to_string ( ) ,
248239 ) ) ;
@@ -255,11 +246,11 @@ impl SingleHeightConsensus {
255246 context. broadcast ( last_vote. clone ( ) ) . await ?;
256247 Ok ( ShcReturn :: Tasks ( vec ! [ ShcTask :: Prevote (
257248 self . timeouts. get_prevote_timeout( 0 ) ,
258- StateMachineEvent :: Prevote ( last_vote. clone ( ) ) ,
249+ StateMachineEvent :: Prevote ( last_vote) ,
259250 ) ] ) )
260251 }
261252 StateMachineEvent :: Precommit ( vote) => {
262- let Some ( last_vote) = & self . last_precommit else {
253+ let Some ( last_vote) = self . state_machine . last_self_precommit ( ) else {
263254 return Err ( ConsensusError :: InternalInconsistency (
264255 "No precommit to send" . to_string ( ) ,
265256 ) ) ;
@@ -272,7 +263,7 @@ impl SingleHeightConsensus {
272263 context. broadcast ( last_vote. clone ( ) ) . await ?;
273264 Ok ( ShcReturn :: Tasks ( vec ! [ ShcTask :: Precommit (
274265 self . timeouts. get_precommit_timeout( 0 ) ,
275- StateMachineEvent :: Precommit ( last_vote. clone ( ) ) ,
266+ StateMachineEvent :: Precommit ( last_vote) ,
276267 ) ] ) )
277268 }
278269 StateMachineEvent :: Proposal ( proposal_id, round, valid_round) => {
@@ -497,37 +488,18 @@ impl SingleHeightConsensus {
497488 context : & mut ContextT ,
498489 vote : Vote ,
499490 ) -> Result < Vec < ShcTask > , ConsensusError > {
500- let ( last_vote, task) = match vote. vote_type {
501- VoteType :: Prevote => (
502- & mut self . last_prevote ,
503- ShcTask :: Prevote (
504- self . timeouts . get_prevote_timeout ( vote. round ) ,
505- StateMachineEvent :: Prevote ( vote. clone ( ) ) ,
506- ) ,
491+ let task = match vote. vote_type {
492+ VoteType :: Prevote => ShcTask :: Prevote (
493+ self . timeouts . get_prevote_timeout ( vote. round ) ,
494+ StateMachineEvent :: Prevote ( vote. clone ( ) ) ,
507495 ) ,
508- VoteType :: Precommit => (
509- & mut self . last_precommit ,
510- ShcTask :: Precommit (
511- self . timeouts . get_precommit_timeout ( vote. round ) ,
512- StateMachineEvent :: Precommit ( vote. clone ( ) ) ,
513- ) ,
496+ VoteType :: Precommit => ShcTask :: Precommit (
497+ self . timeouts . get_precommit_timeout ( vote. round ) ,
498+ StateMachineEvent :: Precommit ( vote. clone ( ) ) ,
514499 ) ,
515500 } ;
516501 // Ensure the voter matches this node.
517502 assert_eq ! ( vote. voter, self . state_machine. validator_id( ) ) ;
518- * last_vote = match last_vote {
519- None => Some ( vote. clone ( ) ) ,
520- Some ( last_vote) if vote. round > last_vote. round => Some ( vote. clone ( ) ) ,
521- Some ( _) => {
522- // According to the Tendermint paper, the state machine should only vote for its
523- // current round. It should monotonically increase its round. It should only vote
524- // once per step.
525- return Err ( ConsensusError :: InternalInconsistency ( format ! (
526- "State machine must progress in time: last_vote: {last_vote:?} new_vote: \
527- {vote:?}",
528- ) ) ) ;
529- }
530- } ;
531503
532504 info ! ( "Broadcasting {vote:?}" ) ;
533505 context. broadcast ( vote) . await ?;
0 commit comments