fix/backup-initialization
frozen 9 months ago
parent fa5efdc5dc
commit 98e103cfcb
No known key found for this signature in database
GPG Key ID: 5391C63E79B03EDE
  1. 6
      consensus/consensus.go
  2. 4
      consensus/consensus_service.go
  3. 2
      consensus/consensus_v2.go
  4. 4
      consensus/validator.go
  5. 2
      consensus/view_change.go

@ -53,8 +53,6 @@ type Consensus struct {
phase FBFTPhase phase FBFTPhase
// current indicates what state a node is in // current indicates what state a node is in
current State current State
// isBackup declarative the node is in backup mode
isBackup bool
// 2 types of timeouts: normal and viewchange // 2 types of timeouts: normal and viewchange
consensusTimeout map[TimeoutType]*utils.Timeout consensusTimeout map[TimeoutType]*utils.Timeout
// Commits collected from validators. // Commits collected from validators.
@ -254,9 +252,7 @@ func (consensus *Consensus) getConsensusLeaderPrivateKey() (*bls.PrivateKeyWrapp
} }
func (consensus *Consensus) IsBackup() bool { func (consensus *Consensus) IsBackup() bool {
consensus.mutex.RLock() return consensus.registry.IsBackup()
defer consensus.mutex.RUnlock()
return consensus.isBackup
} }
func (consensus *Consensus) BlockNum() uint64 { func (consensus *Consensus) BlockNum() uint64 {

@ -199,11 +199,11 @@ func (consensus *Consensus) setMode(m Mode) {
// SetIsBackup sets the mode of consensus // SetIsBackup sets the mode of consensus
func (consensus *Consensus) SetIsBackup(isBackup bool) { func (consensus *Consensus) SetIsBackup(isBackup bool) {
consensus.mutex.Lock() consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Bool("IsBackup", isBackup). Bool("IsBackup", isBackup).
Msg("[SetIsBackup]") Msg("[SetIsBackup]")
consensus.isBackup = isBackup consensus.mutex.Unlock()
consensus.registry.SetIsBackup(isBackup)
} }
// Mode returns the mode of consensus // Mode returns the mode of consensus

@ -106,7 +106,7 @@ func (consensus *Consensus) HandleMessageUpdate(ctx context.Context, peer libp2p
consensus.isLeader() consensus.isLeader()
// if in backup normal mode, force ignore view change event and leader event. // if in backup normal mode, force ignore view change event and leader event.
if consensus.isBackup { if consensus.registry.IsBackup() {
canHandleViewChange = false canHandleViewChange = false
intendedForLeader = false intendedForLeader = false
} }

@ -133,7 +133,7 @@ func (consensus *Consensus) validateNewBlock(recvMsg *FBFTMessage) (*types.Block
} }
func (consensus *Consensus) prepare() { func (consensus *Consensus) prepare() {
if consensus.isBackup { if consensus.registry.IsBackup() {
return return
} }
@ -152,7 +152,7 @@ func (consensus *Consensus) prepare() {
// sendCommitMessages send out commit messages to leader // sendCommitMessages send out commit messages to leader
func (consensus *Consensus) sendCommitMessages(blockObj *types.Block) { func (consensus *Consensus) sendCommitMessages(blockObj *types.Block) {
if consensus.isBackup || blockObj == nil { if consensus.IsBackup() || blockObj == nil {
return return
} }

@ -231,7 +231,7 @@ func createTimeout() map[TimeoutType]*utils.Timeout {
// startViewChange start the view change process // startViewChange start the view change process
func (consensus *Consensus) startViewChange() { func (consensus *Consensus) startViewChange() {
if consensus.disableViewChange || consensus.isBackup { if consensus.disableViewChange || consensus.registry.IsBackup() {
return return
} }

Loading…
Cancel
Save