Skip to content

Commit

Permalink
Fix inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ulbqb committed Dec 6, 2022
1 parent 160e52f commit d57877d
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions test/maverick/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1570,27 +1570,27 @@ func (cs *State) pruneBlocks(retainHeight int64) (uint64, error) {
}

func (cs *State) recordMetrics(height int64, block *types.Block) {
cs.metrics.Voters.Set(float64(cs.Validators.Size()))
cs.metrics.VotersPower.Set(float64(cs.Validators.TotalVotingPower()))
cs.metrics.Voters.Set(float64(cs.Voters.Size()))
cs.metrics.VotersPower.Set(float64(types.NewValidatorSet(cs.Voters.Voters).TotalVotingPower()))

var (
missingValidators int
missingValidatorsPower int64
missingVoters int
missingVotersPower int64
)
// height=0 -> MissingValidators and MissingValidatorsPower are both 0.
// height=0 -> missingVoters and missingVotersPower are both 0.
// Remember that the first LastCommit is intentionally empty, so it's not
// fair to increment missing validators number.
if height > cs.state.InitialHeight {
// Sanity check that commit size matches validator set size - only applies
// after first block.
var (
commitSize = block.LastCommit.Size()
valSetLen = len(cs.LastVoters.Voters)
votSetLen = cs.LastVoters.Size()
address types.Address
)
if commitSize != valSetLen {
panic(fmt.Sprintf("commit size (%d) doesn't match valset length (%d) at height %d\n\n%v\n\n%v",
commitSize, valSetLen, block.Height, block.LastCommit.Signatures, cs.LastVoters.Voters))
if commitSize != votSetLen {
panic(fmt.Sprintf("commit size (%d) doesn't match votset length (%d) at height %d\n\n%v\n\n%v",
commitSize, votSetLen, block.Height, block.LastCommit.Signatures, cs.LastVoters.Voters))
}

if cs.privValidator != nil {
Expand All @@ -1605,8 +1605,8 @@ func (cs *State) recordMetrics(height int64, block *types.Block) {
for i, val := range cs.LastVoters.Voters {
commitSig := block.LastCommit.Signatures[i]
if commitSig.Absent() {
missingValidators++
missingValidatorsPower += val.VotingPower
missingVoters++
missingVotersPower += val.VotingPower
}

if bytes.Equal(val.Address, address) {
Expand All @@ -1623,24 +1623,24 @@ func (cs *State) recordMetrics(height int64, block *types.Block) {

}
}
cs.metrics.MissingVoters.Set(float64(missingValidators))
cs.metrics.MissingVotersPower.Set(float64(missingValidatorsPower))
cs.metrics.MissingVoters.Set(float64(missingVoters))
cs.metrics.MissingVotersPower.Set(float64(missingVotersPower))

// NOTE: byzantine validators power and count is only for consensus evidence i.e. duplicate vote
var (
byzantineValidatorsPower = int64(0)
byzantineValidatorsCount = int64(0)
byzantineVotersPower = int64(0)
byzantineVotersCount = int64(0)
)
for _, ev := range block.Evidence.Evidence {
if dve, ok := ev.(*types.DuplicateVoteEvidence); ok {
if _, val := cs.Validators.GetByAddress(dve.VoteA.ValidatorAddress); val != nil {
byzantineValidatorsCount++
byzantineValidatorsPower += val.VotingPower
if _, bvot := cs.Validators.GetByAddress(dve.VoteA.ValidatorAddress); bvot != nil {
byzantineVotersCount++
byzantineVotersPower += bvot.VotingPower
}
}
}
cs.metrics.ByzantineVoters.Set(float64(byzantineValidatorsCount))
cs.metrics.ByzantineVotersPower.Set(float64(byzantineValidatorsPower))
cs.metrics.ByzantineVoters.Set(float64(byzantineVotersCount))
cs.metrics.ByzantineVotersPower.Set(float64(byzantineVotersPower))

if height > 1 {
lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
Expand Down

0 comments on commit d57877d

Please sign in to comment.