Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metrics): num of validators that didn't sign is always 0 #905

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions internal/consensus/state_apply_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,33 @@ func (c *ApplyCommitAction) Execute(ctx context.Context, stateEvent StateEvent)
}

func (c *ApplyCommitAction) RecordMetrics(stateData *StateData, height int64, block *types.Block, lastBlockMeta *types.BlockMeta) {
c.metrics.Validators.Set(float64(stateData.Validators.Size()))
c.metrics.ValidatorsPower.Set(float64(stateData.Validators.TotalVotingPower()))
totalValidators := stateData.Validators.Size()
totalValidatorsPower := stateData.Validators.TotalVotingPower()

c.metrics.Validators.Set(float64(totalValidators))
c.metrics.ValidatorsPower.Set(float64(totalValidatorsPower))

// Calculate validators that didn't sign

// We initialize with total validators count and power, and then decrement as we find the validators
// who have signed the precommit
missingValidators := totalValidators
missingValidatorsPower := totalValidatorsPower
precommits := stateData.Votes.Precommits(stateData.CommitRound)

for _, vote := range precommits.List() {
if val := stateData.Validators.GetByIndex(vote.ValidatorIndex); val != nil {
missingValidators--
missingValidatorsPower -= val.VotingPower
} else {
c.logger.Error("precommit received from invalid validator",
"val", val,
"vote", vote,
"height", vote.Height,
"round", vote.Round)
}
}

var (
missingValidators int
missingValidatorsPower int64
)
c.metrics.MissingValidators.Set(float64(missingValidators))
c.metrics.MissingValidatorsPower.Set(float64(missingValidatorsPower))

Expand Down
Loading