Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got rid of redundant logic with isBackup. #4639

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ func (consensus *Consensus) getConsensusLeaderPrivateKey() (*bls.PrivateKeyWrapp
}

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

Expand Down
7 changes: 2 additions & 5 deletions consensus/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ func (consensus *Consensus) SetMode(m Mode) {

// SetMode sets the mode of consensus
func (consensus *Consensus) setMode(m Mode) {
if m == Normal && consensus.isBackup {
m = NormalBackup
}

consensus.getLogger().Debug().
Str("Mode", m.String()).
Msg("[SetMode]")
Expand All @@ -203,11 +199,12 @@ 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.current.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.current.Mode() == NormalBackup {
if consensus.isBackup {
canHandleViewChange = false
intendedForLeader = false
}
Expand Down
3 changes: 0 additions & 3 deletions consensus/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const (
Syncing
// Listening ..
Listening
// NormalBackup Backup Node ..
NormalBackup
)

// FBFTPhase : different phases of consensus
Expand All @@ -34,7 +32,6 @@ var (
ViewChanging: "ViewChanging",
Syncing: "Syncing",
Listening: "Listening",
NormalBackup: "NormalBackup",
}
phaseNames = map[FBFTPhase]string{
FBFTAnnounce: "Announce",
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.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
10 changes: 0 additions & 10 deletions consensus/view_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type State struct {
// view changing id is used during view change mode
// it is the next view id
viewChangingID uint64

isBackup bool
}

// Mode return the current node mode
Expand All @@ -44,10 +42,6 @@ func (pm *State) Mode() Mode {

// SetMode set the node mode as required
func (pm *State) SetMode(s Mode) {
if s == Normal && pm.isBackup {
s = NormalBackup
}

pm.mode = s
}

Expand Down Expand Up @@ -81,10 +75,6 @@ func (pm *State) GetViewChangeDuraion() time.Duration {
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
// to calculate the time-based viewId
func (consensus *Consensus) fallbackNextViewID() (uint64, time.Duration) {
Expand Down