pull/4509/head
frozen 2 years ago committed by Casey Gardiner
parent 1b64682f1c
commit f907c70920
  1. 1
      consensus/consensus.go
  2. 34
      consensus/consensus_service.go
  3. 2
      consensus/consensus_v2.go

@ -74,6 +74,7 @@ type Consensus struct {
// blockNum: the next blockNumber that FBFT is going to agree on,
// should be equal to the blockNumber of next block
blockNum uint64
epoch uint64
// Blockhash - 32 byte
blockHash [32]byte
// Block to run consensus on

@ -82,6 +82,7 @@ func (consensus *Consensus) UpdatePublicKeys(pubKeys, allowlist []bls_cosi.Publi
func (consensus *Consensus) updatePublicKeys(pubKeys, allowlist []bls_cosi.PublicKeyWrapper) int64 {
consensus.Decider.UpdateParticipants(pubKeys, allowlist)
consensus.pubKeyLock.Unlock()
consensus.getLogger().Info().Msg("My Committee updated")
for i := range pubKeys {
consensus.getLogger().Info().
@ -89,15 +90,22 @@ func (consensus *Consensus) updatePublicKeys(pubKeys, allowlist []bls_cosi.Publi
Str("BLSPubKey", pubKeys[i].Bytes.Hex()).
Msg("Member")
}
allKeys := consensus.Decider.Participants()
if len(allKeys) != 0 {
consensus.LeaderPubKey = &allKeys[0]
consensus.getLogger().Info().
Str("info", consensus.LeaderPubKey.Bytes.Hex()).Msg("My Leader")
if consensus.Blockchain.Config().IsLeaderRotation(consensus.GetCurEpoch()) {
consensus.updateLeader()
} else {
consensus.getLogger().Error().
Msg("[UpdatePublicKeys] Participants is empty")
consensus.pubKeyLock.Lock()
allKeys := consensus.Decider.Participants()
consensus.pubKeyLock.Unlock()
if len(allKeys) != 0 {
consensus.pubKeyLock.Lock()
consensus.LeaderPubKey = &allKeys[0]
consensus.pubKeyLock.Unlock()
consensus.getLogger().Info().
Str("info", consensus.LeaderPubKey.Bytes.Hex()).Msg("My Leader")
} else {
consensus.getLogger().Error().
Msg("[UpdatePublicKeys] Participants is empty")
}
}
// reset states after update public keys
// TODO: incorporate bitmaps in the decider, so their state can't be inconsistent.
@ -658,3 +666,13 @@ func (consensus *Consensus) getLogger() *zerolog.Logger {
Logger()
return &logger
}
func UpdatePublicKeyDefault(consensus *Consensus) {
if allKeys := consensus.Decider.Participants(); len(allKeys) > 0 {
consensus.LeaderPubKey = &allKeys[0]
}
}
func UpdatePublicKeyRotate(consensus *Consensus) {
//consensus
}

@ -778,7 +778,7 @@ func (consensus *Consensus) getEpochFirstBlockViewID(epoch *big.Int) (uint64, er
if epoch.Uint64() == 0 {
return 0, nil
}
epochBlock := consensus.Blockchain.GetBlockByNumber(epoch.Uint64() - 1)
epochBlock := consensus.Blockchain.GetBlockByNumber(shard.Schedule.EpochLastBlock(epoch.Uint64() - 1))
if epochBlock == nil {
return 0, errors.Errorf("block not found for number %d", epoch.Uint64()-1)
}

Loading…
Cancel
Save