Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config overwrite ignores app.toml values #7233

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 31 additions & 14 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,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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down