Skip to content

Commit

Permalink
chore: remove x/params module (#21)
Browse files Browse the repository at this point in the history
x/params was there in gaia v15 for retro-compatibility and maybe because
of the x/globalfee modules that didn't have its own `MsgUpdateParams`.
For a new chain there's no need for it, as all modules have migrated to
the new params paradigm, where their params are now stored in their own
store rather than in the x/params module store (see [1])

[1]: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-046-module-params.md
  • Loading branch information
tbruyelle authored Sep 24, 2024
1 parent 3fd1692 commit 0ec77cc
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 311 deletions.
82 changes: 0 additions & 82 deletions app/gov_handlers.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package atomone

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/upgrade/plan"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

Expand All @@ -24,7 +19,6 @@ import (
)

var (
paramsChangeProposalHandler = govclient.NewProposalHandler(newSubmitParamChangeProposalTxCmd)
upgradeProposalHandler = govclient.NewProposalHandler(newCmdSubmitLegacyUpgradeProposal)
cancelUpgradeProposalHandler = govclient.NewProposalHandler(newCmdSubmitLegacyCancelUpgradeProposal)
)
Expand All @@ -33,86 +27,10 @@ func init() {
// Proposal types are registered within their specific module in the SDK, but
// using the legacy gov module. To register them in the atomone gov module,
// we need to do it here.
govv1beta1.RegisterProposalType(paramproposal.ProposalTypeChange)
govv1beta1.RegisterProposalType(upgradetypes.ProposalTypeSoftwareUpgrade)
govv1beta1.RegisterProposalType(upgradetypes.ProposalTypeCancelSoftwareUpgrade)
}

// NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating
// a parameter change proposal governance transaction.
//
// NOTE: copy of x/params/client.newSubmitParamChangeProposalTxCmd() except
// that it creates a atomone.gov.MsgSubmitProposal instead of a
// cosmos.gov.MsgSubmitProposal.
func newSubmitParamChangeProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "param-change [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a parameter change proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a parameter proposal along with an initial deposit.
The proposal details must be supplied via a JSON file. For values that contains
objects, only non-empty fields will be updated.
IMPORTANT: Currently parameter changes are evaluated but not validated, so it is
very important that any "value" change is valid (ie. correct type and within bounds)
for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal.
Proper vetting of a parameter change proposal should prevent this from happening
(no deposits should occur during the governance process), but it should be noted
regardless.
Example:
$ %s tx gov submit-proposal param-change <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Staking Param Change",
"description": "Update max validators",
"changes": [
{
"subspace": "staking",
"key": "MaxValidators",
"value": 105
}
],
"deposit": "1000stake"
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := paramscutils.ParseParamChangeProposalJSON(clientCtx.LegacyAmino, args[0])
if err != nil {
return err
}

from := clientCtx.GetFromAddress()
content := paramproposal.NewParameterChangeProposal(
proposal.Title, proposal.Description, proposal.Changes.ToParamChanges(),
)

deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}

msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}

const (
// Deprecated: only used for v1beta1 legacy proposals.
FlagUpgradeHeight = "upgrade-height"
Expand Down
43 changes: 0 additions & 43 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ import (
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand All @@ -47,7 +43,6 @@ import (

govkeeper "github.com/atomone-hub/atomone/x/gov/keeper"
govtypes "github.com/atomone-hub/atomone/x/gov/types"
govv1 "github.com/atomone-hub/atomone/x/gov/types/v1"
govv1beta1 "github.com/atomone-hub/atomone/x/gov/types/v1beta1"
)

Expand All @@ -68,7 +63,6 @@ type AppKeepers struct {
GovKeeper *govkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
Expand Down Expand Up @@ -104,13 +98,6 @@ func NewAppKeeper(
os.Exit(1)
}

appKeepers.ParamsKeeper = initParamsKeeper(
appCodec,
legacyAmino,
appKeepers.keys[paramstypes.StoreKey],
appKeepers.tkeys[paramstypes.TStoreKey],
)

// set the BaseApp's parameter store
appKeepers.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -245,13 +232,9 @@ func NewAppKeeper(
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
//
// TODO(tb): remove completely govRouter and rely only on proposals that
// embed sdk.Msg ?
govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, govv1beta1.WrapSDKHandler(params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper))).
AddRoute(upgradetypes.RouterKey, govv1beta1.WrapSDKHandler(upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)))

// Set legacy router for backwards compatibility with gov v1beta1
Expand All @@ -268,29 +251,3 @@ func NewAppKeeper(

return appKeepers
}

// GetSubspace returns a param subspace for a given module name.
func (appKeepers *AppKeepers) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, ok := appKeepers.ParamsKeeper.GetSubspace(moduleName)
if !ok {
panic("couldn't load subspace for module: " + moduleName)
}
return subspace
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

//nolint: staticcheck // SA1019: moduletypes.ParamKeyTable is deprecated
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable()) //nolint:staticcheck // SA1019
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) //nolint:staticcheck // SA1019
paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) //nolint:staticcheck // SA1019
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) //nolint:staticcheck // SA1019
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck // SA1019
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) //nolint:staticcheck // SA1019

