Skip to content

Commit

Permalink
Stream Duties Client Implementation (#5867)
Browse files Browse the repository at this point in the history
* include validator client stream

* Update validator/client/validator_attest.go

* gazelle

* rem extraneous logs

* fixing tests

* resolve most tests

* gaz

* add lock

* ivan feedback

* pass tests for update protect

* gaz

* duties gaz

* no need for canonical head slot

* fix ctx leak

* fmt

* add in feature flag

* add streaming subpackage

* add polling/streaming separation

* able to build

* fix duplicate package names

* fix polling

* imports

* confirm it works

* fixed up comment

* go lint comments

* gaz

* build

* Update validator/client/streaming/service_test.go

Co-authored-by: terence tsao <terence@prysmaticlabs.com>

* tidy

* fmt

* add stream duties to e2e

* add stream duties to e2e flags

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
  • Loading branch information
3 people committed Jun 18, 2020
1 parent 10af753 commit 7067c84
Show file tree
Hide file tree
Showing 45 changed files with 4,630 additions and 206 deletions.
3 changes: 2 additions & 1 deletion beacon-chain/state/stateutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ go_library(
"//slasher:__subpackages__",
"//tools/blocktree:__pkg__",
"//tools/pcli:__pkg__",
"//validator/client:__pkg__",
"//validator/client/streaming:__pkg__",
"//validator/client/polling:__pkg__",
],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
Expand Down
25 changes: 0 additions & 25 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"lostcancel": {
"exclude_files": {
"validator/client/runner.go": "No need to cancel right when goroutines begin",
"validator/client/streaming/runner.go": "No need to cancel right when goroutines begin",
"validator/client/polling/runner.go": "No need to cancel right when goroutines begin",
"external/.*": "Third party code"
}
},
Expand Down
5 changes: 5 additions & 0 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Flags struct {
E2EConfig bool //E2EConfig made specifically for testing, do not use except in E2E.

// Feature related flags.
EnableStreamDuties bool // Enable streaming of validator duties instead of a polling-based approach.
WriteSSZStateTransitions bool // WriteSSZStateTransitions to tmp directory.
InitSyncNoVerify bool // InitSyncNoVerify when initial syncing w/o verifying block's contents.
DisableDynamicCommitteeSubnets bool // Disables dynamic attestation committee subnets via p2p.
Expand Down Expand Up @@ -272,6 +273,10 @@ func ConfigureValidator(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
cfg = configureConfig(ctx, cfg)
if ctx.Bool(enableStreamDuties.Name) {
log.Warn("Enabled validator duties streaming.")
cfg.EnableStreamDuties = true
}
if ctx.Bool(enableProtectProposerFlag.Name) {
log.Warn("Enabled validator proposal slashing protection.")
cfg.ProtectProposer = true
Expand Down
6 changes: 6 additions & 0 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ var (
Name: "disable-reduce-attester-state-copy",
Usage: "Disables the feature to reduce the amount of state copies for attester rpc",
}
enableStreamDuties = &cli.BoolFlag{
Name: "enable-stream-duties",
Usage: "Enables validator duties streaming in the validator client",
}
enableKadDht = &cli.BoolFlag{
Name: "enable-kad-dht",
Usage: "Enables libp2p's kademlia based discovery to start running",
Expand Down Expand Up @@ -486,6 +490,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
e2eConfigFlag,
enableProtectAttesterFlag,
enableProtectProposerFlag,
enableStreamDuties,
enableExternalSlasherProtectionFlag,
disableDomainDataCacheFlag,
waitForSyncedFlag,
Expand All @@ -503,6 +508,7 @@ var E2EValidatorFlags = []string{
"--wait-for-synced",
"--enable-protect-attester",
"--enable-protect-proposer",
"--enable-stream-duties",
}

// BeaconChainFlags contains a list of all the feature flags that apply to the beacon-chain client.
Expand Down
5 changes: 3 additions & 2 deletions validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ go_library(
"//shared/params:go_default_library",
"//shared/version:go_default_library",
"//validator/accounts:go_default_library",
"//validator/client:go_default_library",
"//validator/client/streaming:go_default_library",
"//validator/flags:go_default_library",
"//validator/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
Expand Down Expand Up @@ -63,7 +63,8 @@ go_image(
"//shared/params:go_default_library",
"//shared/version:go_default_library",
"//validator/accounts:go_default_library",
"//validator/client:go_default_library",
"//validator/client/polling:go_default_library",
"//validator/client/streaming:go_default_library",
"//validator/flags:go_default_library",
"//validator/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
Expand Down
12 changes: 12 additions & 0 deletions validator/client/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["metrics.go"],
importpath = "github.com/prysmaticlabs/prysm/validator/client/metrics",
visibility = ["//validator/client:__subpackages__"],
deps = [
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
],
)
121 changes: 121 additions & 0 deletions validator/client/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
// ValidatorStatusesGaugeVec used to track validator statuses by public key.
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",
},
)
// ValidatorAggSuccessVec used to count successful aggregations.
ValidatorAggSuccessVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "successful_aggregations",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorAggFailVec used to count failed aggregations.
ValidatorAggFailVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "failed_aggregations",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorProposeSuccessVec used to count successful proposals.
ValidatorProposeSuccessVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "successful_proposals",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorProposeFailVec used to count failed proposals.
ValidatorProposeFailVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "failed_proposals",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorProposeFailVecSlasher used to count failed proposals by slashing protection.
ValidatorProposeFailVecSlasher = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "validator_proposals_rejected_total",
Help: "Count the block proposals rejected by slashing protection.",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorBalancesGaugeVec used to keep track of validator balances by public key.
ValidatorBalancesGaugeVec = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "validator",
Name: "balance",
Help: "current validator balance.",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorAttestSuccessVec used to count successful attestations.
ValidatorAttestSuccessVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "successful_attestations",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorAttestFailVec used to count failed attestations.
ValidatorAttestFailVec = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "validator",
Name: "failed_attestations",
},
[]string{
// validator pubkey
"pubkey",
},
)
// ValidatorAttestFailVecSlasher used to count failed attestations by slashing protection.
ValidatorAttestFailVecSlasher = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "validator_attestations_rejected_total",
Help: "Count the attestations rejected by slashing protection.",
},
[]string{
// validator pubkey
"pubkey",
},
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go_library(
"validator_metrics.go",
"validator_propose.go",
],
importpath = "github.com/prysmaticlabs/prysm/validator/client",
importpath = "github.com/prysmaticlabs/prysm/validator/client/polling",
visibility = ["//validator:__subpackages__"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
Expand All @@ -28,6 +28,7 @@ go_library(
"//shared/params:go_default_library",
"//shared/roughtime:go_default_library",
"//shared/slotutil:go_default_library",
"//validator/client/metrics:go_default_library",
"//validator/db:go_default_library",
"//validator/keymanager:go_default_library",
"//validator/slashing-protection:go_default_library",
Expand All @@ -40,8 +41,6 @@ go_library(
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package polling

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package polling

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package polling

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Package client defines the entire lifecycle of a validator in eth2 – it is responsible
// for interacting with a beacon node to determine and perform validator duties.
package client
package polling

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package polling

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package client represents the functionality to act as a validator.
package client
// Package polling represents a gRPC polling-based implementation
// of an eth2 validator client.
package polling

import (
"context"
Expand All @@ -17,8 +18,6 @@ import (
ptypes "github.com/gogo/protobuf/types"
lru "github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/slotutil"
"github.com/prysmaticlabs/prysm/validator/client/metrics"
"github.com/prysmaticlabs/prysm/validator/db"
"github.com/prysmaticlabs/prysm/validator/keymanager"
slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection"
Expand Down Expand Up @@ -67,18 +67,6 @@ type validator struct {
protector slashingprotection.Protector
}

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 @@ -249,7 +237,7 @@ func (v *validator) checkAndLogValidatorStatus(validatorStatuses []*ethpb.Valida
log := log.WithFields(fields)
if v.emitAccountMetrics {
fmtKey := fmt.Sprintf("%#x", status.PublicKey)
validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(status.Status.Status))
metrics.ValidatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(status.Status.Status))
}
switch status.Status.Status {
case ethpb.ValidatorStatus_UNKNOWN_STATUS:
Expand Down Expand Up @@ -565,7 +553,7 @@ func (v *validator) logDuties(slot uint64, duties []*ethpb.DutiesResponse_Duty)
for _, duty := range duties {
if v.emitAccountMetrics {
fmtKey := fmt.Sprintf("%#x", duty.PublicKey)
validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status))
metrics.ValidatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status))
}

// Only interested in validators who are attesting/proposing.
Expand Down

0 comments on commit 7067c84

Please sign in to comment.