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

Return statuses on duties #5069

Merged
4 changes: 3 additions & 1 deletion beacon-chain/rpc/validator/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions beacon-chain/rpc/validator/assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
terencechain marked this conversation as resolved.
Show resolved Hide resolved
"pubkey",
},
)

// Done cleans up the validator.
func (v *validator) Done() {
v.ticker.Done()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions validator/client/validator_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
validatorAggFailVec = promauto.NewCounterVec(
Expand All @@ -34,7 +34,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
)
Expand Down
4 changes: 2 additions & 2 deletions validator/client/validator_attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
validatorAttestFailVec = promauto.NewCounterVec(
Expand All @@ -40,7 +40,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
)
Expand Down
2 changes: 1 addition & 1 deletion validator/client/validator_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var validatorBalancesGaugeVec = promauto.NewGaugeVec(
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)

Expand Down
4 changes: 2 additions & 2 deletions validator/client/validator_propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
validatorProposeFailVec = promauto.NewCounterVec(
Expand All @@ -39,7 +39,7 @@ var (
},
[]string{
// validator pubkey
"pkey",
"pubkey",
},
)
)
Expand Down