Skip to content

Commit

Permalink
core/scheduler: add validator balance (#1051)
Browse files Browse the repository at this point in the history
Adds validator balance metric in scheduler.

category: misc
ticket: #981
  • Loading branch information
dB2510 authored Aug 29, 2022
1 parent 5c804c1 commit e3efc42
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 156 deletions.
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ func createMockValidators(pubkeys []eth2p0.BLSPubKey) beaconmock.ValidatorSet {
vIdx := eth2p0.ValidatorIndex(i)

resp[vIdx] = &eth2v1.Validator{
Index: vIdx,
Status: eth2v1.ValidatorStateActiveOngoing,
Balance: eth2p0.Gwei(31300000000),
Index: vIdx,
Status: eth2v1.ValidatorStateActiveOngoing,
Validator: &eth2p0.Validator{
WithdrawalCredentials: []byte("12345678901234567890123456789012"),
PublicKey: pubkey,
Expand Down
13 changes: 13 additions & 0 deletions core/scheduler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package scheduler

import (
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

Expand Down Expand Up @@ -50,6 +51,13 @@ var (
Name: "validators_active",
Help: "Number of active validators",
})

balanceGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "core",
Subsystem: "scheduler",
Name: "validator_balance_gwei",
Help: "Total balance of a validator by public key",
}, []string{"pubkey"})
)

// instrumentSlot sets the current slot and epoch metrics.
Expand All @@ -62,3 +70,8 @@ func instrumentSlot(slot core.Slot) {
func instrumentDuty(duty core.Duty, defSet core.DutyDefinitionSet) {
dutyCounter.WithLabelValues(duty.Type.String()).Add(float64(len(defSet)))
}

// instrumentValidator sets the validator balance.
func instrumentValidator(pubkey core.PubKey, totalBal eth2p0.Gwei) {
balanceGauge.WithLabelValues(pubkey.String()).Set(float64(totalBal))
}
2 changes: 2 additions & 0 deletions core/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ func resolveActiveValidators(ctx context.Context, eth2Cl eth2wrap.Client,
return nil, err
}

instrumentValidator(pubkey, val.Balance)

resp = append(resp, validator{
PubKey: pubkey,
VIdx: index,
Expand Down
Loading

0 comments on commit e3efc42

Please sign in to comment.