feat: customtendermint config (#11049)
## Description Closes: https://github.com/cosmos/cosmos-sdk/issues/10936 avoid copy pasting init command, allow teams to overwrite config by default. another feature proposal --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
85e27873f0
commit
caf9dca288
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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{}) {
|
||||
|
|
Loading…
Reference in New Issue