Skip to content

Commit

Permalink
Feature Flag for Enabling Slashing Protection Pruning (#8632)
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan authored Mar 19, 2021
1 parent 9282a73 commit d2b1115
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
Expand Down
7 changes: 7 additions & 0 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions validator/db/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions validator/db/kv/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2b1115

Please sign in to comment.