diff --git a/CHANGELOG.md b/CHANGELOG.md index d06518f036e..105f7ec6889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7172) Lower CPU overheads of the Osmosis epoch. * [#7203](https://github.com/osmosis-labs/osmosis/pull/7203) Make a maximum number of pools of 100 billion. +### Bug Fixes + +* [#7233](https://github.com/osmosis-labs/osmosis/pull/7233) fix: config overwrite ignores app.toml values + ## v21.1.5 * [#7210](https://github.com/osmosis-labs/osmosis/pull/7210) Arb filter for new authz exec swap. diff --git a/cmd/osmosisd/cmd/root.go b/cmd/osmosisd/cmd/root.go index 4bc7b1be47e..35490dbc08d 100644 --- a/cmd/osmosisd/cmd/root.go +++ b/cmd/osmosisd/cmd/root.go @@ -16,6 +16,7 @@ import ( rosettaCmd "cosmossdk.io/tools/rosetta/cmd" "github.com/prometheus/client_golang/prometheus" + "github.com/spf13/viper" cometbftdb "github.com/cometbft/cometbft-db" @@ -92,11 +93,17 @@ type DenomUnitMap struct { Exponent uint64 `json:"exponent"` } +const ( + consensusConfigName = "consensus" + timeoutCommitConfigName = "timeout_commit" +) + var ( //go:embed "osmosis-1-assetlist.json" "osmo-test-5-assetlist.json" - assetFS embed.FS - mainnetId = "osmosis-1" - testnetId = "osmo-test-5" + assetFS embed.FS + mainnetId = "osmosis-1" + testnetId = "osmo-test-5" + fiveSecondsString = (5 * time.Second).String() ) func loadAssetList(initClientCtx client.Context, cmd *cobra.Command, basedenomToIBC, IBCtoBasedenom bool) (map[string]DenomUnitMap, map[string]string) { @@ -402,7 +409,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { } // overwrites config.toml values if it exists, otherwise it writes the default config.toml -func overwriteConfigTomlValues(serverCtx *server.Context) (*tmcfg.Config, error) { +func overwriteConfigTomlValues(serverCtx *server.Context) error { // Get paths to config.toml and config parent directory rootDir := serverCtx.Viper.GetString(tmcli.HomeFlag) @@ -416,7 +423,7 @@ func overwriteConfigTomlValues(serverCtx *server.Context) (*tmcfg.Config, error) if err != nil { // something besides a does not exist error if !os.IsNotExist(err) { - return nil, fmt.Errorf("failed to read in %s: %w", configFilePath, err) + return fmt.Errorf("failed to read in %s: %w", configFilePath, err) } // It does not exist, so we update the default config.toml to update @@ -426,22 +433,32 @@ func overwriteConfigTomlValues(serverCtx *server.Context) (*tmcfg.Config, error) } else { // config.toml exists - serverCtx.Viper.SetConfigType("toml") - serverCtx.Viper.SetConfigName("config") - serverCtx.Viper.AddConfigPath(configParentDirPath) + // Create a copy since the original viper from serverCtx + // contains app.toml config values that would get overwritten + // by ReadInConfig below. + viperCopy := viper.New() + + viperCopy.SetConfigType("toml") + viperCopy.SetConfigName("config") + viperCopy.AddConfigPath(configParentDirPath) // We read it in and modify the consensus timeout commit // and write it back. - if err := serverCtx.Viper.ReadInConfig(); err != nil { - return nil, fmt.Errorf("failed to read in %s: %w", configFilePath, err) + if err := viperCopy.ReadInConfig(); err != nil { + return fmt.Errorf("failed to read in %s: %w", configFilePath, err) + } + + consensusValues := viperCopy.GetStringMapString(consensusConfigName) + timeoutCommitValue, ok := consensusValues[timeoutCommitConfigName] + if !ok { + return fmt.Errorf("failed to get %s.%s from %s: %w", consensusConfigName, timeoutCommitValue, configFilePath, err) } // The original default is 5s and is set in Cosmos SDK. // We lower it to 4s for faster block times. - if serverCtx.Config.Consensus.TimeoutCommit == 5*time.Second { + if timeoutCommitValue == fiveSecondsString { serverCtx.Config.Consensus.TimeoutCommit = 4 * time.Second } - tmcConfig = serverCtx.Config defer func() { if err := recover(); err != nil { @@ -452,7 +469,7 @@ func overwriteConfigTomlValues(serverCtx *server.Context) (*tmcfg.Config, error) // this may panic for permissions issues. So we catch the panic. tmcfg.WriteConfigFile(configFilePath, serverCtx.Config) } - return tmcConfig, nil + return nil } func getHomeEnvironment() string { @@ -635,7 +652,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { serverCtx := server.GetServerContextFromCmd(cmd) // overwrite config.toml values - _, err := overwriteConfigTomlValues(serverCtx) + err := overwriteConfigTomlValues(serverCtx) if err != nil { return err }