From d0acfc68d52641ed9633fc24a0bc331f22dc0233 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 23 Apr 2024 13:40:31 +0300 Subject: [PATCH 1/4] skip configs download flag --- cmd/chainsimulator/flags.go | 4 +++ cmd/chainsimulator/main.go | 51 ++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/cmd/chainsimulator/flags.go b/cmd/chainsimulator/flags.go index f4ae497c..c8642e22 100644 --- a/cmd/chainsimulator/flags.go +++ b/cmd/chainsimulator/flags.go @@ -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) { diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index e2986c31..2c193267 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -78,6 +78,7 @@ func main() { initialEpoch, autoGenerateBlocks, blockTimeInMs, + skipConfigsDownload, } app.Authors = []cli.Author{ @@ -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) @@ -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) @@ -334,6 +320,35 @@ 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 configs for node and proxy are missing 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 + } + + err = configsFetcher.FetchProxyConfigs(buildInfo, proxyConfigs) + if err != nil { + return err + } + + return nil +} + func loadMainConfig(filepath string) (config.Config, error) { cfg := config.Config{} err := core.LoadTomlFile(&cfg, filepath) From 04a6368e78104226158fccd569d0d389c123928a Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 23 Apr 2024 13:57:53 +0300 Subject: [PATCH 2/4] small fix --- cmd/chainsimulator/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index 2c193267..20ce82ac 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -326,7 +326,7 @@ func fetchConfigs(skipDownload bool, cfg config.Config, nodeConfigs, proxyConfig return errors.New("cannot read build info") } if skipDownload { - log.Warn(`flag "skip-configs-download" has been provided, if configs for node and proxy are missing simulator will not start`) + log.Warn(`flag "skip-configs-download" has been provided, if the configs are missing, them simulator will not start`) return nil } From 1e2529ad312df9deaafea3430c5251457f4cbf7b Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 23 Apr 2024 14:59:43 +0300 Subject: [PATCH 3/4] fixes after second review --- cmd/chainsimulator/main.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index 20ce82ac..93b150e8 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -341,12 +341,7 @@ func fetchConfigs(skipDownload bool, cfg config.Config, nodeConfigs, proxyConfig return err } - err = configsFetcher.FetchProxyConfigs(buildInfo, proxyConfigs) - if err != nil { - return err - } - - return nil + return configsFetcher.FetchProxyConfigs(buildInfo, proxyConfigs) } func loadMainConfig(filepath string) (config.Config, error) { From 394ef9d0f093b1f1b1b12b9273209c819abbe6f1 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 23 Apr 2024 15:45:21 +0300 Subject: [PATCH 4/4] fix --- cmd/chainsimulator/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index 93b150e8..78b1fae4 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -326,7 +326,7 @@ func fetchConfigs(skipDownload bool, cfg config.Config, nodeConfigs, proxyConfig return errors.New("cannot read build info") } if skipDownload { - log.Warn(`flag "skip-configs-download" has been provided, if the configs are missing, them simulator will not start`) + log.Warn(`flag "skip-configs-download" has been provided, if the configs are missing, then simulator will not start`) return nil }