-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / golangci-lint
|
||
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 GitHub Actions / golangci-lint
|
||
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 GitHub Actions / golangci-lint
|
||
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 GitHub Actions / golangci-lint
|
||
return nil | ||
}}, | ||
Check failure on line 35 in cmd/starsd/cmd/settings.go GitHub Actions / golangci-lint
|
||
{ | ||
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 GitHub Actions / golangci-lint
|
||
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 GitHub Actions / golangci-lint
|
||
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 | ||
} |