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

Tracked validators metric #14575

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Added SubmitPoolAttesterSlashingV2 endpoint.
- Added SubmitAggregateAndProofsRequestV2 endpoint.
- Updated the `beacon-chain/monitor` package to Electra. [PR](https://github.com/prysmaticlabs/prysm/pull/14562)
- Metric for the size of tracked validators cache

### Changed

Expand Down
3 changes: 3 additions & 0 deletions api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ go_library(
"constants.go",
"headers.go",
"jwt.go",
"metrics.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/api",
visibility = ["//visibility:public"],
deps = [
"//crypto/rand:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
],
)

Expand Down
13 changes: 13 additions & 0 deletions api/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package api

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
TrackedValidatorsCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "tracked_validator_count",
Help: "The total number of validators tracked by trackedValidatorsCache in the beacon node. This is updated at intervals via the push proposer settings API endpoint.",
})
)
6 changes: 6 additions & 0 deletions beacon-chain/cache/tracked_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ func (t *TrackedValidatorsCache) Validating() bool {
defer t.Unlock()
return len(t.trackedValidators) > 0
}

func (t *TrackedValidatorsCache) Size() int {
t.Lock()
defer t.Unlock()
return len(t.trackedValidators)
}
Comment on lines +51 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be beneficial to add a note directly to the code that the accuracy of this is not 100%?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does return the size of the cache, it's more that the metric might not be fully representative

1 change: 1 addition & 0 deletions beacon-chain/rpc/eth/validator/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ func (s *Server) PrepareBeaconProposer(w http.ResponseWriter, r *http.Request) {
if len(validatorIndices) == 0 {
return
}
api.TrackedValidatorsCount.Set(float64(s.TrackedValidatorsCache.Size()))
log.WithFields(logrus.Fields{
"validatorIndices": validatorIndices,
}).Info("Updated fee recipient addresses")
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/prysm/v1alpha1/validator",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//api:go_default_library",
"//api/client/builder:go_default_library",
"//async/event:go_default_library",
"//beacon-chain/blockchain:go_default_library",
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
emptypb "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
builderapi "github.com/prysmaticlabs/prysm/v5/api/client/builder"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/builder"
Expand Down Expand Up @@ -427,6 +428,7 @@ func (vs *Server) PrepareBeaconProposer(
validatorIndices = append(validatorIndices, r.ValidatorIndex)
}
if len(validatorIndices) != 0 {
api.TrackedValidatorsCount.Set(float64(vs.TrackedValidatorsCache.Size()))
log.WithFields(logrus.Fields{
"validatorCount": len(validatorIndices),
}).Debug("Updated fee recipient addresses for validator indices")
Expand Down
Loading