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

Isbackup initialization with provided value. #4644

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
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
5 changes: 3 additions & 2 deletions consensus/consensus_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ 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() {
consensus.getLogger().Info().Msgf("IsBackup: true")
canHandleViewChange = false
intendedForLeader = false
}
Expand Down Expand Up @@ -424,7 +425,7 @@ func (consensus *Consensus) BlockChannel(newBlock *types.Block) {
Msg("[ConsensusMainLoop] Received Proposed New Block!")

if newBlock.NumberU64() < consensus.BlockNum() {
consensus.getLogger().Warn().Uint64("newBlockNum", newBlock.NumberU64()).
consensus.GetLogger().Warn().Uint64("newBlockNum", newBlock.NumberU64()).
Msg("[ConsensusMainLoop] received old block, abort")
return
}
Expand Down
4 changes: 4 additions & 0 deletions consensus/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (

// announce fires leader
func (consensus *Consensus) announce(block *types.Block) {
if consensus.registry.IsBackup() {
consensus.getLogger().Warn().Msg("[Announce] I am a backup node")
return
}
blockHash := block.Hash()

// prepare message and broadcast to validators
Expand Down
8 changes: 6 additions & 2 deletions consensus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
)

func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
if consensus.registry.IsBackup() {
return
}
recvMsg, err := consensus.parseFBFTMessage(msg)
if err != nil {
consensus.getLogger().Error().
Expand Down Expand Up @@ -133,7 +136,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 +155,8 @@ 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 {
Frozen marked this conversation as resolved.
Show resolved Hide resolved
consensus.getLogger().Warn().Msg("[sendCommitMessages] I am a backup node, will not send commit message")
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