@@ -592,8 +592,8 @@ impl Worker {
592592 self . votes_received = BitSet :: new ( ) ;
593593 }
594594
595- fn move_to_step ( & mut self , step : Step , is_restoring : bool ) {
596- let prev_step = mem:: replace ( & mut self . step , step . into ( ) ) ;
595+ fn move_to_step ( & mut self , state : TendermintState , is_restoring : bool ) {
596+ let prev_step = mem:: replace ( & mut self . step , state . clone ( ) ) ;
597597 if !is_restoring {
598598 self . backup ( ) ;
599599 }
@@ -602,18 +602,18 @@ impl Worker {
602602 self . timeout_token_nonce += 1 ;
603603 self . extension
604604 . send ( network:: Event :: SetTimerStep {
605- step,
605+ step : state . to_step ( ) ,
606606 view : self . view ,
607607 expired_token_nonce,
608608 } )
609609 . unwrap ( ) ;
610- let vote_step = VoteStep :: new ( self . height , self . view , step ) ;
610+ let vote_step = VoteStep :: new ( self . height , self . view , state . to_step ( ) ) ;
611611
612612 // If there are not enough pre-votes or pre-commits,
613613 // move_to_step can be called with the same step
614614 // Also, when moving to the commit step,
615615 // keep `votes_received` for gossiping.
616- if prev_step. to_step ( ) != step && step != Step :: Commit {
616+ if prev_step. to_step ( ) != state . to_step ( ) && !state . is_commit ( ) {
617617 self . votes_received = BitSet :: new ( ) ;
618618 }
619619
@@ -624,13 +624,13 @@ impl Worker {
624624 self . last_two_thirds_majority . view ( ) ,
625625 self . votes_received ,
626626 ) ;
627- match step {
627+ match state . to_step ( ) {
628628 Step :: Propose => {
629629 cinfo ! ( ENGINE , "move_to_step: Propose." ) ;
630630 if let Some ( hash) = self . votes . get_block_hashes ( & vote_step) . first ( ) {
631631 if self . client ( ) . block ( & BlockId :: Hash ( * hash) ) . is_some ( ) {
632632 self . proposal = Proposal :: new_imported ( * hash) ;
633- self . move_to_step ( Step :: Prevote , is_restoring) ;
633+ self . move_to_step ( TendermintState :: Prevote , is_restoring) ;
634634 } else {
635635 cwarn ! ( ENGINE , "Proposal is received but not imported" ) ;
636636 // Proposal is received but is not verified yet.
@@ -822,7 +822,7 @@ impl Worker {
822822 let next_step = match self . step {
823823 TendermintState :: Precommit if message. on . block_hash . is_none ( ) && has_enough_aligned_votes => {
824824 self . increment_view ( 1 ) ;
825- Some ( Step :: Propose )
825+ Some ( TendermintState :: Propose )
826826 }
827827 TendermintState :: Precommit if has_enough_aligned_votes => {
828828 let bh = message. on . block_hash . expect ( "previous guard ensures is_some; qed" ) ;
@@ -832,16 +832,16 @@ impl Worker {
832832
833833 // Update the best block hash as the hash of the committed block
834834 self . client ( ) . update_best_as_committed ( bh) ;
835- Some ( Step :: Commit )
835+ Some ( TendermintState :: Commit )
836836 } else {
837837 cwarn ! ( ENGINE , "Cannot find a proposal which committed" ) ;
838838 self . increment_view ( 1 ) ;
839- Some ( Step :: Propose )
839+ Some ( TendermintState :: Propose )
840840 }
841841 }
842842 // Avoid counting votes twice.
843- TendermintState :: Prevote if lock_change => Some ( Step :: Precommit ) ,
844- TendermintState :: Prevote if has_enough_aligned_votes => Some ( Step :: Precommit ) ,
843+ TendermintState :: Prevote if lock_change => Some ( TendermintState :: Precommit ) ,
844+ TendermintState :: Prevote if has_enough_aligned_votes => Some ( TendermintState :: Precommit ) ,
845845 _ => None ,
846846 } ;
847847
@@ -856,7 +856,7 @@ impl Worker {
856856 {
857857 let height = self . height ;
858858 self . move_to_height ( height + 1 ) ;
859- self . move_to_step ( Step :: Propose , is_restoring) ;
859+ self . move_to_step ( TendermintState :: Propose , is_restoring) ;
860860 return
861861 }
862862
@@ -904,7 +904,7 @@ impl Worker {
904904 let current_step = self . step . clone ( ) ;
905905 match current_step {
906906 TendermintState :: Propose => {
907- self . move_to_step ( Step :: Prevote , false ) ;
907+ self . move_to_step ( TendermintState :: Prevote , false ) ;
908908 }
909909 TendermintState :: ProposeWaitImported {
910910 block,
@@ -944,13 +944,13 @@ impl Worker {
944944 if proposal_at_view_0 == Some ( proposal. hash ( ) ) {
945945 self . proposal = Proposal :: new_imported ( proposal. hash ( ) )
946946 }
947- self . move_to_step ( Step :: Prevote , false ) ;
947+ self . move_to_step ( TendermintState :: Prevote , false ) ;
948948 }
949949 }
950950
951951 fn submit_proposal_block ( & mut self , sealed_block : & SealedBlock ) {
952952 cinfo ! ( ENGINE , "Submitting proposal block {}" , sealed_block. header( ) . hash( ) ) ;
953- self . move_to_step ( Step :: Prevote , false ) ;
953+ self . move_to_step ( TendermintState :: Prevote , false ) ;
954954 self . broadcast_proposal_block ( self . view , encoded:: Block :: new ( sealed_block. rlp_bytes ( ) ) ) ;
955955 }
956956
@@ -968,14 +968,16 @@ impl Worker {
968968 let client = self . client ( ) ;
969969 let backup = restore ( client. get_kvdb ( ) . as_ref ( ) ) ;
970970 if let Some ( backup) = backup {
971- let backup_step = if backup. step == Step :: Commit {
971+ let backup_step = match backup. step {
972+ Step :: Propose => TendermintState :: Propose ,
973+ Step :: Prevote => TendermintState :: Prevote ,
974+ Step :: Precommit => TendermintState :: Precommit ,
972975 // If the backuped step is `Commit`, we should start at `Precommit` to update the
973976 // chain's best block safely.
974- Step :: Precommit
975- } else {
976- backup. step
977+ Step :: Commit => TendermintState :: Precommit ,
977978 } ;
978- self . step = backup_step. into ( ) ;
979+
980+ self . step = backup_step;
979981 self . height = backup. height ;
980982 self . view = backup. view ;
981983 self . last_confirmed_view = backup. last_confirmed_view ;
@@ -1188,7 +1190,7 @@ impl Worker {
11881190 let next_step = match self . step {
11891191 TendermintState :: Propose => {
11901192 cinfo ! ( ENGINE , "Propose timeout." ) ;
1191- Step :: Prevote
1193+ TendermintState :: Prevote
11921194 }
11931195 TendermintState :: ProposeWaitBlockGeneration {
11941196 ..
@@ -1210,20 +1212,20 @@ impl Worker {
12101212 }
12111213 TendermintState :: Prevote if self . has_enough_any_votes ( ) => {
12121214 cinfo ! ( ENGINE , "Prevote timeout." ) ;
1213- Step :: Precommit
1215+ TendermintState :: Precommit
12141216 }
12151217 TendermintState :: Prevote => {
12161218 cinfo ! ( ENGINE , "Prevote timeout without enough votes." ) ;
1217- Step :: Prevote
1219+ TendermintState :: Prevote
12181220 }
12191221 TendermintState :: Precommit if self . has_enough_any_votes ( ) => {
12201222 cinfo ! ( ENGINE , "Precommit timeout." ) ;
12211223 self . increment_view ( 1 ) ;
1222- Step :: Propose
1224+ TendermintState :: Propose
12231225 }
12241226 TendermintState :: Precommit => {
12251227 cinfo ! ( ENGINE , "Precommit timeout without enough votes." ) ;
1226- Step :: Precommit
1228+ TendermintState :: Precommit
12271229 }
12281230 TendermintState :: Commit => {
12291231 cinfo ! ( ENGINE , "Commit timeout." ) ;
@@ -1234,7 +1236,7 @@ impl Worker {
12341236 }
12351237 let height = self . height ;
12361238 self . move_to_height ( height + 1 ) ;
1237- Step :: Propose
1239+ TendermintState :: Propose
12381240 }
12391241 TendermintState :: CommitTimedout => unreachable ! ( ) ,
12401242 } ;
@@ -1457,14 +1459,14 @@ impl Worker {
14571459 }
14581460 }
14591461 if height_changed {
1460- self . move_to_step ( Step :: Propose , false ) ;
1462+ self . move_to_step ( TendermintState :: Propose , false ) ;
14611463 return
14621464 }
14631465 }
14641466 if !enacted. is_empty ( ) && self . can_move_from_commit_to_propose ( ) {
14651467 let new_height = self . height + 1 ;
14661468 self . move_to_height ( new_height) ;
1467- self . move_to_step ( Step :: Propose , false )
1469+ self . move_to_step ( TendermintState :: Propose , false )
14681470 }
14691471 }
14701472
0 commit comments