Skip to content

Commit

Permalink
fix: config overwrite ignores app.toml values
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Jan 2, 2024
1 parent 9cd7231 commit 06cf429
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 31 additions & 13 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -426,19 +433,30 @@ 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
Expand All @@ -452,7 +470,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 {
Expand Down Expand Up @@ -635,7 +653,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
}
Expand Down

0 comments on commit 06cf429

Please sign in to comment.