Skip to content

Commit

Permalink
only retrieve pubkey once for all validators (partially fixes #4865) (#…
Browse files Browse the repository at this point in the history
…4895)

in consensus/state.go, when calulating metrics, retrieve address (ergo, pubkey) once prior to iterating over validatorset to ensure we do not make excessive calls to signer.

Partially closes: #4865
  • Loading branch information
Joe Bowman authored and melekes committed Nov 16, 2020
1 parent 1a8e42d commit 6e375c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi


### BUG FIXES:

- [consensus] [\#4895](https://github.com/tendermint/tendermint/pull/4895) Cache the address of the validator to reduce querying a remote KMS (@joe-bowman)
37 changes: 20 additions & 17 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1532,39 +1532,42 @@ func (cs *State) recordMetrics(height int64, block *types.Block) {
var (
commitSize = block.LastCommit.Size()
valSetLen = len(cs.LastValidators.Validators)
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.LastValidators.Validators))
}

if cs.privValidator != nil {
pubkey, err := cs.privValidator.GetPubKey()
if err != nil {
// Metrics won't be updated, but it's not critical.
cs.Logger.Error("Error on retrieval of pubkey", "err", err)
} else {
address = pubkey.Address()
}
}

for i, val := range cs.LastValidators.Validators {
commitSig := block.LastCommit.Signatures[i]
if commitSig.Absent() {
missingValidators++
missingValidatorsPower += val.VotingPower
}

if cs.privValidator != nil {
pubKey, err := cs.privValidator.GetPubKey()
if err != nil {
// Metrics won't be updated, but it's not critical.
cs.Logger.Error("Error on retrival of pubkey", "err", err)
continue
if bytes.Equal(val.Address, address) {
label := []string{
"validator_address", val.Address.String(),
}

if bytes.Equal(val.Address, pubKey.Address()) {
label := []string{
"validator_address", val.Address.String(),
}
cs.metrics.ValidatorPower.With(label...).Set(float64(val.VotingPower))
if commitSig.ForBlock() {
cs.metrics.ValidatorLastSignedHeight.With(label...).Set(float64(height))
} else {
cs.metrics.ValidatorMissedBlocks.With(label...).Add(float64(1))
}
cs.metrics.ValidatorPower.With(label...).Set(float64(val.VotingPower))
if commitSig.ForBlock() {
cs.metrics.ValidatorLastSignedHeight.With(label...).Set(float64(height))
} else {
cs.metrics.ValidatorMissedBlocks.With(label...).Add(float64(1))
}
}

}
}
cs.metrics.MissingValidators.Set(float64(missingValidators))
Expand Down

0 comments on commit 6e375c2

Please sign in to comment.