Skip to content

Commit

Permalink
enable preferred settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhernandezb committed Jan 29, 2025
1 parent 8531661 commit 3283cb9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/starsd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func NewRootCmd() *cobra.Command {
panic(err)
}

rootCmd.PersistentPreRunE = chainPreRuns(rootCmd.PersistentPreRunE, SetPreferredSettings, LogPreferredSettings)

return rootCmd
}

Expand Down Expand Up @@ -176,11 +178,13 @@ func initRootCmd(
txCommand(),
keys.Commands(),
)

Check failure on line 181 in cmd/starsd/cmd/root.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)

Check failure on line 181 in cmd/starsd/cmd/root.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
}

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)
}

Expand Down
85 changes: 85 additions & 0 deletions cmd/starsd/cmd/settings.go
Original file line number Diff line number Diff line change
@@ -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 {

Check warning on line 22 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 22 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
serverCtx.Viper.Set(key, value)
serverCtx.Config.Consensus.TimeoutCommit = time.Duration(3 * time.Second)

Check failure on line 24 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)

Check failure on line 24 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)
return nil
},
},
{
ViperKey: "consensus.timeout_propose",
Value: "2s",
Set: func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error {

Check warning on line 31 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 31 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
serverCtx.Viper.Set(key, value)
serverCtx.Config.Consensus.TimeoutPropose = time.Duration(2 * time.Second)

Check failure on line 33 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)

Check failure on line 33 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)
return nil
}},

Check failure on line 35 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)

Check failure on line 35 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
{
ViperKey: "wasm.memory_cache_size",
Value: "1024",
Set: func(cmd *cobra.Command, serverCtx *server.Context, key, value string) error {

Check warning on line 39 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 39 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
serverCtx.Viper.Set(key, value)
return nil
},
},
}

func SetPreferredSettings(cmd *cobra.Command, _ []string) error {

Check failure on line 47 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)

Check failure on line 47 in cmd/starsd/cmd/settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
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
}
2 changes: 1 addition & 1 deletion cmd/starsd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3283cb9

Please sign in to comment.