Skip to content

Commit

Permalink
Return statuses on duties (#5069)
Browse files Browse the repository at this point in the history
* try to return somethign for everything
* default to unknown
* debug
* moar debug
* move else to outer check
* working
* reorder imports
* cleanup
* fix TestGetDuties_NextEpoch_CantFindValidatorIdx
* Merge branch 'master' into return-statuses-on-duties
* Update validator/client/validator.go
* Merge branch 'master' into return-statuses-on-duties
* Merge branch 'master' into return-statuses-on-duties
  • Loading branch information
tzapu committed Mar 12, 2020
1 parent 0f95b79 commit 0704ba6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion beacon-chain/rpc/validator/assignments.go
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
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
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.
"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
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
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
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
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

0 comments on commit 0704ba6

Please sign in to comment.