Got rid of redundant logic with isBackup. (#4639)

feature/dev-clear-stake-031024
Konstantin 9 months ago committed by GitHub
parent 56ad3fa6b9
commit 8d2b36d7f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      consensus/consensus.go
  2. 7
      consensus/consensus_service.go
  3. 2
      consensus/consensus_v2.go
  4. 3
      consensus/enums.go
  5. 4
      consensus/validator.go
  6. 10
      consensus/view_change.go

@ -254,6 +254,8 @@ func (consensus *Consensus) getConsensusLeaderPrivateKey() (*bls.PrivateKeyWrapp
} }
func (consensus *Consensus) IsBackup() bool { func (consensus *Consensus) IsBackup() bool {
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.isBackup return consensus.isBackup
} }

@ -190,10 +190,6 @@ func (consensus *Consensus) SetMode(m Mode) {
// SetMode sets the mode of consensus // SetMode sets the mode of consensus
func (consensus *Consensus) setMode(m Mode) { func (consensus *Consensus) setMode(m Mode) {
if m == Normal && consensus.isBackup {
m = NormalBackup
}
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Str("Mode", m.String()). Str("Mode", m.String()).
Msg("[SetMode]") Msg("[SetMode]")
@ -202,11 +198,12 @@ 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()
defer consensus.mutex.Unlock()
consensus.getLogger().Debug(). consensus.getLogger().Debug().
Bool("IsBackup", isBackup). Bool("IsBackup", isBackup).
Msg("[SetIsBackup]") Msg("[SetIsBackup]")
consensus.isBackup = isBackup consensus.isBackup = isBackup
consensus.current.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.current.Mode() == NormalBackup { if consensus.isBackup {
canHandleViewChange = false canHandleViewChange = false
intendedForLeader = false intendedForLeader = false
} }

@ -14,8 +14,6 @@ const (
Syncing Syncing
// Listening .. // Listening ..
Listening Listening
// NormalBackup Backup Node ..
NormalBackup
) )
// FBFTPhase : different phases of consensus // FBFTPhase : different phases of consensus
@ -34,7 +32,6 @@ var (
ViewChanging: "ViewChanging", ViewChanging: "ViewChanging",
Syncing: "Syncing", Syncing: "Syncing",
Listening: "Listening", Listening: "Listening",
NormalBackup: "NormalBackup",
} }
phaseNames = map[FBFTPhase]string{ phaseNames = map[FBFTPhase]string{
FBFTAnnounce: "Announce", FBFTAnnounce: "Announce",

@ -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.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
} }

@ -33,8 +33,6 @@ type State struct {
// view changing id is used during view change mode // view changing id is used during view change mode
// it is the next view id // it is the next view id
viewChangingID uint64 viewChangingID uint64
isBackup bool
} }
// Mode return the current node mode // Mode return the current node mode
@ -44,10 +42,6 @@ func (pm *State) Mode() Mode {
// SetMode set the node mode as required // SetMode set the node mode as required
func (pm *State) SetMode(s Mode) { func (pm *State) SetMode(s Mode) {
if s == Normal && pm.isBackup {
s = NormalBackup
}
pm.mode = s pm.mode = s
} }
@ -81,10 +75,6 @@ func (pm *State) GetViewChangeDuraion() time.Duration {
return time.Duration(diff * diff * int64(viewChangeDuration)) return time.Duration(diff * diff * int64(viewChangeDuration))
} }
func (pm *State) SetIsBackup(isBackup bool) {
pm.isBackup = isBackup
}
// fallbackNextViewID return the next view ID and duration when there is an exception // fallbackNextViewID return the next view ID and duration when there is an exception
// to calculate the time-based viewId // to calculate the time-based viewId
func (consensus *Consensus) fallbackNextViewID() (uint64, time.Duration) { func (consensus *Consensus) fallbackNextViewID() (uint64, time.Duration) {

Loading…
Cancel
Save