Skip to content

Commit

Permalink
Revert "Rotate all shards, but only hmy validators for beacon."
Browse files Browse the repository at this point in the history
This reverts commit 70b09e2.
  • Loading branch information
Frozen committed Mar 8, 2023
1 parent fa48a1c commit 66cfaa9
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 251 deletions.
18 changes: 7 additions & 11 deletions consensus/consensus_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,16 @@ 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) {
// Feature activated only for non-beacon shards.
if consensus.ShardID == shard.BeaconChainShardID {
return
}
var (
bc = consensus.Blockchain()
prev = consensus.getLeaderPubKey()
leader = consensus.getLeaderPubKey()
)
utils.Logger().Info().Msgf("[Rotating leader] epoch: %v rotation:%v external rotation %v", epoch.Uint64(), bc.Config().IsLeaderRotation(epoch), bc.Config().IsLeaderRotationExternalValidatorsAllowed(epoch, consensus.ShardID))
utils.Logger().Info().Msgf("[Rotating leader] epoch: %v rotation:%v ", epoch.Uint64(), bc.Config().IsNonBeaconLeaderRotation(epoch))
ss, err := bc.ReadShardState(epoch)
if err != nil {
utils.Logger().Error().Err(err).Msg("Failed to read shard state")
Expand Down Expand Up @@ -746,15 +750,7 @@ func (consensus *Consensus) rotateLeader(epoch *big.Int) {
// Passed all checks, we can change leader.
// NthNext will move the leader to the next leader in the committee.
// It does not know anything about external or internal validators.
var (
wasFound bool
next *bls.PublicKeyWrapper
)
if bc.Config().IsLeaderRotationExternalValidatorsAllowed(epoch, consensus.ShardID) {
wasFound, next = consensus.Decider.NthNext(leader, 1)
} else {
wasFound, next = consensus.Decider.NthNextHmy(shard.Schedule.InstanceForEpoch(epoch), leader, 1)
}
wasFound, next := consensus.Decider.NthNext(leader, 1)
if !wasFound {
utils.Logger().Error().Msg("Failed to get next leader")
return
Expand All @@ -780,7 +776,7 @@ func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg
} else {
epoch = blk.Epoch()
}
if consensus.Blockchain().Config().IsLeaderRotation(epoch) {
if consensus.Blockchain().Config().IsNonBeaconLeaderRotation(epoch) {
consensus.rotateLeader(epoch)
}

Expand Down
10 changes: 5 additions & 5 deletions consensus/view_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ func (consensus *Consensus) getNextLeaderKey(viewID uint64) *bls.PublicKeyWrappe
// FIXME: rotate leader on harmony nodes only before fully externalization
var wasFound bool
var next *bls.PublicKeyWrapper
if blockchain != nil && blockchain.Config().IsLeaderRotation(epoch) {
if blockchain.Config().IsLeaderRotationExternalValidatorsAllowed(epoch, consensus.ShardID) {
wasFound, next = consensus.Decider.NthNext(
if blockchain != nil && blockchain.Config().IsNonBeaconLeaderRotation(epoch) {
if consensus.ShardID == shard.BeaconChainShardID {
wasFound, next = consensus.Decider.NthNextHmy(
shard.Schedule.InstanceForEpoch(epoch),
lastLeaderPubKey,
gap)
} else {
wasFound, next = consensus.Decider.NthNextHmy(
shard.Schedule.InstanceForEpoch(epoch),
wasFound, next = consensus.Decider.NthNext(
lastLeaderPubKey,
gap)
}
Expand Down
Loading

0 comments on commit 66cfaa9

Please sign in to comment.