From 98e103cfcb926e818531778078c615c18d6db848 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:54:07 -0400 Subject: [PATCH] verify --- consensus/consensus.go | 6 +----- consensus/consensus_service.go | 4 ++-- consensus/consensus_v2.go | 2 +- consensus/validator.go | 4 ++-- consensus/view_change.go | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index 63f18a85e..9718ac185 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -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. @@ -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 { diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index d658fe83d..8e9479e93 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -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 diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 33ba54b1d..6c32337fa 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -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 } diff --git a/consensus/validator.go b/consensus/validator.go index 2f14f76b4..015bfb592 100644 --- a/consensus/validator.go +++ b/consensus/validator.go @@ -133,7 +133,7 @@ func (consensus *Consensus) validateNewBlock(recvMsg *FBFTMessage) (*types.Block } func (consensus *Consensus) prepare() { - if consensus.isBackup { + if consensus.registry.IsBackup() { return } @@ -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 } diff --git a/consensus/view_change.go b/consensus/view_change.go index f55c5400f..9e77b19b5 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -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 }