From d57877d1ea7c6350a7752f0ddbcecb5f14d0ce3b Mon Sep 17 00:00:00 2001 From: Shogo Hyodo Date: Tue, 6 Dec 2022 16:13:11 +0900 Subject: [PATCH] Fix inconsistencies --- test/maverick/consensus/state.go | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 0d3648ff7..33321c2d0 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -1570,14 +1570,14 @@ 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 { @@ -1585,12 +1585,12 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { // 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 { @@ -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) { @@ -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)