Fix quorum checking discrepancy

pull/1932/head
Rongjian Lan 5 years ago
parent fd4ff19fc3
commit 2160c37e96
  1. 12
      consensus/consensus_v2.go
  2. 24
      consensus/quorum/one-node-staked-vote.go
  3. 2
      node/worker/worker.go
  4. 3
      shard/shard_state.go

@ -366,11 +366,7 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
defer consensus.mutex.Unlock()
logger := utils.Logger().With().
Str("validatorPubKey", validatorPubKey.SerializeToHexStr()).Logger()
if consensus.Decider.IsQuorumAchieved(quorum.Prepare) {
// already have enough signatures
logger.Debug().Msg("[OnPrepare] Received Additional Prepare Message")
return
}
// proceed only when the message is not received before
signed := consensus.Decider.ReadSignature(quorum.Prepare, validatorPubKey)
if signed != nil {
@ -379,6 +375,12 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
return
}
if consensus.Decider.IsQuorumAchieved(quorum.Prepare) {
// already have enough signatures
logger.Debug().Msg("[OnPrepare] Received Additional Prepare Message")
return
}
// Check BLS signature for the multi-sig
var sign bls.Sign
err = sign.Deserialize(prepareSig)

@ -72,14 +72,12 @@ func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
Msgf("[IsQuorumAchievedByMask] currentTotalPower is nil")
return false
}
if (*currentTotalPower).LT(threshold) {
utils.Logger().Warn().
Msgf("[IsQuorumAchievedByMask] Not enough voting power: need %+v, have %+v", threshold, currentTotalPower)
return false
}
utils.Logger().Debug().
Msgf("[IsQuorumAchievedByMask] have enough voting power: need %+v, have %+v", threshold, currentTotalPower)
return true
utils.Logger().Info().
Str("policy", v.Policy().String()).
Str("threshold", threshold.String()).
Str("total-power-of-signers", currentTotalPower.String()).
Msg("[IsQuorumAchievedByMask] Checking quorum")
return (*currentTotalPower).GT(threshold)
}
func (v *stakedVoteWeight) computeCurrentTotalPower(p Phase) (*numeric.Dec, error) {
@ -104,16 +102,18 @@ func (v *stakedVoteWeight) computeCurrentTotalPower(p Phase) (*numeric.Dec, erro
// ComputeTotalPowerByMask computes the total power indicated by bitmap mask
func (v *stakedVoteWeight) computeTotalPowerByMask(mask *bls_cosi.Mask) *numeric.Dec {
currentTotalPower := numeric.ZeroDec()
pubKeys := mask.GetPubKeyFromMask(true)
pubKeys := mask.Publics
for _, key := range pubKeys {
w := shard.BlsPublicKey{}
err := w.FromLibBLSPublicKey(key)
if err != nil {
return nil
}
currentTotalPower = currentTotalPower.Add(
v.roster.Voters[w].EffectivePercent,
)
if enabled, err := mask.KeyEnabled(key); err == nil && enabled {
currentTotalPower = currentTotalPower.Add(
v.roster.Voters[w].EffectivePercent,
)
}
}
return &currentTotalPower
}

@ -263,7 +263,7 @@ func (w *Worker) GetNewEpoch() *big.Int {
epoch := new(big.Int).Set(parent.Header().Epoch())
shardState, err := parent.Header().GetShardState()
if err == nil && shardState.Epoch != nil {
if err == nil && shardState.Epoch != nil && w.config.IsStaking(shardState.Epoch) {
// For shard state of staking epochs, the shard state will have an epoch and it will decide the next epoch for following blocks
epoch = new(big.Int).Set(shardState.Epoch)
} else {

@ -160,6 +160,9 @@ func (ss *State) JSON() string {
// FindCommitteeByID returns the committee configuration for the given shard,
// or nil if the given shard is not found.
func (ss *State) FindCommitteeByID(shardID uint32) *Committee {
if ss == nil {
return nil
}
for committee := range ss.Shards {
if ss.Shards[committee].ShardID == shardID {
return &ss.Shards[committee]

Loading…
Cancel
Save