@@ -27,7 +27,7 @@ use crate::votes_threshold::{QuorumType, VotesThreshold, ROUND_SKIP_THRESHOLD};
2727
2828/// Events which the state machine sends/receives.
2929#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
30- pub enum StateMachineEvent {
30+ pub ( crate ) enum StateMachineEvent {
3131 /// Sent by the state machine when a block is required to propose (ProposalCommitment is always
3232 /// None). While waiting for the response of GetProposal, the state machine will buffer all
3333 /// other events. The caller *must* respond with a valid proposal id for this height to the
@@ -53,7 +53,7 @@ pub enum StateMachineEvent {
5353}
5454
5555#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
56- pub enum Step {
56+ pub ( crate ) enum Step {
5757 Propose ,
5858 Prevote ,
5959 Precommit ,
@@ -65,7 +65,7 @@ pub enum Step {
6565///
6666/// Each height is begun with a call to `start`, with no further calls to it.
6767#[ derive( Serialize , Deserialize ) ]
68- pub struct StateMachine {
68+ pub ( crate ) struct StateMachine {
6969 id : ValidatorId ,
7070 round : Round ,
7171 step : Step ,
@@ -91,7 +91,7 @@ pub struct StateMachine {
9191
9292impl StateMachine {
9393 /// total_weight - the total voting weight of all validators for this height.
94- pub fn new (
94+ pub ( crate ) fn new (
9595 id : ValidatorId ,
9696 total_weight : u64 ,
9797 is_observer : bool ,
@@ -120,22 +120,26 @@ impl StateMachine {
120120 }
121121 }
122122
123- pub fn round ( & self ) -> Round {
123+ pub ( crate ) fn round ( & self ) -> Round {
124124 self . round
125125 }
126126
127- pub fn total_weight ( & self ) -> u64 {
127+ pub ( crate ) fn total_weight ( & self ) -> u64 {
128128 self . total_weight
129129 }
130130
131- pub fn quorum ( & self ) -> & VotesThreshold {
131+ pub ( crate ) fn quorum ( & self ) -> & VotesThreshold {
132132 & self . quorum
133133 }
134134
135+ pub ( crate ) fn id ( & self ) -> ValidatorId {
136+ self . id
137+ }
138+
135139 /// Starts the state machine, effectively calling `StartRound(0)` from the paper. This is
136140 /// needed to trigger the first leader to propose.
137141 /// See [`GetProposal`](StateMachineEvent::GetProposal)
138- pub fn start < LeaderFn > ( & mut self , leader_fn : & LeaderFn ) -> VecDeque < StateMachineEvent >
142+ pub ( crate ) fn start < LeaderFn > ( & mut self , leader_fn : & LeaderFn ) -> VecDeque < StateMachineEvent >
139143 where
140144 LeaderFn : Fn ( Round ) -> ValidatorId ,
141145 {
@@ -151,7 +155,7 @@ impl StateMachine {
151155 /// events back to the state machine, as it makes sure to handle them before returning.
152156 // This means that the StateMachine handles events the same regardless of whether it was sent by
153157 // self or a peer. This is in line with the Algorithm 1 in the paper and keeps the code simpler.
154- pub fn handle_event < LeaderFn > (
158+ pub ( crate ) fn handle_event < LeaderFn > (
155159 & mut self ,
156160 event : StateMachineEvent ,
157161 leader_fn : & LeaderFn ,
@@ -178,7 +182,7 @@ impl StateMachine {
178182 self . handle_enqueued_events ( leader_fn)
179183 }
180184
181- fn handle_enqueued_events < LeaderFn > (
185+ pub ( crate ) fn handle_enqueued_events < LeaderFn > (
182186 & mut self ,
183187 leader_fn : & LeaderFn ,
184188 ) -> VecDeque < StateMachineEvent >
@@ -219,7 +223,7 @@ impl StateMachine {
219223 output_events
220224 }
221225
222- fn handle_event_internal < LeaderFn > (
226+ pub ( crate ) fn handle_event_internal < LeaderFn > (
223227 & mut self ,
224228 event : StateMachineEvent ,
225229 leader_fn : & LeaderFn ,
@@ -258,7 +262,7 @@ impl StateMachine {
258262 }
259263 }
260264
261- fn handle_get_proposal (
265+ pub ( crate ) fn handle_get_proposal (
262266 & mut self ,
263267 proposal_id : Option < ProposalCommitment > ,
264268 round : u32 ,
@@ -271,7 +275,7 @@ impl StateMachine {
271275 }
272276
273277 // A proposal from a peer (or self) node.
274- fn handle_proposal < LeaderFn > (
278+ pub ( crate ) fn handle_proposal < LeaderFn > (
275279 & mut self ,
276280 proposal_id : Option < ProposalCommitment > ,
277281 round : u32 ,
@@ -286,7 +290,7 @@ impl StateMachine {
286290 self . map_round_to_upons ( round, leader_fn)
287291 }
288292
289- fn handle_timeout_propose ( & mut self , round : u32 ) -> VecDeque < StateMachineEvent > {
293+ pub ( crate ) fn handle_timeout_propose ( & mut self , round : u32 ) -> VecDeque < StateMachineEvent > {
290294 if self . step != Step :: Propose || round != self . round {
291295 return VecDeque :: new ( ) ;
292296 } ;
@@ -301,7 +305,7 @@ impl StateMachine {
301305 }
302306
303307 // A prevote from a peer (or self) node.
304- fn handle_prevote < LeaderFn > (
308+ pub ( crate ) fn handle_prevote < LeaderFn > (
305309 & mut self ,
306310 proposal_id : Option < ProposalCommitment > ,
307311 round : u32 ,
@@ -316,7 +320,7 @@ impl StateMachine {
316320 self . map_round_to_upons ( round, leader_fn)
317321 }
318322
319- fn handle_timeout_prevote ( & mut self , round : u32 ) -> VecDeque < StateMachineEvent > {
323+ pub ( crate ) fn handle_timeout_prevote ( & mut self , round : u32 ) -> VecDeque < StateMachineEvent > {
320324 if self . step != Step :: Prevote || round != self . round {
321325 return VecDeque :: new ( ) ;
322326 } ;
0 commit comments