diff --git a/CHANGELOG.md b/CHANGELOG.md index 4479669cfc..3553d50573 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691) * (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig * (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation +* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537) ### Removed diff --git a/server/config/config.go b/server/config/config.go index 20f1cfa6e5..9422e8e4ab 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -3,7 +3,6 @@ package config import ( "fmt" "math" - "strings" "github.com/spf13/viper" @@ -207,23 +206,15 @@ func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) { c.MinGasPrices = gasPrices.String() } -// GetMinGasPrices returns the validator's minimum gas prices based on the set -// configuration. +// GetMinGasPrices returns the validator's minimum gas prices based on the set configuration. func (c *Config) GetMinGasPrices() sdk.DecCoins { if c.MinGasPrices == "" { return sdk.DecCoins{} } - gasPricesStr := strings.Split(c.MinGasPrices, ";") - gasPrices := make(sdk.DecCoins, len(gasPricesStr)) - - for i, s := range gasPricesStr { - gasPrice, err := sdk.ParseDecCoin(s) - if err != nil { - panic(fmt.Errorf("failed to parse minimum gas price coin (%s): %s", s, err)) - } - - gasPrices[i] = gasPrice + gasPrices, err := sdk.ParseDecCoins(c.MinGasPrices) + if err != nil { + panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) } return gasPrices diff --git a/server/config/config_test.go b/server/config/config_test.go index 4a1e9ba9b1..5f3415ab9f 100644 --- a/server/config/config_test.go +++ b/server/config/config_test.go @@ -14,10 +14,18 @@ func TestDefaultConfig(t *testing.T) { require.True(t, cfg.GetMinGasPrices().IsZero()) } -func TestSetMinimumFees(t *testing.T) { +func TestGetAndSetMinimumGas(t *testing.T) { cfg := DefaultConfig() - cfg.SetMinGasPrices(sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)}) + + input := sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)} + cfg.SetMinGasPrices(input) require.Equal(t, "5.000000000000000000foo", cfg.MinGasPrices) + require.EqualValues(t, cfg.GetMinGasPrices(), input) + + input = sdk.DecCoins{sdk.NewInt64DecCoin("bar", 1), sdk.NewInt64DecCoin("foo", 5)} + cfg.SetMinGasPrices(input) + require.Equal(t, "1.000000000000000000bar,5.000000000000000000foo", cfg.MinGasPrices) + require.EqualValues(t, cfg.GetMinGasPrices(), input) } func TestValidateBasic(t *testing.T) { diff --git a/server/config/toml.go b/server/config/toml.go index ff05e58eca..960caee664 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -17,7 +17,7 @@ const DefaultConfigTemplate = `# This is a TOML config file. # The minimum gas prices a validator is willing to accept for processing a # transaction. A transaction's fees must meet the minimum of any denomination -# specified in this config (e.g. 0.25token1;0.0001token2). +# specified in this config (e.g. 0.25token1,0.0001token2). minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" # default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals