|
|
@ -480,27 +480,6 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { |
|
|
|
consensus.Decider.SetShardIDProvider(func() (uint32, error) { |
|
|
|
consensus.Decider.SetShardIDProvider(func() (uint32, error) { |
|
|
|
return consensus.ShardID, nil |
|
|
|
return consensus.ShardID, nil |
|
|
|
}) |
|
|
|
}) |
|
|
|
s, err := committee.WithStakingEnabled.ReadFromDB( |
|
|
|
|
|
|
|
nextEpoch, consensus.ChainReader, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Error(). |
|
|
|
|
|
|
|
Err(err). |
|
|
|
|
|
|
|
Uint32("shard", consensus.ShardID). |
|
|
|
|
|
|
|
Msg("Error when reading staking committee") |
|
|
|
|
|
|
|
return Syncing |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err := consensus.Decider.SetVoters( |
|
|
|
|
|
|
|
s.FindCommitteeByID(consensus.ShardID).Slots, |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
|
|
|
|
utils.Logger().Error(). |
|
|
|
|
|
|
|
Err(err). |
|
|
|
|
|
|
|
Uint32("shard", consensus.ShardID). |
|
|
|
|
|
|
|
Msg("Error when updating voting power") |
|
|
|
|
|
|
|
return Syncing |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils.Logger().Info(). |
|
|
|
utils.Logger().Info(). |
|
|
|
Uint64("block-number", curHeader.Number().Uint64()). |
|
|
|
Uint64("block-number", curHeader.Number().Uint64()). |
|
|
@ -511,7 +490,7 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { |
|
|
|
Msg("changing committee") |
|
|
|
Msg("changing committee") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pubKeys := []*bls.PublicKey{} |
|
|
|
committeeToSet := &shard.Committee{} |
|
|
|
hasError := false |
|
|
|
hasError := false |
|
|
|
|
|
|
|
|
|
|
|
// TODO: change GetCommitteePublicKeys to read from DB
|
|
|
|
// TODO: change GetCommitteePublicKeys to read from DB
|
|
|
@ -526,11 +505,6 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { |
|
|
|
return Syncing |
|
|
|
return Syncing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
curCommittee := curShardState.FindCommitteeByID(curHeader.ShardID()) |
|
|
|
|
|
|
|
curPubKeys := committee.WithStakingEnabled.GetCommitteePublicKeys( |
|
|
|
|
|
|
|
curCommittee, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
consensus.numPrevPubKeys = len(curPubKeys) |
|
|
|
|
|
|
|
consensus.getLogger().Info().Msg("[UpdateConsensusInformation] Updating.....") |
|
|
|
consensus.getLogger().Info().Msg("[UpdateConsensusInformation] Updating.....") |
|
|
|
if len(curHeader.ShardState()) > 0 { |
|
|
|
if len(curHeader.ShardState()) > 0 { |
|
|
|
// increase curEpoch by one if it's the last block
|
|
|
|
// increase curEpoch by one if it's the last block
|
|
|
@ -549,28 +523,40 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { |
|
|
|
return Syncing |
|
|
|
return Syncing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
nextCommittee := nextShardState.FindCommitteeByID(curHeader.ShardID()) |
|
|
|
committeeToSet = nextShardState.FindCommitteeByID(curHeader.ShardID()) |
|
|
|
pubKeys = committee.WithStakingEnabled.GetCommitteePublicKeys( |
|
|
|
|
|
|
|
nextCommittee, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
consensus.SetEpochNum(curEpoch.Uint64()) |
|
|
|
consensus.SetEpochNum(curEpoch.Uint64()) |
|
|
|
pubKeys = curPubKeys |
|
|
|
committeeToSet = curShardState.FindCommitteeByID(curHeader.ShardID()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(pubKeys) == 0 { |
|
|
|
if len(committeeToSet.Slots) == 0 { |
|
|
|
consensus.getLogger().Warn(). |
|
|
|
consensus.getLogger().Warn(). |
|
|
|
Msg("[UpdateConsensusInformation] PublicKeys is Nil") |
|
|
|
Msg("[UpdateConsensusInformation] No members in the committee to update") |
|
|
|
hasError = true |
|
|
|
hasError = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// update public keys committee
|
|
|
|
// update public keys in the committee
|
|
|
|
oldLeader := consensus.LeaderPubKey |
|
|
|
oldLeader := consensus.LeaderPubKey |
|
|
|
|
|
|
|
pubKeys := committee.WithStakingEnabled.GetCommitteePublicKeys( |
|
|
|
|
|
|
|
committeeToSet, |
|
|
|
|
|
|
|
) |
|
|
|
consensus.getLogger().Info(). |
|
|
|
consensus.getLogger().Info(). |
|
|
|
Int("numPubKeys", len(pubKeys)). |
|
|
|
Int("numPubKeys", len(pubKeys)). |
|
|
|
Msg("[UpdateConsensusInformation] Successfully updated public keys") |
|
|
|
Msg("[UpdateConsensusInformation] Successfully updated public keys") |
|
|
|
consensus.UpdatePublicKeys(pubKeys) |
|
|
|
consensus.UpdatePublicKeys(pubKeys) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update voters in the committee
|
|
|
|
|
|
|
|
if _, err := consensus.Decider.SetVoters( |
|
|
|
|
|
|
|
committeeToSet.Slots, |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
|
|
|
|
utils.Logger().Error(). |
|
|
|
|
|
|
|
Err(err). |
|
|
|
|
|
|
|
Uint32("shard", consensus.ShardID). |
|
|
|
|
|
|
|
Msg("Error when updating voters") |
|
|
|
|
|
|
|
return Syncing |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// take care of possible leader change during the curEpoch
|
|
|
|
// take care of possible leader change during the curEpoch
|
|
|
|
if !shard.Schedule.IsLastBlock(curHeader.Number().Uint64()) && |
|
|
|
if !shard.Schedule.IsLastBlock(curHeader.Number().Uint64()) && |
|
|
|
curHeader.Number().Uint64() != 0 { |
|
|
|
curHeader.Number().Uint64() != 0 { |
|
|
|