From d2b1115f469b056520bc1e52964caccf219f3439 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 19 Mar 2021 12:54:47 -0500 Subject: [PATCH] Feature Flag for Enabling Slashing Protection Pruning (#8632) --- nogo_config.json | 1 + shared/featureconfig/config.go | 7 +++++++ shared/featureconfig/flags.go | 5 +++++ validator/db/kv/BUILD.bazel | 1 + validator/db/kv/db.go | 9 ++++++--- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/nogo_config.json b/nogo_config.json index 04d5f24e7..ad54ca3c9 100644 --- a/nogo_config.json +++ b/nogo_config.json @@ -64,6 +64,7 @@ "external/.*": "Third party code", "rules_go_work-.*": "Third party code", "shared/params/config.go": "This config struct needs to be organized for now", + "shared/featureconfig/config.go": "This config struct needs to be organized for now", "proto/.*": "Excluding protobuf objects for now" } }, diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 6e5d41a08..fe7a3080a 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -70,6 +70,9 @@ type Flags struct { // KeystoreImportDebounceInterval specifies the time duration the validator waits to reload new keys if they have // changed on disk. This feature is for advanced use cases only. KeystoreImportDebounceInterval time.Duration + + // EnableSlashingProtectionPruning for the validator client. + EnableSlashingProtectionPruning bool } var featureConfig *Flags @@ -237,6 +240,10 @@ func ConfigureValidator(ctx *cli.Context) { log.WithField(attestTimely.Name, attestTimely.Usage).Warn(enabledFeatureFlag) cfg.AttestTimely = true } + if ctx.Bool(enableSlashingProtectionPruning.Name) { + log.WithField(enableSlashingProtectionPruning.Name, enableSlashingProtectionPruning.Usage).Warn(enabledFeatureFlag) + cfg.EnableSlashingProtectionPruning = true + } cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name) Init(cfg) } diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index 1b3b50ab6..fd0971f07 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -118,6 +118,10 @@ var ( Name: "proposer-atts-selection-using-max-cover", Usage: "Rely on max-cover algorithm when selecting attestations for proposer", } + enableSlashingProtectionPruning = &cli.BoolFlag{ + Name: "enable-slashing-protection-pruning", + Usage: "Enables the pruning of the validator client's slashing protectin database", + } ) // devModeFlags holds list of flags that are set when development mode is on. @@ -142,6 +146,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{ disableBlst, dynamicKeyReloadDebounceInterval, attestTimely, + enableSlashingProtectionPruning, }...) // SlasherFlags contains a list of all the feature flags that apply to the slasher client. diff --git a/validator/db/kv/BUILD.bazel b/validator/db/kv/BUILD.bazel index e8fbe3a14..e133556e3 100644 --- a/validator/db/kv/BUILD.bazel +++ b/validator/db/kv/BUILD.bazel @@ -26,6 +26,7 @@ go_library( "//shared/abool:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", + "//shared/featureconfig:go_default_library", "//shared/fileutil:go_default_library", "//shared/params:go_default_library", "//shared/progressutil:go_default_library", diff --git a/validator/db/kv/db.go b/validator/db/kv/db.go index fe75ffb66..d6d8a05e7 100644 --- a/validator/db/kv/db.go +++ b/validator/db/kv/db.go @@ -12,6 +12,7 @@ import ( prombolt "github.com/prysmaticlabs/prombbolt" "github.com/prysmaticlabs/prysm/shared/abool" "github.com/prysmaticlabs/prysm/shared/event" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/params" bolt "go.etcd.io/bbolt" @@ -160,9 +161,11 @@ func NewKVStore(ctx context.Context, dirPath string, config *Config) (*Store, er } } - // Prune attesting records older than the current weak subjectivity period. - if err := kv.PruneAttestations(ctx); err != nil { - return nil, errors.Wrap(err, "could not prune old attestations from DB") + if featureconfig.Get().EnableSlashingProtectionPruning { + // Prune attesting records older than the current weak subjectivity period. + if err := kv.PruneAttestations(ctx); err != nil { + return nil, errors.Wrap(err, "could not prune old attestations from DB") + } } // Batch save attestation records for slashing protection at timed