From 1928311d18953e408af55aa06a4d1b9a00e6b3f6 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 11:38:13 +0200 Subject: [PATCH 01/10] try to return somethign for everything --- beacon-chain/rpc/validator/assignments.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 05718f4f7b41..2ea85faa4daa 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -4,10 +4,11 @@ import ( "context" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" - "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/beacon-chain/core/state" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/state" ) // GetDuties returns the committee assignment response from a given validator public key. @@ -54,6 +55,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth return nil, status.Errorf(codes.Internal, "Could not fetch validator idx for public key %#x: %v", pubKey, err) } if ok { + ca, ok := committeeAssignments[idx] if ok { assignment.Committee = ca.Committee @@ -63,6 +65,10 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.AttesterSlot = ca.AttesterSlot assignment.ProposerSlot = proposerIndexToSlot[idx] assignment.CommitteeIndex = ca.CommitteeIndex + } else { + vs, _, _ := vs.retrieveStatusFromState(ctx, pubKey, s) + log.Println(vs, pubKey) + assignment.Status = vs } } From 3d4a07af5adcd6cd090abe126d2c290667b67001 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 11:48:26 +0200 Subject: [PATCH 02/10] default to unknown --- beacon-chain/rpc/validator/assignments.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 2ea85faa4daa..85531a3b51fb 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -48,6 +48,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth // Default assignment. assignment := ðpb.DutiesResponse_Duty{ PublicKey: pubKey, + Status: ethpb.ValidatorStatus_UNKNOWN_STATUS, } idx, ok, err := vs.BeaconDB.ValidatorIndex(ctx, pubKey) @@ -55,7 +56,6 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth return nil, status.Errorf(codes.Internal, "Could not fetch validator idx for public key %#x: %v", pubKey, err) } if ok { - ca, ok := committeeAssignments[idx] if ok { assignment.Committee = ca.Committee From 525c1c73da1d47152a38aa5ee6e2630fb7e192fb Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 12:01:11 +0200 Subject: [PATCH 03/10] debug --- beacon-chain/rpc/validator/assignments.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 85531a3b51fb..125d4def7fdc 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -18,6 +18,7 @@ import ( // 3.) The slot at which the committee is assigned. // 4.) The bool signaling if the validator is expected to propose a block at the assigned slot. func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) { + log.Error("get duties") if vs.SyncChecker.Syncing() { return nil, status.Error(codes.Unavailable, "Syncing to latest head, not ready to respond") } @@ -42,6 +43,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth var validatorAssignments []*ethpb.DutiesResponse_Duty for _, pubKey := range req.PublicKeys { + log.Errorf(" %#x", pubKey) if ctx.Err() != nil { return nil, status.Errorf(codes.Aborted, "Could not continue fetching assignments: %v", ctx.Err()) } @@ -71,7 +73,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.Status = vs } } - + log.Error("assignment", assignment) validatorAssignments = append(validatorAssignments, assignment) } From 4ee07600bb3eadcac6ba21ed8d165f2b850ae4c4 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 12:22:34 +0200 Subject: [PATCH 04/10] moar debug --- beacon-chain/rpc/validator/assignments.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 125d4def7fdc..c257b070383e 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -50,7 +50,6 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth // Default assignment. assignment := ðpb.DutiesResponse_Duty{ PublicKey: pubKey, - Status: ethpb.ValidatorStatus_UNKNOWN_STATUS, } idx, ok, err := vs.BeaconDB.ValidatorIndex(ctx, pubKey) @@ -68,8 +67,9 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.ProposerSlot = proposerIndexToSlot[idx] assignment.CommitteeIndex = ca.CommitteeIndex } else { + log.Error("no committee assigment") vs, _, _ := vs.retrieveStatusFromState(ctx, pubKey, s) - log.Println(vs, pubKey) + log.Error(vs, pubKey) assignment.Status = vs } } From d0d98af409d1a2b134d1edacfb252e30ee149574 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 12:34:23 +0200 Subject: [PATCH 05/10] move else to outer check --- beacon-chain/rpc/validator/assignments.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index c257b070383e..9ef5ac8846f1 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -66,12 +66,12 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.AttesterSlot = ca.AttesterSlot assignment.ProposerSlot = proposerIndexToSlot[idx] assignment.CommitteeIndex = ca.CommitteeIndex - } else { - log.Error("no committee assigment") - vs, _, _ := vs.retrieveStatusFromState(ctx, pubKey, s) - log.Error(vs, pubKey) - assignment.Status = vs } + } else { + log.Error("no committee index") + vs := vs.validatorStatus(ctx, pubKey, s) + log.Error(vs, pubKey) + assignment.Status = vs.Status } log.Error("assignment", assignment) validatorAssignments = append(validatorAssignments, assignment) From 08a0bbef86c355dfc2a6e839bf0c556d56c780a2 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 14:11:33 +0200 Subject: [PATCH 06/10] working --- beacon-chain/rpc/validator/assignments.go | 4 ---- validator/client/validator.go | 23 +++++++++++++++++++++++ validator/client/validator_aggregate.go | 4 ++-- validator/client/validator_attest.go | 4 ++-- validator/client/validator_metrics.go | 2 +- validator/client/validator_propose.go | 4 ++-- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 9ef5ac8846f1..6f6c1139a84e 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -43,7 +43,6 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth var validatorAssignments []*ethpb.DutiesResponse_Duty for _, pubKey := range req.PublicKeys { - log.Errorf(" %#x", pubKey) if ctx.Err() != nil { return nil, status.Errorf(codes.Aborted, "Could not continue fetching assignments: %v", ctx.Err()) } @@ -68,12 +67,9 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth assignment.CommitteeIndex = ca.CommitteeIndex } } else { - log.Error("no committee index") vs := vs.validatorStatus(ctx, pubKey, s) - log.Error(vs, pubKey) assignment.Status = vs.Status } - log.Error("assignment", assignment) validatorAssignments = append(validatorAssignments, assignment) } diff --git a/validator/client/validator.go b/validator/client/validator.go index 537821e77db1..fec41265f25e 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 a7d91ae5868c..1e03548c98ee 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 0ab1fb23d7f5..96f89336341d 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 ccc917646559..fa75c6758fb9 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 b3f4bd258bed..9836fc90abea 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", }, ) ) From 7f9061e9357c06f8b68bad17734df9635e8f54d8 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 14:13:00 +0200 Subject: [PATCH 07/10] reorder imports --- beacon-chain/rpc/validator/assignments.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 6f6c1139a84e..ea031777a984 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -4,11 +4,10 @@ import ( "context" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/state" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // GetDuties returns the committee assignment response from a given validator public key. From b111969d776901461d32f5cbdcd205d952d19627 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 11 Mar 2020 14:13:43 +0200 Subject: [PATCH 08/10] cleanup --- beacon-chain/rpc/validator/assignments.go | 1 - 1 file changed, 1 deletion(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index ea031777a984..7c641ccf63ca 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -17,7 +17,6 @@ import ( // 3.) The slot at which the committee is assigned. // 4.) The bool signaling if the validator is expected to propose a block at the assigned slot. func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) { - log.Error("get duties") if vs.SyncChecker.Syncing() { return nil, status.Error(codes.Unavailable, "Syncing to latest head, not ready to respond") } From 737efd2de2ffa509ebcac3c89880f594fba56c4f Mon Sep 17 00:00:00 2001 From: Alex T Date: Thu, 12 Mar 2020 11:02:30 +0200 Subject: [PATCH 09/10] fix TestGetDuties_NextEpoch_CantFindValidatorIdx --- beacon-chain/rpc/validator/assignments_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/beacon-chain/rpc/validator/assignments_test.go b/beacon-chain/rpc/validator/assignments_test.go index c61ee0cb9c3d..dbb8ea163c00 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) From ee180bdbc0ccc9b069dc3d8d2136739e25861356 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 12 Mar 2020 14:00:07 +0100 Subject: [PATCH 10/10] Update validator/client/validator.go --- validator/client/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/client/validator.go b/validator/client/validator.go index fec41265f25e..eda761c872fc 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -58,7 +58,7 @@ var validatorStatusesGaugeVec = promauto.NewGaugeVec( Help: "validator statuses: 0 UNKNOWN, 1 DEPOSITED, 2 PENDING, 3 ACTIVE, 4 EXITING, 5 SLASHING, 6 EXITED", }, []string{ - // validator pubkey + // Validator pubkey. "pubkey", }, )