Avoid duplicate bls as harmony nodes; Fix epoch gap issue (#2964)

pull/2968/head
Rongjian Lan 5 years ago committed by GitHub
parent ee31573c1c
commit 211ed79888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      consensus/consensus_service.go
  2. 1
      consensus/votepower/roster.go
  3. 14
      shard/committee/assignment.go
  4. 3
      staking/effective/calculate.go

@ -422,6 +422,18 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
curHeader := consensus.ChainReader.CurrentHeader()
curEpoch := curHeader.Epoch()
nextEpoch := new(big.Int).Add(curHeader.Epoch(), common.Big1)
// Overwrite nextEpoch if the shard state has a epoch number
if len(curHeader.ShardState()) > 0 {
nextShardState, err := curHeader.GetShardState()
if err != nil {
return Syncing
}
if nextShardState.Epoch != nil {
nextEpoch = nextShardState.Epoch
}
}
isFirstTimeStaking := consensus.ChainReader.Config().IsStaking(nextEpoch) &&
len(curHeader.ShardState()) > 0 &&
!consensus.ChainReader.Config().IsStaking(curEpoch)
@ -529,9 +541,8 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
Uint32("shard-id", consensus.ShardID).
Msg("[UpdateConsensusInformation] changing committee")
// take care of possible leader change during the curEpoch
if !shard.Schedule.IsLastBlock(curHeader.Number().Uint64()) &&
curHeader.Number().Uint64() != 0 {
// take care of possible leader change during the epoch
if len(curHeader.ShardState()) == 0 && curHeader.Number().Uint64() != 0 {
leaderPubKey, err := consensus.getLeaderPubKeyFromCoinbase(curHeader)
if err != nil || leaderPubKey == nil {
consensus.getLogger().Debug().Err(err).

@ -207,7 +207,6 @@ func Compute(subComm *shard.Committee, epoch *big.Int) (*Roster, error) {
ourPercentage = ourPercentage.Add(member.OverallPercent)
}
// TODO: make sure external user's BLS key can be same as harmony's bls keys
if _, ok := roster.Voters[staked[i].BLSPublicKey]; !ok {
roster.Voters[staked[i].BLSPublicKey] = &member
} else {

@ -129,6 +129,20 @@ func prepareOrders(
essentials := map[common.Address]*effective.SlotOrder{}
totalStaked, tempZero := big.NewInt(0), numeric.ZeroDec()
// Avoid duplicate BLS keys as harmony nodes
instance := shard.Schedule.InstanceForEpoch(stakedReader.CurrentBlock().Epoch())
for _, account := range instance.HmyAccounts() {
pub := &bls.PublicKey{}
if err := pub.DeserializeHexStr(account.BLSPublicKey); err != nil {
continue
}
pubKey := shard.BLSPublicKey{}
if err := pubKey.FromLibBLSPublicKey(pub); err != nil {
continue
}
blsKeys[pubKey] = struct{}{}
}
for i := range candidates {
validator, err := stakedReader.ReadValidatorInformation(
candidates[i],

@ -110,6 +110,9 @@ func Compute(
// Expand
for _, staker := range shorter {
slotsCount := len(staker.slot.SpreadAmong)
if slotsCount == 0 {
continue
}
spread := numeric.NewDecFromBigInt(staker.slot.Stake).
QuoInt64(int64(slotsCount))
for i := 0; i < slotsCount; i++ {

Loading…
Cancel
Save