Skip to content

Commit

Permalink
Merge pull request #4257 from ElrondNetwork/force-start-from-network
Browse files Browse the repository at this point in the history
Added force-start-from-network flag
  • Loading branch information
iulianpascalau authored Jul 4, 2022
2 parents 5ba9c12 + 92dde49 commit 84c9960
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cmd/node/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ var (
"and by advanced users, as a too high memory ballast could lead to Out Of Memory panics. The memory ballast " +
"should not be higher than 20-25% of the machine's available RAM",
}
// forceStartFromNetwork defines a flag that will force the start from network bootstrap process
forceStartFromNetwork = cli.BoolFlag{
Name: "force-start-from-network",
Usage: "Flag that will force the start from network bootstrap process",
}
)

func getFlags() []cli.Flag {
Expand Down Expand Up @@ -371,6 +376,7 @@ func getFlags() []cli.Flag {
fullArchive,
memBallast,
memoryUsageToCreateProfiles,
forceStartFromNetwork,
}
}

Expand All @@ -393,6 +399,7 @@ func getFlagsConfig(ctx *cli.Context, log logger.Logger) *config.ContextFlagsCon
flagsConfig.EnablePprof = ctx.GlobalBool(profileMode.Name)
flagsConfig.UseLogView = ctx.GlobalBool(useLogView.Name)
flagsConfig.ValidatorKeyIndex = ctx.GlobalInt(validatorKeyIndex.Name)
flagsConfig.ForceStartFromNetwork = ctx.GlobalBool(forceStartFromNetwork.Name)
return flagsConfig
}

Expand Down
3 changes: 2 additions & 1 deletion config/contextFlagsConfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

//ContextFlagsConfig will keep the values for the cli.Context flags
// ContextFlagsConfig will keep the values for the cli.Context flags
type ContextFlagsConfig struct {
WorkingDir string
EnableGops bool
Expand All @@ -20,6 +20,7 @@ type ContextFlagsConfig struct {
ValidatorKeyIndex int
EnableRestAPIServerDebugMode bool
Version string
ForceStartFromNetwork bool
}

// ImportDbConfig will hold the import-db parameters
Expand Down
11 changes: 10 additions & 1 deletion epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type epochStartBootstrap struct {
messenger Messenger
generalConfig config.Config
prefsConfig config.PreferencesConfig
flagsConfig config.ContextFlagsConfig
economicsData process.EconomicsDataHandler
shardCoordinator sharding.Coordinator
genesisNodesConfig sharding.GenesisNodesSetupHandler
Expand Down Expand Up @@ -152,6 +153,7 @@ type ArgsEpochStartBootstrap struct {
GeneralConfig config.Config
PrefsConfig config.PreferencesConfig
EnableEpochs config.EnableEpochs
FlagsConfig config.ContextFlagsConfig
EconomicsData process.EconomicsDataHandler
GenesisNodesConfig sharding.GenesisNodesSetupHandler
GenesisShardCoordinator sharding.Coordinator
Expand Down Expand Up @@ -187,6 +189,7 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap,
messenger: args.Messenger,
generalConfig: args.GeneralConfig,
prefsConfig: args.PrefsConfig,
flagsConfig: args.FlagsConfig,
economicsData: args.EconomicsData,
genesisNodesConfig: args.GenesisNodesConfig,
genesisShardCoordinator: args.GenesisShardCoordinator,
Expand Down Expand Up @@ -299,7 +302,12 @@ func (e *epochStartBootstrap) isNodeInGenesisNodesConfig() bool {
func (e *epochStartBootstrap) Bootstrap() (Parameters, error) {
defer e.closeTrieComponents()

if !e.generalConfig.GeneralSettings.StartInEpochEnabled {
if e.flagsConfig.ForceStartFromNetwork {
log.Warn("epochStartBootstrap.Bootstrap: forcing start from network")
}

shouldStartFromNetwork := e.generalConfig.GeneralSettings.StartInEpochEnabled || e.flagsConfig.ForceStartFromNetwork
if !shouldStartFromNetwork {
return e.bootstrapFromLocalStorage()
}

Expand All @@ -325,6 +333,7 @@ func (e *epochStartBootstrap) Bootstrap() (Parameters, error) {
}

params, shouldContinue, err := e.startFromSavedEpoch()
shouldContinue = shouldContinue || e.flagsConfig.ForceStartFromNetwork
if !shouldContinue {
return params, err
}
Expand Down
3 changes: 3 additions & 0 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func createMockEpochStartBootstrapArgs(
}, nil
},
},
FlagsConfig: config.ContextFlagsConfig{
ForceStartFromNetwork: false,
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions factory/bootstrapComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type BootstrapComponentsFactoryArgs struct {
RoundConfig config.RoundConfig
PrefConfig config.Preferences
ImportDbConfig config.ImportDbConfig
FlagsConfig config.ContextFlagsConfig
WorkingDir string
CoreComponents CoreComponentsHolder
CryptoComponents CryptoComponentsHolder
Expand All @@ -43,6 +44,7 @@ type bootstrapComponentsFactory struct {
roundConfig config.RoundConfig
prefConfig config.Preferences
importDbConfig config.ImportDbConfig
flagsConfig config.ContextFlagsConfig
workingDir string
coreComponents CoreComponentsHolder
cryptoComponents CryptoComponentsHolder
Expand Down Expand Up @@ -81,6 +83,7 @@ func NewBootstrapComponentsFactory(args BootstrapComponentsFactoryArgs) (*bootst
roundConfig: args.RoundConfig,
prefConfig: args.PrefConfig,
importDbConfig: args.ImportDbConfig,
flagsConfig: args.FlagsConfig,
workingDir: args.WorkingDir,
coreComponents: args.CoreComponents,
cryptoComponents: args.CryptoComponents,
Expand Down Expand Up @@ -167,6 +170,7 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) {
GeneralConfig: bcf.config,
PrefsConfig: bcf.prefConfig.Preferences,
EnableEpochs: bcf.epochConfig.EnableEpochs,
FlagsConfig: bcf.flagsConfig,
EconomicsData: bcf.coreComponents.EconomicsData(),
GenesisNodesConfig: bcf.coreComponents.GenesisNodesSetup(),
GenesisShardCoordinator: genesisShardCoordinator,
Expand Down
3 changes: 3 additions & 0 deletions factory/bootstrapComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func getBootStrapArgs() factory.BootstrapComponentsFactoryArgs {
IsImportDBMode: false,
},
RoundConfig: config.RoundConfig{},
FlagsConfig: config.ContextFlagsConfig{
ForceStartFromNetwork: false,
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func testNodeStartsInEpoch(t *testing.T, shardID uint32, expectedHighestRound ui
},
},
ScheduledSCRsStorer: genericMocks.NewStorerMock("path", 0),
FlagsConfig: config.ContextFlagsConfig{
ForceStartFromNetwork: false,
},
}

epochStartBootstrap, err := bootstrap.NewEpochStartBootstrap(argsBootstrapHandler)
Expand Down
1 change: 1 addition & 0 deletions node/nodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ func (nr *nodeRunner) CreateManagedBootstrapComponents(
RoundConfig: *nr.configs.RoundConfig,
PrefConfig: *nr.configs.PreferencesConfig,
ImportDbConfig: *nr.configs.ImportDbConfig,
FlagsConfig: *nr.configs.FlagsConfig,
WorkingDir: nr.configs.FlagsConfig.WorkingDir,
CoreComponents: coreComponents,
CryptoComponents: cryptoComponents,
Expand Down

0 comments on commit 84c9960

Please sign in to comment.