diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf30c6c1b23..feef3d8ef041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### CLI Breaking Changes +* (x/genutil) [#13535](https://github.com/cosmos/cosmos-sdk/pull/13535) Replace in `simd init`, the `--staking-bond-denom` flag with `--default-denom` which is used for all default denomination in the genesis, instead of only staking. * (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`. ### Bug Fixes diff --git a/types/staking.go b/types/staking.go index 2f17bb1dd85f..66a01a29b381 100644 --- a/types/staking.go +++ b/types/staking.go @@ -1,26 +1,25 @@ package types -// staking constants -const ( +// Delay, in blocks, between when validator updates are returned to the +// consensus-engine and when they are applied. For example, if +// ValidatorUpdateDelay is set to X, and if a validator set update is +// returned with new validators at the end of block 10, then the new +// validators are expected to sign blocks beginning at block 11+X. +// +// This value is constant as this should not change without a hard fork. +// For Tendermint this should be set to 1 block, for more details see: +// https://tendermint.com/docs/spec/abci/apps.html#endblock +const ValidatorUpdateDelay int64 = 1 - // default bond denomination +var ( + // DefaultBondDenom is the default bondable coin denomination (defaults to stake) + // Overwriting this value has the side effect of changing the default denomination in genesis DefaultBondDenom = "stake" - // Delay, in blocks, between when validator updates are returned to the - // consensus-engine and when they are applied. For example, if - // ValidatorUpdateDelay is set to X, and if a validator set update is - // returned with new validators at the end of block 10, then the new - // validators are expected to sign blocks beginning at block 11+X. - // - // This value is constant as this should not change without a hard fork. - // For Tendermint this should be set to 1 block, for more details see: - // https://tendermint.com/docs/spec/abci/apps.html#endblock - ValidatorUpdateDelay int64 = 1 + // DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power + DefaultPowerReduction = NewIntFromUint64(1000000) ) -// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power -var DefaultPowerReduction = NewIntFromUint64(1000000) - // TokensToConsensusPower - convert input tokens to potential consensus-engine power func TokensToConsensusPower(tokens Int, powerReduction Int) int64 { return (tokens.Quo(powerReduction)).Int64() diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 77b763aeb734..e7e3e91ab0c4 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -22,7 +22,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) const ( @@ -32,8 +31,8 @@ const ( // FlagSeed defines a flag to initialize the private validator key from a specific seed. FlagRecover = "recover" - // FlagStakingBondDenom defines a flag to specify the staking token in the genesis file. - FlagStakingBondDenom = "staking-bond-denom" + // FlagDefaultBondDenom defines the default denom to use in the genesis file. + FlagDefaultBondDenom = "default-denom" ) type printInfo struct { @@ -115,7 +114,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { genFile := config.GenesisFile() overwrite, _ := cmd.Flags().GetBool(FlagOverwrite) - stakingBondDenom, _ := cmd.Flags().GetString(FlagStakingBondDenom) + defaultDenom, _ := cmd.Flags().GetString(FlagDefaultBondDenom) // use os.Stat to check if the file exists _, err = os.Stat(genFile) @@ -123,25 +122,11 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { return fmt.Errorf("genesis.json file already exists: %v", genFile) } - appGenState := mbm.DefaultGenesis(cdc) - - if stakingBondDenom != "" { - var stakingGenesis stakingtypes.GenesisState - - stakingRaw := appGenState[stakingtypes.ModuleName] - err := clientCtx.Codec.UnmarshalJSON(stakingRaw, &stakingGenesis) - if err != nil { - return err - } - - stakingGenesis.Params.BondDenom = stakingBondDenom - modifiedStakingStr, err := clientCtx.Codec.MarshalJSON(&stakingGenesis) - if err != nil { - return err - } - - appGenState[stakingtypes.ModuleName] = modifiedStakingStr + // Overwrites the SDK default denom for side-effects + if defaultDenom != "" { + sdk.DefaultBondDenom = defaultDenom } + appGenState := mbm.DefaultGenesis(cdc) appState, err := json.MarshalIndent(appGenState, "", " ") if err != nil { @@ -179,7 +164,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file") cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") - cmd.Flags().String(FlagStakingBondDenom, "", "genesis file staking bond denomination, if left blank default value is 'stake'") + cmd.Flags().String(FlagDefaultBondDenom, "", "genesis file default denomination, if left blank default value is 'stake'") return cmd } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 705af61cace3..e836f5a9e99f 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -120,7 +120,7 @@ func TestInitRecover(t *testing.T) { require.NoError(t, cmd.ExecuteContext(ctx)) } -func TestInitStakingBondDenom(t *testing.T) { +func TestInitDefaultBondDenom(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) @@ -143,7 +143,7 @@ func TestInitStakingBondDenom(t *testing.T) { cmd.SetArgs([]string{ "appnode-test", fmt.Sprintf("--%s=%s", cli.HomeFlag, home), - fmt.Sprintf("--%s=testtoken", genutilcli.FlagStakingBondDenom), + fmt.Sprintf("--%s=testtoken", genutilcli.FlagDefaultBondDenom), }) require.NoError(t, cmd.ExecuteContext(ctx)) }