@@ -34,17 +34,20 @@ type State struct {
3434 block []byte
3535
3636 // FBFT phase: Announce, Prepare, Commit
37- phase FBFTPhase
37+ phase atomic. Value // FBFTPhase
3838
3939 // ShardID of the consensus
4040 ShardID uint32
4141}
4242
4343func NewState (mode Mode , shardID uint32 ) State {
44- return State {
44+ state := State {
4545 mode : uint32 (mode ),
4646 ShardID : shardID ,
47+ phase : atomic.Value {},
4748 }
49+ state .phase .Store (FBFTAnnounce )
50+ return state
4851}
4952
5053func (pm * State ) getBlockNum () uint64 {
@@ -79,7 +82,7 @@ func (pm *State) getLogger() *zerolog.Logger {
7982 Uint32 ("shardID" , pm .ShardID ).
8083 Uint64 ("myBlock" , pm .getBlockNum ()).
8184 Uint64 ("myViewID" , pm .GetCurBlockViewID ()).
82- Str ("phase" , pm .phase .String ()).
85+ Str ("phase" , pm .phase .Load ().( FBFTPhase ). String ()).
8386 Str ("mode" , pm .Mode ().String ()).
8487 Logger ()
8588 return & logger
@@ -88,11 +91,11 @@ func (pm *State) getLogger() *zerolog.Logger {
8891// switchPhase will switch FBFTPhase to desired phase.
8992func (pm * State ) switchPhase (subject string , desired FBFTPhase ) {
9093 pm .getLogger ().Info ().
91- Str ("from:" , pm .phase .String ()).
94+ Str ("from:" , pm .phase .Load ().( FBFTPhase ). String ()).
9295 Str ("to:" , desired .String ()).
9396 Str ("switchPhase:" , subject )
9497
95- pm .phase = desired
98+ pm .phase . Store ( desired )
9699}
97100
98101// GetCurBlockViewID returns the current view ID of the consensus
0 commit comments