From 3283cb98ee859e51249741b50c1284252a30d7f4 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Wed, 29 Jan 2025 11:41:14 -0600 Subject: [PATCH] enable preferred settings --- cmd/starsd/cmd/root.go | 4 ++ cmd/starsd/cmd/settings.go | 85 ++++++++++++++++++++++++++++++++++++++ cmd/starsd/cmd/start.go | 2 +- 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 cmd/starsd/cmd/settings.go diff --git a/cmd/starsd/cmd/root.go b/cmd/starsd/cmd/root.go index 750502c20..e2213a3e2 100644 --- a/cmd/starsd/cmd/root.go +++ b/cmd/starsd/cmd/root.go @@ -135,6 +135,8 @@ func NewRootCmd() *cobra.Command { panic(err) } + rootCmd.PersistentPreRunE = chainPreRuns(rootCmd.PersistentPreRunE, SetPreferredSettings, LogPreferredSettings) + return rootCmd } @@ -176,11 +178,13 @@ func initRootCmd( txCommand(), keys.Commands(), ) + } func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) wasm.AddModuleInitFlags(startCmd) + startCmd.Flags().Bool(flagSkipPreferredSettings, false, "Skip preferred settings") startCmd.PreRunE = chainPreRuns(CheckLibwasmVersion, startCmd.PreRunE) } diff --git a/cmd/starsd/cmd/settings.go b/cmd/starsd/cmd/settings.go new file mode 100644 index 000000000..33e8ce8e5 --- /dev/null +++ b/cmd/starsd/cmd/settings.go @@ -0,0 +1,85 @@ +package cmd + +import ( + "time" + + "github.com/cosmos/cosmos-sdk/server" + "github.com/spf13/cobra" +) + +const flagSkipPreferredSettings = "skip-preferred-settings" + +type PreferredSetting struct { + ViperKey string + Value string + Set func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error +} + +var preferredSettings = []PreferredSetting{ + { + ViperKey: "consensus.timeout_commit", + Value: "3s", + Set: func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error { + serverCtx.Viper.Set(key, value) + serverCtx.Config.Consensus.TimeoutCommit = time.Duration(3 * time.Second) + return nil + }, + }, + { + ViperKey: "consensus.timeout_propose", + Value: "2s", + Set: func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error { + serverCtx.Viper.Set(key, value) + serverCtx.Config.Consensus.TimeoutPropose = time.Duration(2 * time.Second) + return nil + }}, + { + ViperKey: "wasm.memory_cache_size", + Value: "1024", + Set: func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error { + serverCtx.Viper.Set(key, value) + return nil + }, + }, +} + +func SetPreferredSettings(cmd *cobra.Command, _ []string) error { + + skip, err := cmd.Flags().GetBool(flagSkipPreferredSettings) + if err != nil { + return err + } + if skip { + return nil + } + + serverCtx := server.GetServerContextFromCmd(cmd) + + for _, setting := range preferredSettings { + err := setting.Set(cmd, serverCtx, setting.ViperKey, setting.Value) + if err != nil { + return err + } + } + + return server.SetCmdServerContext(cmd, serverCtx) +} + +func LogPreferredSettings(cmd *cobra.Command, _ []string) error { + serverCtx := server.GetServerContextFromCmd(cmd) + + skip, err := cmd.Flags().GetBool(flagSkipPreferredSettings) + if err != nil { + return err + } + + if !skip { + serverCtx.Logger.Info("using preferred settings use --skip-preferred-settings to disable") + } + + serverCtx.Logger.Info("using timeout_commit", "value", serverCtx.Config.Consensus.TimeoutCommit.String()) + serverCtx.Logger.Info("using timeout_propose", "value", serverCtx.Config.Consensus.TimeoutPropose.String()) + serverCtx.Logger.Info("using wasm.memory_cache_size", "value", serverCtx.Viper.Get("wasm.memory_cache_size")) + + return nil +} diff --git a/cmd/starsd/cmd/start.go b/cmd/starsd/cmd/start.go index a74ba904d..b8ac4051c 100644 --- a/cmd/starsd/cmd/start.go +++ b/cmd/starsd/cmd/start.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -var LibwasmVersion = "2.2.1" +var LibwasmVersion = "2.1.4" func CheckLibwasmVersion(_ *cobra.Command, _ []string) error { version, err := wasmvmapi.LibwasmvmVersion()