Historical pruning by flag only (#2210)

* add flag

* use flag

* fixes
This commit is contained in:
Preston Van Loon 2019-04-07 22:46:55 -04:00 committed by GitHub
parent 771c4c0b0f
commit 97b184e5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 3 deletions

View File

@ -25,6 +25,7 @@ go_test(
"//beacon-chain/chaintest/backend:go_default_library",
"//beacon-chain/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
],

View File

@ -10,9 +10,14 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/chaintest/backend"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
)
func init() {
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{})
}
func TestGenerateState_OK(t *testing.T) {
b, err := backend.NewSimulatedBackend()
if err != nil {

View File

@ -22,6 +22,7 @@ go_library(
"//beacon-chain/core/genesis:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_boltdb_bolt//:go_default_library",
@ -51,6 +52,7 @@ go_test(
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bls:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",

View File

@ -13,6 +13,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/genesis"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"go.opencensus.io/trace"
)
@ -331,6 +332,9 @@ func (db *BeaconDB) GenesisTime(ctx context.Context) (time.Time, error) {
}
func (db *BeaconDB) deleteHistoricalStates(slot uint64) error {
if !featureconfig.FeatureConfig().EnableHistoricalStatePruning {
return nil
}
return db.update(func(tx *bolt.Tx) error {
histState := tx.Bucket(histStateBucket)
chainInfo := tx.Bucket(chainInfoBucket)

View File

@ -12,9 +12,16 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
)
func init() {
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{
EnableHistoricalStatePruning: true,
})
}
func setupInitialDeposits(t testing.TB, numDeposits int) ([]*pb.Deposit, []*bls.SecretKey) {
privKeys := make([]*bls.SecretKey, numDeposits)
deposits := make([]*pb.Deposit, numDeposits)

View File

@ -51,6 +51,7 @@ go_test(
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/p2p:go_default_library",
"//shared/params:go_default_library",

View File

@ -11,6 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
)
@ -21,6 +22,10 @@ func NotSyncQuerierConfig() *QuerierConfig {
}
}
func init() {
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{})
}
func initializeTestSyncService(ctx context.Context, cfg *Config, synced bool) *Service {
var sqCfg *QuerierConfig
if synced {

View File

@ -25,9 +25,10 @@ var log = logrus.WithField("prefix", "flags")
// FeatureFlagConfig is a struct to represent what features the client will perform on runtime.
type FeatureFlagConfig struct {
VerifyAttestationSigs bool // VerifyAttestationSigs declares if the client will verify attestations.
EnableComputeStateRoot bool // EnableComputeStateRoot implementation on server side.
EnableCrosslinks bool // EnableCrosslinks in epoch processing.
VerifyAttestationSigs bool // VerifyAttestationSigs declares if the client will verify attestations.
EnableComputeStateRoot bool // EnableComputeStateRoot implementation on server side.
EnableCrosslinks bool // EnableCrosslinks in epoch processing.
EnableHistoricalStatePruning bool // EnableHistoricalStatePruning when updatifinalized states.
}
var featureConfig *FeatureFlagConfig
@ -58,6 +59,10 @@ func ConfigureBeaconFeatures(ctx *cli.Context) {
log.Info("Enabled crosslink computations")
cfg.EnableCrosslinks = true
}
if ctx.GlobalBool(EnableHistoricalStatePruningFlag.Name) {
log.Info("Enabled historical state pruning")
cfg.EnableHistoricalStatePruning = true
}
InitFeatureConfig(cfg)
}

View File

@ -24,6 +24,12 @@ var (
Name: "enable-crosslinks",
Usage: "Enable crosslinks in epoch processing, default is disabled.",
}
// EnableHistoricalStatePruningFlag allows the database to prune old historical states.
EnableHistoricalStatePruningFlag = cli.BoolFlag{
Name: "enable-historical-state-pruning",
Usage: "Enable database pruning of historical states after finalized epochs",
}
)
// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
@ -33,4 +39,5 @@ var ValidatorFlags = []cli.Flag{}
var BeaconChainFlags = []cli.Flag{
EnableComputeStateRootFlag,
EnableCrosslinksFlag,
EnableHistoricalStatePruningFlag,
}