From b2ee466f799a64dcbf864c3ee4d3698cfdab375a Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Wed, 6 May 2020 18:17:36 -0400 Subject: [PATCH] Add--disable-historical-detection flag to slasher (#5759) * Add--disable-historical-detection flag * Merge branch 'master' into slasher-add-hist-flag * Fix for comments * Add flag to usage help * Merge branch 'master' into slasher-add-hist-flag * Update slasher/usage.go * Fix imports * Merge branch 'master' into slasher-add-hist-flag * Merge branch 'master' into slasher-add-hist-flag * Merge branch 'master' into slasher-add-hist-flag --- shared/featureconfig/config.go | 10 +++++++++- shared/featureconfig/flags.go | 8 +++++++- slasher/detection/BUILD.bazel | 1 + slasher/detection/service.go | 9 ++++++--- slasher/usage.go | 5 +++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 7935cc6840..2e3072e2ee 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -60,7 +60,8 @@ type Flags struct { DisableForkChoice bool // BroadcastSlashings enables p2p broadcasting of proposer or attester slashing. - BroadcastSlashings bool + BroadcastSlashings bool + DisableHistoricalDetection bool // Cache toggles. EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558. @@ -217,6 +218,13 @@ func ConfigureBeaconChain(ctx *cli.Context) { // on what flags are enabled for the slasher client. func ConfigureSlasher(ctx *cli.Context) { complainOnDeprecatedFlags(ctx) + cfg := &Flags{} + cfg = configureConfig(ctx, cfg) + if ctx.Bool(disableHistoricalDetectionFlag.Name) { + log.Warn("Disabling historical attestation detection") + cfg.DisableHistoricalDetection = true + } + Init(cfg) } // ConfigureValidator sets the global config based diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index d8f88558c2..505c27d462 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -146,6 +146,10 @@ var ( Name: "wait-for-synced", Usage: "Uses WaitForSynced for validator startup, to ensure a validator is able to communicate with the beacon node as quick as possible", } + disableHistoricalDetectionFlag = &cli.BoolFlag{ + Name: "disable-historical-detection", + Usage: "Disables historical attestation detection for the slasher", + } ) // devModeFlags holds list of flags that are set when development mode is on. @@ -362,7 +366,9 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{ }...) // SlasherFlags contains a list of all the feature flags that apply to the slasher client. -var SlasherFlags = append(deprecatedFlags, []cli.Flag{}...) +var SlasherFlags = append(deprecatedFlags, []cli.Flag{ + disableHistoricalDetectionFlag, +}...) // E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E. var E2EValidatorFlags = []string{ diff --git a/slasher/detection/BUILD.bazel b/slasher/detection/BUILD.bazel index e1941a259d..7932f10ef1 100644 --- a/slasher/detection/BUILD.bazel +++ b/slasher/detection/BUILD.bazel @@ -14,6 +14,7 @@ go_library( deps = [ "//beacon-chain/state/stateutil:go_default_library", "//shared/event:go_default_library", + "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/sliceutil:go_default_library", "//slasher/beaconclient:go_default_library", diff --git a/slasher/detection/service.go b/slasher/detection/service.go index 657a1d7193..5a6f3e71a3 100644 --- a/slasher/detection/service.go +++ b/slasher/detection/service.go @@ -5,6 +5,7 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/shared/event" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/sliceutil" "github.com/prysmaticlabs/prysm/slasher/beaconclient" "github.com/prysmaticlabs/prysm/slasher/db" @@ -85,9 +86,11 @@ func (ds *Service) Start() { <-ch sub.Unsubscribe() - // The detection service runs detection on all historical - // chain data since genesis. - go ds.detectHistoricalChainData(ds.ctx) + if !featureconfig.Get().DisableHistoricalDetection { + // The detection service runs detection on all historical + // chain data since genesis. + go ds.detectHistoricalChainData(ds.ctx) + } // We subscribe to incoming blocks from the beacon node via // our gRPC client to keep detecting slashable offenses. diff --git a/slasher/usage.go b/slasher/usage.go index 35d77e5194..a679fbfe67 100644 --- a/slasher/usage.go +++ b/slasher/usage.go @@ -7,6 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/debug" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/slasher/flags" "gopkg.in/urfave/cli.v2" ) @@ -78,6 +79,10 @@ var appHelpFlagGroups = []flagGroup{ flags.BeaconRPCProviderFlag, }, }, + { + Name: "features", + Flags: featureconfig.ActiveFlags(featureconfig.SlasherFlags), + }, } func init() {