Add Flag To Disable Initial Sync (#7258)

* add new flag
* terence's review
This commit is contained in:
Nishant Das
2020-09-17 14:11:21 +08:00
committed by GitHub
parent 913e4aa538
commit a335bbbb61
5 changed files with 26 additions and 2 deletions

View File

@@ -119,6 +119,12 @@ var (
Usage: "The factor by which block batch limit may increase on burst.",
Value: 10,
}
// DisableSync disables a node from syncing at start-up. Instead the node enters regular sync
// immediately.
DisableSync = &cli.BoolFlag{
Name: "disable-sync",
Usage: "Starts the beacon node without entering initial sync and instead exits to regular sync immediately.",
}
// EnableDebugRPCEndpoints as /v1/beacon/state.
EnableDebugRPCEndpoints = &cli.BoolFlag{
Name: "enable-debug-rpc-endpoints",

View File

@@ -10,6 +10,7 @@ import (
// beacon node.
type GlobalFlags struct {
UnsafeSync bool
DisableSync bool
DisableDiscv5 bool
MinimumSyncPeers int
BlockBatchLimit int
@@ -36,11 +37,14 @@ func Init(c *GlobalFlags) {
func ConfigureGlobalFlags(ctx *cli.Context) {
cfg := &GlobalFlags{}
if ctx.Bool(UnsafeSync.Name) {
log.Warn("Using Unsafe Sync flag, it is insecure to use this flag with your beacon node.")
cfg.UnsafeSync = true
}
if ctx.Bool(DisableDiscv5.Name) {
cfg.DisableDiscv5 = true
if ctx.Bool(DisableSync.Name) {
log.Warn("Using Disable Sync flag, using this flag on a live network might lead to adverse consequences.")
cfg.DisableSync = true
}
cfg.DisableDiscv5 = ctx.Bool(DisableDiscv5.Name)
cfg.BlockBatchLimit = ctx.Int(BlockBatchLimit.Name)
cfg.BlockBatchLimitBurstFactor = ctx.Int(BlockBatchLimitBurstFactor.Name)
configureMinimumPeers(ctx, cfg)

View File

@@ -39,6 +39,7 @@ var appFlags = []cli.Flag{
flags.ContractDeploymentBlock,
flags.SetGCPercent,
flags.UnsafeSync,
flags.DisableSync,
flags.DisableDiscv5,
flags.BlockBatchLimit,
flags.BlockBatchLimitBurstFactor,

View File

@@ -116,6 +116,18 @@ func (s *Service) Start() {
genesis = time.Unix(int64(headState.GenesisTime()), 0)
}
if flags.Get().DisableSync {
s.synced = true
s.stateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Synced,
Data: &statefeed.SyncedData{
StartTime: genesis,
},
})
log.WithField("genesisTime", genesis).Info("Due to Sync Being Disabled, entering regular sync immediately.")
return
}
if genesis.After(roughtime.Now()) {
s.synced = true
s.stateNotifier.StateFeed().Send(&feed.Event{

View File

@@ -98,6 +98,7 @@ var appHelpFlagGroups = []flagGroup{
flags.HTTPWeb3ProviderFlag,
flags.SetGCPercent,
flags.UnsafeSync,
flags.DisableSync,
flags.SlotsPerArchivedPoint,
flags.DisableDiscv5,
flags.BlockBatchLimit,