only retrieve pubkey once for all validators (partially fixes #4865) (#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
This commit is contained in:
Joe Bowman
2020-05-29 07:15:46 +01:00
committed by Anton Kaliaev
parent 8706d45f3d
commit 61ab6718e9
2 changed files with 8 additions and 1 deletions

View File

@@ -21,3 +21,4 @@ program](https://hackerone.com/tendermint).
### 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)

View File

@@ -1463,7 +1463,13 @@ func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) {
var (
missingValidators = 0
missingValidatorsPower int64
address types.Address
)
if cs.privValidator != nil {
address = cs.privValidator.GetPubKey().Address()
}
for i, val := range cs.Validators.Validators {
var vote *types.CommitSig
if i < len(block.LastCommit.Precommits) {
@@ -1474,7 +1480,7 @@ func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) {
missingValidatorsPower += val.VotingPower
}
if cs.privValidator != nil && bytes.Equal(val.Address, cs.privValidator.GetPubKey().Address()) {
if bytes.Equal(val.Address, address) {
label := []string{
"validator_address", val.Address.String(),
}