Skip to content

Commit

Permalink
Merge pull request #32 from multiversx/ski-configs-download-flag
Browse files Browse the repository at this point in the history
skip configs download flag
  • Loading branch information
miiu96 authored Apr 23, 2024
2 parents c1ca475 + 394ef9d commit 555df09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
4 changes: 4 additions & 0 deletions cmd/chainsimulator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ var (
Usage: "The time between blocks generations, when autoGenerateBlocks flag is true",
Value: 6000,
}
skipConfigsDownload = cli.BoolFlag{
Name: "skip-configs-download",
Usage: "The flag is used to specify whether to skip downloading configs",
}
)

func applyFlags(ctx *cli.Context, cfg *config.Config) {
Expand Down
46 changes: 28 additions & 18 deletions cmd/chainsimulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func main() {
initialEpoch,
autoGenerateBlocks,
blockTimeInMs,
skipConfigsDownload,
}

app.Authors = []cli.Author{
Expand All @@ -97,11 +98,6 @@ func main() {
}

func startChainSimulator(ctx *cli.Context) error {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return errors.New("cannot read build info")
}

cfg, err := loadMainConfig(ctx.GlobalString(configurationFile.Name))
if err != nil {
return fmt.Errorf("%w while loading the config file", err)
Expand All @@ -119,22 +115,12 @@ func startChainSimulator(ctx *cli.Context) error {
return fmt.Errorf("%w while initializing the logger", err)
}

gitFetcher := git.NewGitFetcher()
configsFetcher, err := configs.NewConfigsFetcher(cfg.Config.Simulator.MxChainRepo, cfg.Config.Simulator.MxProxyRepo, gitFetcher)
if err != nil {
return err
}

skipDownload := ctx.GlobalBool(skipConfigsDownload.Name)
nodeConfigs := ctx.GlobalString(pathToNodeConfigs.Name)
err = configsFetcher.FetchNodeConfigs(buildInfo, nodeConfigs)
if err != nil {
return err
}

proxyConfigs := ctx.GlobalString(pathToProxyConfigs.Name)
err = configsFetcher.FetchProxyConfigs(buildInfo, proxyConfigs)
err = fetchConfigs(skipDownload, cfg, nodeConfigs, proxyConfigs)
if err != nil {
return err
return fmt.Errorf("%w while fetching configs", err)
}

bypassTxsSignature := ctx.GlobalBool(bypassTransactionsSignature.Name)
Expand Down Expand Up @@ -334,6 +320,30 @@ func initializeLogger(ctx *cli.Context, cfg config.Config) (closing.Closer, erro
return fileLogging, nil
}

func fetchConfigs(skipDownload bool, cfg config.Config, nodeConfigs, proxyConfigs string) error {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return errors.New("cannot read build info")
}
if skipDownload {
log.Warn(`flag "skip-configs-download" has been provided, if the configs are missing, then simulator will not start`)
return nil
}

gitFetcher := git.NewGitFetcher()
configsFetcher, err := configs.NewConfigsFetcher(cfg.Config.Simulator.MxChainRepo, cfg.Config.Simulator.MxProxyRepo, gitFetcher)
if err != nil {
return err
}

err = configsFetcher.FetchNodeConfigs(buildInfo, nodeConfigs)
if err != nil {
return err
}

return configsFetcher.FetchProxyConfigs(buildInfo, proxyConfigs)
}

func loadMainConfig(filepath string) (config.Config, error) {
cfg := config.Config{}
err := core.LoadTomlFile(&cfg, filepath)
Expand Down

0 comments on commit 555df09

Please sign in to comment.