Feature flag to gate prune state upon start up (#5011)

* Added feature flag to gate prune state upon start up
This commit is contained in:
prylabs-bulldozer[bot] 2020-03-05 06:24:59 +00:00 committed by GitHub
parent 66991f0efe
commit e635e5b205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 4 deletions

View File

@ -34,6 +34,7 @@ import (
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
@ -404,6 +405,10 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
// This is called when a client starts from a non-genesis slot. It deletes the states in DB
// from slot 1 (avoid genesis state) to `slot`.
func (s *Service) pruneGarbageState(ctx context.Context, slot uint64) error {
if featureconfig.Get().DontPruneStateStartUp {
return nil
}
filter := filters.NewFilter().SetStartSlot(1).SetEndSlot(slot)
roots, err := s.beaconDB.BlockRoots(ctx, filter)
if err != nil {

View File

@ -2,4 +2,4 @@ package stategen
import "github.com/sirupsen/logrus"
var log = logrus.WithField("prefix", "state-gen")
var log = logrus.WithField("prefix", "state-gen")

View File

@ -72,9 +72,9 @@ type fetchRequestResponse struct {
func newBlocksFetcher(ctx context.Context, cfg *blocksFetcherConfig) *blocksFetcher {
ctx, cancel := context.WithCancel(ctx)
rateLimiter := leakybucket.NewCollector(
allowedBlocksPerSecond /* rate */,
allowedBlocksPerSecond /* capacity */,
false /* deleteEmptyBuckets */)
allowedBlocksPerSecond, /* rate */
allowedBlocksPerSecond, /* capacity */
false /* deleteEmptyBuckets */)
return &blocksFetcher{
ctx: ctx,

View File

@ -46,6 +46,7 @@ type Flags struct {
EnableStateGenSigVerify bool // EnableStateGenSigVerify verifies proposer and randao signatures during state gen.
CheckHeadState bool // CheckHeadState checks the current headstate before retrieving the desired state from the db.
EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer.
DontPruneStateStartUp bool // DontPruneStateStartUp disables pruning state upon beacon node start up.
// DisableForkChoice disables using LMD-GHOST fork choice to update
// the head of the chain based on attestations and instead accepts any valid received block
// as the chain head. UNSAFE, use with caution.
@ -158,6 +159,10 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Enabling noise handshake for peer")
cfg.EnableNoise = true
}
if ctx.GlobalBool(dontPruneStateStartUp.Name) {
log.Warn("Not enabling state pruning upon start up")
cfg.DontPruneStateStartUp = true
}
Init(cfg)
}

View File

@ -111,6 +111,10 @@ var (
Usage: "This enables the beacon node to use NOISE instead of SECIO for performing handshakes between peers and " +
"securing transports between peers",
}
dontPruneStateStartUp = cli.BoolFlag{
Name: "dont-prune-state-start-up",
Usage: "Don't prune historical states upon start up",
}
)
// Deprecated flags list.
@ -285,6 +289,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
enableStateGenSigVerify,
checkHeadState,
enableNoiseHandshake,
dontPruneStateStartUp,
}...)
// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.