return paramsKeeper
}
5 changes: 0 additions & 5 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand All @@ -33,7 +32,6 @@ func (appKeepers *AppKeepers) GenerateKeys() {
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
capabilitytypes.StoreKey,
Expand All @@ -42,9 +40,6 @@ func (appKeepers *AppKeepers) GenerateKeys() {
consensusparamtypes.StoreKey,
)

// Define transient store keys
appKeepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey)

// MemKeys are for information that is stored only in RAM.
appKeepers.memKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
}
Expand Down
40 changes: 15 additions & 25 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
sdkparams "github.com/cosmos/cosmos-sdk/x/params"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand Down Expand Up @@ -64,14 +62,11 @@ var ModuleBasics = module.NewBasicManager(
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
// TODO remove since no compat needed with old gov handler system?
[]govclient.ProposalHandler{
paramsChangeProposalHandler,
upgradeProposalHandler,
cancelUpgradeProposalHandler,
},
),
sdkparams.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
Expand All @@ -96,21 +91,20 @@ func appModules(
app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
auth.NewAppModule(appCodec, app.AccountKeeper, nil, nil),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, nil),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, nil),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
sdkparams.NewAppModule(app.ParamsKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
}
}
Expand All @@ -125,16 +119,15 @@ func simulationModules(
appCodec := encodingConfig.Marshaler

return []module.AppModuleSimulation{
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, nil),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, nil),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
sdkparams.NewAppModule(app.ParamsKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, nil),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
evidence.NewAppModule(app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
}
Expand Down Expand Up @@ -169,7 +162,6 @@ func orderBeginBlockers() []string {
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
}
Expand Down Expand Up @@ -198,7 +190,6 @@ func orderEndBlockers() []string {
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -228,7 +219,6 @@ func orderInitBlockers() []string {
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
distribtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
paramsproptypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -52,8 +51,6 @@ func init() {
feegrant.RegisterInterfaces(encodingConfig.InterfaceRegistry)
govv1types.RegisterInterfaces(encodingConfig.InterfaceRegistry)
govv1beta1types.RegisterInterfaces(encodingConfig.InterfaceRegistry)
paramsproptypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
paramsproptypes.RegisterLegacyAminoCodec(encodingConfig.Amino)
feegrant.RegisterLegacyAminoCodec(encodingConfig.Amino)
slashingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)

Expand Down
16 changes: 8 additions & 8 deletions x/gov/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/atomone-hub/atomone/x/gov/keeper"
"github.com/atomone-hub/atomone/x/gov/types"
v1 "github.com/atomone-hub/atomone/x/gov/types/v1"
"github.com/atomone-hub/atomone/x/gov/types/v1beta1"
govkeeper "github.com/atomone-hub/atomone/x/gov/keeper"
govtypes "github.com/atomone-hub/atomone/x/gov/types"
govv1 "github.com/atomone-hub/atomone/x/gov/types/v1"
govv1beta1 "github.com/atomone-hub/atomone/x/gov/types/v1beta1"
)

var (
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
TestProposal = v1beta1.NewTextProposal("Test", "description")
TestProposal = govv1beta1.NewTextProposal("Test", "description")
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
TestCommissionRates = stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
)

// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes.
func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent {
msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String())
func mkTestLegacyContent(t *testing.T) *govv1.MsgExecLegacyContent {
msgContent, err := govv1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(govtypes.ModuleName).String())
require.NoError(t, err)

return msgContent
Expand Down Expand Up @@ -104,7 +104,7 @@ var pubkeys = []cryptotypes.PubKey{
type suite struct {
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
GovKeeper *keeper.Keeper
GovKeeper *govkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
App *runtime.App
}
Expand Down
Loading

0 comments on commit 0ec77cc

Please sign in to comment.