|
|
|
@ -460,16 +460,6 @@ func (consensus *Consensus) BlockChannel(newBlock *types.Block) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Close closes the consensus. If current is in normal commit phase, wait until the commit
|
|
|
|
|
// phase end.
|
|
|
|
|
func (consensus *Consensus) Close() error { |
|
|
|
|
if consensus.dHelper != nil { |
|
|
|
|
consensus.dHelper.close() |
|
|
|
|
} |
|
|
|
|
consensus.waitForCommit() |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// waitForCommit wait extra 2 seconds for commit phase to finish
|
|
|
|
|
func (consensus *Consensus) waitForCommit() { |
|
|
|
|
if consensus.Mode() != Normal || consensus.phase.Get() != FBFTCommit { |
|
|
|
@ -717,11 +707,11 @@ func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMess |
|
|
|
|
// rotateLeader rotates the leader to the next leader in the committee.
|
|
|
|
|
// This function must be called with enabled leader rotation.
|
|
|
|
|
func (consensus *Consensus) rotateLeader(epoch *big.Int) { |
|
|
|
|
prev := consensus.GetLeaderPubKey() |
|
|
|
|
prev := consensus.getLeaderPubKey() |
|
|
|
|
bc := consensus.Blockchain() |
|
|
|
|
curNumber := bc.CurrentHeader().Number().Uint64() |
|
|
|
|
utils.Logger().Info().Msgf("[Rotating leader] epoch: %v rotation:%v numblocks:%d", epoch.Uint64(), bc.Config().IsLeaderRotation(epoch), bc.Config().LeaderRotationBlocksCount) |
|
|
|
|
leader := consensus.GetLeaderPubKey() |
|
|
|
|
leader := consensus.getLeaderPubKey() |
|
|
|
|
for i := 0; i < bc.Config().LeaderRotationBlocksCount; i++ { |
|
|
|
|
header := bc.GetHeaderByNumber(curNumber - uint64(i)) |
|
|
|
|
if header == nil { |
|
|
|
@ -748,9 +738,9 @@ func (consensus *Consensus) rotateLeader(epoch *big.Int) { |
|
|
|
|
utils.Logger().Error().Msg("Failed to get next leader") |
|
|
|
|
return |
|
|
|
|
} else { |
|
|
|
|
consensus.SetLeaderPubKey(next) |
|
|
|
|
consensus.setLeaderPubKey(next) |
|
|
|
|
} |
|
|
|
|
if consensus.IsLeader() && !consensus.GetLeaderPubKey().Object.IsEqual(prev.Object) { |
|
|
|
|
if consensus.isLeader() && !consensus.getLeaderPubKey().Object.IsEqual(prev.Object) { |
|
|
|
|
// leader changed
|
|
|
|
|
go func() { |
|
|
|
|
consensus.ReadySignal <- SyncProposal |
|
|
|
|