Skip to content

Commit

Permalink
verify
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen committed Mar 14, 2024
1 parent fa5efdc commit 98e103c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
6 changes: 1 addition & 5 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ type Consensus struct {
phase FBFTPhase
// current indicates what state a node is in
current State
// isBackup declarative the node is in backup mode
isBackup bool
// 2 types of timeouts: normal and viewchange
consensusTimeout map[TimeoutType]*utils.Timeout
// Commits collected from validators.
Expand Down Expand Up @@ -254,9 +252,7 @@ func (consensus *Consensus) getConsensusLeaderPrivateKey() (*bls.PrivateKeyWrapp
}

func (consensus *Consensus) IsBackup() bool {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.isBackup
return consensus.registry.IsBackup()
}

func (consensus *Consensus) BlockNum() uint64 {
Expand Down
4 changes: 2 additions & 2 deletions consensus/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ func (consensus *Consensus) setMode(m Mode) {
// SetIsBackup sets the mode of consensus
func (consensus *Consensus) SetIsBackup(isBackup bool) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.getLogger().Debug().
Bool("IsBackup", isBackup).
Msg("[SetIsBackup]")
consensus.isBackup = isBackup
consensus.mutex.Unlock()
consensus.registry.SetIsBackup(isBackup)
}

// Mode returns the mode of consensus
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (consensus *Consensus) HandleMessageUpdate(ctx context.Context, peer libp2p
consensus.isLeader()

// if in backup normal mode, force ignore view change event and leader event.
if consensus.isBackup {
if consensus.registry.IsBackup() {
canHandleViewChange = false
intendedForLeader = false
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (consensus *Consensus) validateNewBlock(recvMsg *FBFTMessage) (*types.Block
}

func (consensus *Consensus) prepare() {
if consensus.isBackup {
if consensus.registry.IsBackup() {
return
}

Expand All @@ -152,7 +152,7 @@ func (consensus *Consensus) prepare() {

// sendCommitMessages send out commit messages to leader
func (consensus *Consensus) sendCommitMessages(blockObj *types.Block) {
if consensus.isBackup || blockObj == nil {
if consensus.IsBackup() || blockObj == nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/view_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func createTimeout() map[TimeoutType]*utils.Timeout {

// startViewChange start the view change process
func (consensus *Consensus) startViewChange() {
if consensus.disableViewChange || consensus.isBackup {
if consensus.disableViewChange || consensus.registry.IsBackup() {
return
}

Expand Down

0 comments on commit 98e103c

Please sign in to comment.