Add feature flag for state pruning (#3845)

* Add feature flag for state pruning

* gaz
This commit is contained in:
Preston Van Loon 2019-10-23 23:45:52 -07:00 committed by terence tsao
parent 2d98902eed
commit acf11262de
6 changed files with 24 additions and 2 deletions

View File

@ -58,6 +58,7 @@ go_test(
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/bytesutil: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

@ -379,6 +379,10 @@ func (s *Store) clearSeenAtts() {
// rmStatesOlderThanLastFinalized deletes the states in db since last finalized check point.
func (s *Store) rmStatesOlderThanLastFinalized(ctx context.Context, startSlot uint64, endSlot uint64) error {
if !featureconfig.Get().PruneFinalizedStates {
return nil
}
ctx, span := trace.StartSpan(ctx, "forkchoice.rmStatesBySlots")
defer span.End()

View File

@ -15,11 +15,18 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func init() {
fc := featureconfig.Get()
fc.PruneFinalizedStates = true
featureconfig.Init(fc)
}
func TestStore_OnBlock(t *testing.T) {
ctx := context.Background()
db := testDB.SetupDB(t)

View File

@ -5,8 +5,8 @@ import (
"testing"
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
@ -109,7 +109,7 @@ func TestStore_FinalizedCheckpoint_StateMustExist(t *testing.T) {
Root: []byte{'B'},
}
if err := db.SaveFinalizedCheckpoint(ctx, cp); err != errMissingStateForFinalizedCheckpoint {
if err := db.SaveFinalizedCheckpoint(ctx, cp); err != errMissingStateForFinalizedCheckpoint {
t.Fatalf("wanted err %v, got %v", errMissingStateForFinalizedCheckpoint, err)
}
}

View File

@ -32,6 +32,7 @@ type Flag struct {
SkipBLSVerify bool // Skips BLS verification across the runtime.
EnableBackupWebhook bool // EnableBackupWebhook to allow database backups to trigger from monitoring port /db/backup
OptimizeProcessEpoch bool // OptimizeProcessEpoch to process epoch with optimizations by pre computing records
PruneFinalizedStates bool // PruneFinalizedStates from the database.
// Cache toggles.
EnableAttestationCache bool // EnableAttestationCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
@ -103,6 +104,10 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Processing epoch with optimizations")
cfg.OptimizeProcessEpoch = true
}
if ctx.GlobalBool(pruneFinalizedStatesFlag.Name) {
log.Warn("Enabled pruning old finalized states from database.")
cfg.PruneFinalizedStates = true
}
Init(cfg)
}

View File

@ -57,6 +57,10 @@ var (
Name: "optimize-process-epoch",
Usage: "Process epoch with optimizations",
}
pruneFinalizedStatesFlag = cli.BoolFlag{
Name: "prune-finalized-states",
Usage: "Delete old states from the database after reaching new finalized checkpoint",
}
)
// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
@ -77,4 +81,5 @@ var BeaconChainFlags = []cli.Flag{
OptimizeProcessEpoch,
enableBackupWebhookFlag,
enableBLSPubkeyCacheFlag,
pruneFinalizedStatesFlag,
}