diff --git a/CHANGELOG.md b/CHANGELOG.md index 3749ef3c21..43dab52c41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -219,6 +219,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#10561](https://github.com/cosmos/cosmos-sdk/pull/10561) The `CommitMultiStore` interface contains a new `SetIAVLCacheSize` method * [\#10922](https://github.com/cosmos/cosmos-sdk/pull/10922), [/#10956](https://github.com/cosmos/cosmos-sdk/pull/10956) Deprecate key `server.Generate*` functions and move them to `testutil` and support custom mnemonics in in-process testing network. Moved `TestMnemonic` from `testutil` package to `testdata`. +* [\#11049](https://github.com/cosmos/cosmos-sdk/pull/11049) Add custom tendermint config variables into root command. Allows App developers to set config.toml variables. ### Features diff --git a/server/util.go b/server/util.go index 16c9f3a185..dcdeb3ff58 100644 --- a/server/util.go +++ b/server/util.go @@ -105,7 +105,7 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) // is used to read and parse the application configuration. Command handlers can // fetch the server Context to get the Tendermint configuration or to get access // to Viper. -func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}) error { +func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, tmConfig *tmcfg.Config) error { serverCtx := NewDefaultContext() // Get the executable name and configure the viper instance so that environmental @@ -126,7 +126,7 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s serverCtx.Viper.AutomaticEnv() // intercept configuration files, using both Viper instances separately - config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig) + config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, tmConfig) if err != nil { return err } @@ -184,12 +184,12 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { // configuration file. The Tendermint configuration file is parsed given a root // Viper object, whereas the application is parsed with the private package-aware // viperCfg object. -func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}) (*tmcfg.Config, error) { +func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, tmConfig *tmcfg.Config) (*tmcfg.Config, error) { rootDir := rootViper.GetString(flags.FlagHome) configPath := filepath.Join(rootDir, "config") tmCfgFile := filepath.Join(configPath, "config.toml") - conf := tmcfg.DefaultConfig() + conf := tmConfig switch _, err := os.Stat(tmCfgFile); { case os.IsNotExist(err): diff --git a/server/util_test.go b/server/util_test.go index 77bbbbc951..4a297af460 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/require" + tmcfg "github.com/tendermint/tendermint/config" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -27,7 +28,7 @@ var cancelledInPreRun = errors.New("Cancelled in prerun") // Used in each test to run the function under test via Cobra // but to always halt the command func preRunETestImpl(cmd *cobra.Command, args []string) error { - err := server.InterceptConfigsPreRunHandler(cmd, "", nil) + err := server.InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig()) if err != nil { return err } @@ -432,7 +433,7 @@ func TestEmptyMinGasPrices(t *testing.T) { // Run StartCmd. cmd = server.StartCmd(nil, tempDir) cmd.PreRunE = func(cmd *cobra.Command, _ []string) error { - return server.InterceptConfigsPreRunHandler(cmd, "", nil) + return server.InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig()) } err = cmd.ExecuteContext(ctx) require.Errorf(t, err, sdkerrors.ErrAppConfig.Error()) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index eee610d941..d1425eb892 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cast" "github.com/spf13/cobra" + tmcfg "github.com/tendermint/tendermint/config" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -71,8 +72,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { } customAppTemplate, customAppConfig := initAppConfig() + customTMConfig := initTendermintConfig() - return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig) + return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) }, } @@ -81,6 +83,18 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return rootCmd, encodingConfig } +// initTendermintConfig helps to override default Tendermint Config values. +// return tmcfg.DefaultConfig if no custom configuration is required for the application. +func initTendermintConfig() *tmcfg.Config { + cfg := tmcfg.DefaultConfig() + + // these values put a higher strain on node memory + // cfg.P2P.MaxNumInboundPeers = 100 + // cfg.P2P.MaxNumOutboundPeers = 40 + + return cfg +} + // initAppConfig helps to override default appConfig template and configs. // return "", nil if no custom configuration is required for the application. func initAppConfig() (string, interface{}) {