diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 05718f4f7..7c641ccf6 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -64,8 +64,10 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.ProposerSlot = proposerIndexToSlot[idx] assignment.CommitteeIndex = ca.CommitteeIndex } + } else { + vs := vs.validatorStatus(ctx, pubKey, s) + assignment.Status = vs.Status } - validatorAssignments = append(validatorAssignments, assignment) } diff --git a/beacon-chain/rpc/validator/assignments_test.go b/beacon-chain/rpc/validator/assignments_test.go index c61ee0cb9..dbb8ea163 100644 --- a/beacon-chain/rpc/validator/assignments_test.go +++ b/beacon-chain/rpc/validator/assignments_test.go @@ -6,10 +6,13 @@ import ( "fmt" "strings" "testing" + "time" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/go-ssz" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" + "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" + mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" blk "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/state" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" @@ -67,10 +70,19 @@ func TestGetDuties_NextEpoch_CantFindValidatorIdx(t *testing.T) { t.Fatalf("Could not get signing root %v", err) } + height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix() + p := &mockPOW.POWChain{ + TimesByHeight: map[int]uint64{ + 0: uint64(height), + }, + } + vs := &Server{ BeaconDB: db, HeadFetcher: &mockChain.ChainService{State: beaconState, Root: genesisRoot[:]}, SyncChecker: &mockSync.Sync{IsSyncing: false}, + Eth1InfoFetcher: p, + DepositFetcher: depositcache.NewDepositCache(), } pubKey := pubKey(99999) diff --git a/validator/client/validator.go b/validator/client/validator.go index 537821e77..eda761c87 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -28,6 +28,8 @@ import ( "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/sirupsen/logrus" "go.opencensus.io/trace" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ) type validator struct { @@ -49,6 +51,18 @@ type validator struct { domainDataCache *ristretto.Cache } +var validatorStatusesGaugeVec = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "validator", + Name: "statuses", + Help: "validator statuses: 0 UNKNOWN, 1 DEPOSITED, 2 PENDING, 3 ACTIVE, 4 EXITING, 5 SLASHING, 6 EXITED", + }, + []string{ + // Validator pubkey. + "pubkey", + }, +) + // Done cleans up the validator. func (v *validator) Done() { v.ticker.Done() @@ -175,6 +189,10 @@ func (v *validator) checkAndLogValidatorStatus(validatorStatuses []*ethpb.Valida "pubKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey[:])), "status": status.Status.Status.String(), }) + if v.emitAccountMetrics { + fmtKey := fmt.Sprintf("%#x", status.PublicKey[:]) + validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(status.Status.Status)) + } if status.Status.Status == ethpb.ValidatorStatus_ACTIVE { activatedKeys = append(activatedKeys, status.PublicKey) continue @@ -269,6 +287,11 @@ func (v *validator) UpdateDuties(ctx context.Context, slot uint64) error { "status": duty.Status, } + if v.emitAccountMetrics { + fmtKey := fmt.Sprintf("%#x", duty.PublicKey[:]) + validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status)) + } + if duty.Status == ethpb.ValidatorStatus_ACTIVE { if duty.ProposerSlot > 0 { lFields["proposerSlot"] = duty.ProposerSlot diff --git a/validator/client/validator_aggregate.go b/validator/client/validator_aggregate.go index a7d91ae58..1e03548c9 100644 --- a/validator/client/validator_aggregate.go +++ b/validator/client/validator_aggregate.go @@ -24,7 +24,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) validatorAggFailVec = promauto.NewCounterVec( @@ -34,7 +34,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) ) diff --git a/validator/client/validator_attest.go b/validator/client/validator_attest.go index 0ab1fb23d..96f893363 100644 --- a/validator/client/validator_attest.go +++ b/validator/client/validator_attest.go @@ -30,7 +30,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) validatorAttestFailVec = promauto.NewCounterVec( @@ -40,7 +40,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) ) diff --git a/validator/client/validator_metrics.go b/validator/client/validator_metrics.go index ccc917646..fa75c6758 100644 --- a/validator/client/validator_metrics.go +++ b/validator/client/validator_metrics.go @@ -20,7 +20,7 @@ var validatorBalancesGaugeVec = promauto.NewGaugeVec( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) diff --git a/validator/client/validator_propose.go b/validator/client/validator_propose.go index b3f4bd258..9836fc90a 100644 --- a/validator/client/validator_propose.go +++ b/validator/client/validator_propose.go @@ -29,7 +29,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) validatorProposeFailVec = promauto.NewCounterVec( @@ -39,7 +39,7 @@ var ( }, []string{ // validator pubkey - "pkey", + "pubkey", }, ) )