add debug flag to avoid too much log info in crosslink verification (#2021)

pull/2028/head
chaosma 5 years ago committed by Edgar Aroutiounian
parent 887eeaef75
commit 56dc8e04d8
  1. 2
      consensus/consensus_service.go
  2. 4
      consensus/consensus_v2.go
  3. 4
      consensus/quorum/one-node-one-vote.go
  4. 36
      consensus/quorum/one-node-staked-vote.go
  5. 4
      consensus/quorum/one-node-staked-vote_test.go
  6. 4
      consensus/quorum/quorum.go
  7. 6
      consensus/view_change.go
  8. 8
      internal/chain/engine.go
  9. 8
      node/node_cross_link.go
  10. 2
      node/node_explorer.go

@ -548,7 +548,7 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
// Update voters in the committee // Update voters in the committee
if _, err := consensus.Decider.SetVoters( if _, err := consensus.Decider.SetVoters(
committeeToSet.Slots, committeeToSet.Slots, true,
); err != nil { ); err != nil {
utils.Logger().Error(). utils.Logger().Error().
Err(err). Err(err).

@ -518,7 +518,7 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
return return
} }
if !consensus.Decider.IsQuorumAchievedByMask(mask) { if !consensus.Decider.IsQuorumAchievedByMask(mask, true) {
consensus.getLogger().Warn(). consensus.getLogger().Warn().
Msgf("[OnPrepared] Quorum Not achieved") Msgf("[OnPrepared] Quorum Not achieved")
return return
@ -904,7 +904,7 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
return return
} }
if !consensus.Decider.IsQuorumAchievedByMask(mask) { if !consensus.Decider.IsQuorumAchievedByMask(mask, true) {
consensus.getLogger().Warn(). consensus.getLogger().Warn().
Msgf("[OnCommitted] Quorum Not achieved") Msgf("[OnCommitted] Quorum Not achieved")
return return

@ -35,7 +35,7 @@ func (v *uniformVoteWeight) IsQuorumAchieved(p Phase) bool {
} }
// IsQuorumAchivedByMask .. // IsQuorumAchivedByMask ..
func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool { func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask, debug bool) bool {
threshold := v.TwoThirdsSignersCount() threshold := v.TwoThirdsSignersCount()
currentTotalPower := utils.CountOneBits(mask.Bitmap) currentTotalPower := utils.CountOneBits(mask.Bitmap)
if currentTotalPower < threshold { if currentTotalPower < threshold {
@ -60,7 +60,7 @@ func (v *uniformVoteWeight) IsRewardThresholdAchieved() bool {
} }
func (v *uniformVoteWeight) SetVoters( func (v *uniformVoteWeight) SetVoters(
shard.SlotList, shard.SlotList, bool,
) (*TallyResult, error) { ) (*TallyResult, error) {
// NO-OP do not add anything here // NO-OP do not add anything here
return nil, nil return nil, nil

@ -73,19 +73,23 @@ func (v *stakedVoteWeight) IsQuorumAchieved(p Phase) bool {
} }
// IsQuorumAchivedByMask .. // IsQuorumAchivedByMask ..
func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool { func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask, debug bool) bool {
threshold := v.QuorumThreshold() threshold := v.QuorumThreshold()
currentTotalPower := v.computeTotalPowerByMask(mask) currentTotalPower := v.computeTotalPowerByMask(mask)
if currentTotalPower == nil { if currentTotalPower == nil {
utils.Logger().Warn(). if debug { // temp for remove debug info on crosslink verification
Msgf("[IsQuorumAchievedByMask] currentTotalPower is nil") utils.Logger().Warn().
Msgf("[IsQuorumAchievedByMask] currentTotalPower is nil")
}
return false return false
} }
utils.Logger().Info(). if debug {
Str("policy", v.Policy().String()). utils.Logger().Info().
Str("threshold", threshold.String()). Str("policy", v.Policy().String()).
Str("total-power-of-signers", currentTotalPower.String()). Str("threshold", threshold.String()).
Msg("[IsQuorumAchievedByMask] Checking quorum") Str("total-power-of-signers", currentTotalPower.String()).
Msg("[IsQuorumAchievedByMask] Checking quorum")
}
return (*currentTotalPower).GT(threshold) return (*currentTotalPower).GT(threshold)
} }
@ -169,7 +173,7 @@ var (
) )
func (v *stakedVoteWeight) SetVoters( func (v *stakedVoteWeight) SetVoters(
staked shard.SlotList, staked shard.SlotList, debug bool,
) (*TallyResult, error) { ) (*TallyResult, error) {
s, _ := v.ShardIDProvider()() s, _ := v.ShardIDProvider()()
v.ResetPrepareAndCommitVotes() v.ResetPrepareAndCommitVotes()
@ -179,12 +183,14 @@ func (v *stakedVoteWeight) SetVoters(
if err != nil { if err != nil {
return nil, err return nil, err
} }
utils.Logger().Info(). if debug {
Str("our-percentage", roster.OurVotingPowerTotalPercentage.String()). utils.Logger().Info().
Str("their-percentage", roster.TheirVotingPowerTotalPercentage.String()). Str("our-percentage", roster.OurVotingPowerTotalPercentage.String()).
Uint32("on-shard", s). Str("their-percentage", roster.TheirVotingPowerTotalPercentage.String()).
Str("Raw-Staked", roster.RawStakedTotal.String()). Uint32("on-shard", s).
Msg("Total staked") Str("Raw-Staked", roster.RawStakedTotal.String()).
Msg("Total staked")
}
// Hold onto this calculation // Hold onto this calculation
v.roster = *roster v.roster = *roster

@ -66,7 +66,7 @@ func setupBaseCase() (Decider, *TallyResult, shard.SlotList, map[string]secretKe
decider := NewDecider(SuperMajorityStake) decider := NewDecider(SuperMajorityStake)
decider.SetShardIDProvider(func() (uint32, error) { return 0, nil }) decider.SetShardIDProvider(func() (uint32, error) { return 0, nil })
decider.UpdateParticipants(pubKeys) decider.UpdateParticipants(pubKeys)
tally, err := decider.SetVoters(slotList) tally, err := decider.SetVoters(slotList, false)
if err != nil { if err != nil {
panic("Unable to SetVoters for Base Case") panic("Unable to SetVoters for Base Case")
} }
@ -92,7 +92,7 @@ func setupEdgeCase() (Decider, *TallyResult, shard.SlotList, secretKeyMap) {
decider := NewDecider(SuperMajorityStake) decider := NewDecider(SuperMajorityStake)
decider.SetShardIDProvider(func() (uint32, error) { return 0, nil }) decider.SetShardIDProvider(func() (uint32, error) { return 0, nil })
decider.UpdateParticipants(pubKeys) decider.UpdateParticipants(pubKeys)
tally, err := decider.SetVoters(slotList) tally, err := decider.SetVoters(slotList, false)
if err != nil { if err != nil {
panic("Unable to SetVoters for Edge Case") panic("Unable to SetVoters for Edge Case")
} }

@ -111,10 +111,10 @@ type Decider interface {
slash.Slasher slash.Slasher
WithJSONDump WithJSONDump
ToggleActive(*bls.PublicKey) bool ToggleActive(*bls.PublicKey) bool
SetVoters(shard.SlotList) (*TallyResult, error) SetVoters(shard.SlotList, bool) (*TallyResult, error)
Policy() Policy Policy() Policy
IsQuorumAchieved(Phase) bool IsQuorumAchieved(Phase) bool
IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool IsQuorumAchievedByMask(mask *bls_cosi.Mask, debug bool) bool
QuorumThreshold() numeric.Dec QuorumThreshold() numeric.Dec
AmIMemberOfCommitee() bool AmIMemberOfCommitee() bool
IsRewardThresholdAchieved() bool IsRewardThresholdAchieved() bool

@ -280,7 +280,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
return return
} }
if !consensus.Decider.IsQuorumAchievedByMask(mask) { if !consensus.Decider.IsQuorumAchievedByMask(mask, true) {
consensus.getLogger().Warn(). consensus.getLogger().Warn().
Msgf("[onViewChange] Quorum Not achieved") Msgf("[onViewChange] Quorum Not achieved")
return return
@ -347,7 +347,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
Msg("[onViewChange]") Msg("[onViewChange]")
// received enough view change messages, change state to normal consensus // received enough view change messages, change state to normal consensus
if consensus.Decider.IsQuorumAchievedByMask(consensus.viewIDBitmap[recvMsg.ViewID]) { if consensus.Decider.IsQuorumAchievedByMask(consensus.viewIDBitmap[recvMsg.ViewID], true) {
consensus.current.SetMode(Normal) consensus.current.SetMode(Normal)
consensus.LeaderPubKey = consensus.PubKey consensus.LeaderPubKey = consensus.PubKey
consensus.ResetState() consensus.ResetState()
@ -443,7 +443,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
viewIDBytes := make([]byte, 8) viewIDBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(viewIDBytes, recvMsg.ViewID) binary.LittleEndian.PutUint64(viewIDBytes, recvMsg.ViewID)
if !consensus.Decider.IsQuorumAchievedByMask(m3Mask) { if !consensus.Decider.IsQuorumAchievedByMask(m3Mask, true) {
consensus.getLogger().Warn(). consensus.getLogger().Warn().
Msgf("[onNewView] Quorum Not achieved") Msgf("[onNewView] Quorum Not achieved")
return return

@ -226,8 +226,8 @@ func (e *engineImpl) VerifySeal(chain engine.ChainReader, header *block.Header)
d.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) { d.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) {
return nil, nil return nil, nil
}) })
d.SetVoters(slotList.FindCommitteeByID(parentHeader.ShardID()).Slots) d.SetVoters(slotList.FindCommitteeByID(parentHeader.ShardID()).Slots, true)
if !d.IsQuorumAchievedByMask(mask) { if !d.IsQuorumAchievedByMask(mask, true) {
return ctxerror.New( return ctxerror.New(
"[VerifySeal] Not enough voting power in LastCommitSignature from Block Header", "[VerifySeal] Not enough voting power in LastCommitSignature from Block Header",
) )
@ -358,8 +358,8 @@ func (e *engineImpl) VerifyHeaderWithSignature(chain engine.ChainReader, header
d.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) { d.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) {
return nil, nil return nil, nil
}) })
d.SetVoters(slotList.FindCommitteeByID(header.ShardID()).Slots) d.SetVoters(slotList.FindCommitteeByID(header.ShardID()).Slots, true)
if !d.IsQuorumAchievedByMask(mask) { if !d.IsQuorumAchievedByMask(mask, true) {
return ctxerror.New( return ctxerror.New(
"[VerifySeal] Not enough voting power in commitSignature from Block Header", "[VerifySeal] Not enough voting power in commitSignature from Block Header",
) )

@ -91,7 +91,7 @@ func (node *Node) ProcessCrossLinkMessage(msgPayload []byte) {
if err == nil && exist != nil { if err == nil && exist != nil {
// TODO: leader add double sign checking // TODO: leader add double sign checking
utils.Logger().Err(err). utils.Logger().Err(err).
Msgf("[ProcessingCrossLink] Cross Link already exists, pass. Block num: %d, shardID %d", cl.Number(), cl.ShardID()) Msgf("[ProcessingCrossLink] Cross Link already exists, pass. Beacon Epoch: %d, Block num: %d, Epoch: %d, shardID %d", node.Blockchain().CurrentHeader().Epoch(), cl.Number(), cl.Epoch(), cl.ShardID())
continue continue
} }
@ -133,7 +133,7 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
committee := shardState.FindCommitteeByID(cl.ShardID()) committee := shardState.FindCommitteeByID(cl.ShardID())
if err != nil || committee == nil { if err != nil || committee == nil {
return ctxerror.New("[VerifyCrossLink] Failed to read shard state for cross link", "shardID", cl.ShardID(), "blockNum", cl.BlockNum()).WithCause(err) return ctxerror.New("[VerifyCrossLink] Failed to read shard state for cross link", "beaconEpoch", node.Blockchain().CurrentHeader().Epoch(), "epoch", cl.Epoch(), "shardID", cl.ShardID(), "blockNum", cl.BlockNum()).WithCause(err)
} }
var committerKeys []*bls.PublicKey var committerKeys []*bls.PublicKey
@ -166,10 +166,10 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
decider.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) { decider.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) {
return nil, nil return nil, nil
}) })
if _, err := decider.SetVoters(committee.Slots); err != nil { if _, err := decider.SetVoters(committee.Slots, false); err != nil {
return ctxerror.New("[VerifyCrossLink] Cannot SetVoters for committee", "shardID", cl.ShardID()) return ctxerror.New("[VerifyCrossLink] Cannot SetVoters for committee", "shardID", cl.ShardID())
} }
if !decider.IsQuorumAchievedByMask(mask) { if !decider.IsQuorumAchievedByMask(mask, false) {
return ctxerror.New("[VerifyCrossLink] Not enough voting power for crosslink", "shardID", cl.ShardID()) return ctxerror.New("[VerifyCrossLink] Not enough voting power for crosslink", "shardID", cl.ShardID())
} }

@ -48,7 +48,7 @@ func (node *Node) ExplorerMessageHandler(payload []byte) {
return return
} }
if node.Consensus.Decider.IsQuorumAchievedByMask(mask) { if node.Consensus.Decider.IsQuorumAchievedByMask(mask, false) {
utils.Logger().Error().Msg("[Explorer] not have enough signature power") utils.Logger().Error().Msg("[Explorer] not have enough signature power")
return return
} }

Loading…
Cancel
Save