diff --git a/UPGRADING.md b/UPGRADING.md index 7493d0577270..db8a9cd26755 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -145,6 +145,15 @@ The module name is assumed by `baseapp` to be the second element of the message In case a module does not follow the standard message path, (e.g. IBC), it is advised to keep emitting the module name event. `Baseapp` only emits that event if the module have not already done so. +### `x/params` + +The `params` module was deprecated since v0.46. The Cosmos SDK has migrated away from `x/params` for its own modules. +Cosmos SDK modules now store their parameters directly in its repective modules. +The `params` module will be removed in `v0.48`, as mentioned [in v0.46 release](https://github.com/cosmos/cosmos-sdk/blob/v0.46.1/UPGRADING.md#xparams). It is strongly encouraged to migrate away from `x/params` before `v0.48`. + +When performing a chain migration, the params table must be initizalied manually. This was done in the modules keepers in previous versions. +Have a look at `simapp.RegisterUpgradeHandlers()` for an example. + #### `x/gov` ##### Minimum Proposal Deposit At Time of Submission @@ -215,20 +224,17 @@ func (app SimApp) RegisterUpgradeHandlers() { The old params module is required to still be imported in your app.go in order to handle this migration. -##### App.go Changes +##### `app.go` changes -Previous: +When using an `app.go` without App Wiring, the following changes are required: -```go -bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) +```diff +- bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) ++ app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamstypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) ++ bApp.SetParamStore(&app.ConsensusParamsKeeper) ``` -After: - -```go -app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[upgradetypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) -bApp.SetParamStore(&app.ConsensusParamsKeeper) -``` +When using App Wiring, the paramater store is automatically set for you. #### `x/nft` @@ -321,7 +327,7 @@ mistakes. #### `x/params` -* The `x/params` module has been depreacted in favour of each module housing and providing way to modify their parameters. Each module that has parameters that are changable during runtime have an authority, the authority can be a module or user account. The Cosmos-SDK team recommends migrating modules away from using the param module. An example of how this could look like can be found [here](https://github.com/cosmos/cosmos-sdk/pull/12363). +* The `x/params` module has been depreacted in favour of each module housing and providing way to modify their parameters. Each module that has parameters that are changable during runtime have an authority, the authority can be a module or user account. The Cosmos SDK team recommends migrating modules away from using the param module. An example of how this could look like can be found [here](https://github.com/cosmos/cosmos-sdk/pull/12363). * The Param module will be maintained until April 18, 2023. At this point the module will reach end of life and be removed from the Cosmos SDK. #### `x/gov` diff --git a/simapp/app.go b/simapp/app.go index 9cf0b0f865c7..cc511a047718 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -76,7 +76,6 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -282,7 +281,7 @@ func NewSimApp( app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[upgradetypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(&app.ConsensusParamsKeeper) app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) @@ -722,7 +721,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(minttypes.ModuleName) paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) + paramsKeeper.Subspace(govtypes.ModuleName) paramsKeeper.Subspace(crisistypes.ModuleName) return paramsKeeper diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 1324d9d98e8e..77189559f399 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -5,7 +5,17 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + 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" ) @@ -18,15 +28,46 @@ import ( const UpgradeName = "v046-to-v047" func (app SimApp) RegisterUpgradeHandlers() { + // Set param key table for params module migration + for _, subspace := range app.ParamsKeeper.GetSubspaces() { + subspace := subspace + + var keyTable paramstypes.KeyTable + switch subspace.Name() { + case authtypes.ModuleName: + keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + case banktypes.ModuleName: + keyTable = banktypes.ParamKeyTable() //nolint:staticcheck + case stakingtypes.ModuleName: + keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + case minttypes.ModuleName: + keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + case slashingtypes.ModuleName: + keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + case govtypes.ModuleName: + keyTable = govv1.ParamKeyTable() //nolint:staticcheck + case crisistypes.ModuleName: + keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + } + + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) app.UpgradeKeeper.SetUpgradeHandler( UpgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Migrate Tendermint consensus parameters from x/params module to a - // dedicated x/consensus module. + // Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module. baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) + // Note: this migration is optional, + // You can include x/gov proposal migration documented in [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md) + return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) }, ) @@ -37,7 +78,12 @@ func (app SimApp) RegisterUpgradeHandlers() { } if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := storetypes.StoreUpgrades{} + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{ + consensustypes.ModuleName, + crisistypes.ModuleName, + }, + } // configure store loader that checks if version == upgradeHeight and applies store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) diff --git a/x/auth/migrations/v4/migrate.go b/x/auth/migrations/v4/migrate.go index 93b8658408c8..6a1c8febc12f 100644 --- a/x/auth/migrations/v4/migrate.go +++ b/x/auth/migrations/v4/migrate.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -var ParamsKey = []byte{0x01} +var ParamsKey = []byte{0x00} // Migrate migrates the x/auth module state from the consensus version 3 to // version 4. Specifically, it takes the parameters that are currently stored diff --git a/x/auth/migrations/v4/migrator_test.go b/x/auth/migrations/v4/migrate_test.go similarity index 100% rename from x/auth/migrations/v4/migrator_test.go rename to x/auth/migrations/v4/migrate_test.go diff --git a/x/auth/types/params.go b/x/auth/types/params.go index 177cf49a027c..b157eb220eaf 100644 --- a/x/auth/types/params.go +++ b/x/auth/types/params.go @@ -14,9 +14,7 @@ const ( ) // NewParams creates a new Params object -func NewParams( - maxMemoCharacters, txSigLimit, txSizeCostPerByte, sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64, -) Params { +func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte, sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64) Params { return Params{ MaxMemoCharacters: maxMemoCharacters, TxSigLimit: txSigLimit, diff --git a/x/auth/types/params_legacy.go b/x/auth/types/params_legacy.go index d5ebfb29dc29..8800f5822283 100644 --- a/x/auth/types/params_legacy.go +++ b/x/auth/types/params_legacy.go @@ -20,9 +20,7 @@ var ( var _ paramtypes.ParamSet = &Params{} -// ParamKeyTable for auth module -// -// Deprecated. +// Deprecated: ParamKeyTable for auth module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } diff --git a/x/crisis/types/legacy_params.go b/x/crisis/types/legacy_params.go index 100bf229c7b0..bcb689a4fadd 100644 --- a/x/crisis/types/legacy_params.go +++ b/x/crisis/types/legacy_params.go @@ -10,7 +10,7 @@ import ( // ParamStoreKeyConstantFee is the constant fee parameter var ParamStoreKeyConstantFee = []byte("ConstantFee") -// type declaration for parameters +// Deprecated: Type declaration for parameters func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable( paramtypes.NewParamSetPair(ParamStoreKeyConstantFee, sdk.Coin{}, validateConstantFee), diff --git a/x/distribution/types/params_legacy.go b/x/distribution/types/params_legacy.go index 26ebfc8b5d0e..4805e8bd8c8c 100644 --- a/x/distribution/types/params_legacy.go +++ b/x/distribution/types/params_legacy.go @@ -8,12 +8,12 @@ var ( ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled") ) -// ParamKeyTable returns the parameter key table. +// Deprecated: ParamKeyTable returns the parameter key table. func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -// ParamSetPairs returns the parameter set pairs. +// Deprecated: ParamSetPairs returns the parameter set pairs. func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), diff --git a/x/gov/module.go b/x/gov/module.go index 9f9ed4f6c71e..b497d3f8a4e7 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -216,7 +216,7 @@ func ProvideModule(in GovInputs) GovOutputs { } func ProvideKeyTable() paramtypes.KeyTable { - return v1.ParamKeyTable() + return v1.ParamKeyTable() //nolint:staticcheck } func InvokeAddRoutes(keeper *keeper.Keeper, routes []v1beta1.HandlerRoute) { diff --git a/x/gov/types/v1/params_legacy.go b/x/gov/types/v1/params_legacy.go index 1f8ba56ea75f..38fb6b84ff10 100644 --- a/x/gov/types/v1/params_legacy.go +++ b/x/gov/types/v1/params_legacy.go @@ -16,7 +16,7 @@ var ( ParamStoreKeyTallyParams = []byte("tallyparams") ) -// ParamKeyTable - Key declaration for parameters +// Deprecated: ParamKeyTable - Key declaration for parameters func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable( paramtypes.NewParamSetPair(ParamStoreKeyDepositParams, DepositParams{}, validateDepositParams), diff --git a/x/mint/types/params_legacy.go b/x/mint/types/params_legacy.go index 640ad2db223a..23354e2f89ea 100644 --- a/x/mint/types/params_legacy.go +++ b/x/mint/types/params_legacy.go @@ -19,9 +19,7 @@ var ( KeyBlocksPerYear = []byte("BlocksPerYear") ) -// ParamTable for minting module. -// -// Deprecated. +// Deprecated: ParamTable for minting module. func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index f90914f3a62a..01445fc30f07 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -50,10 +50,10 @@ func (s Subspace) HasKeyTable() bool { // WithKeyTable initializes KeyTable and returns modified Subspace func (s Subspace) WithKeyTable(table KeyTable) Subspace { if table.m == nil { - panic("SetKeyTable() called with nil KeyTable") + panic("WithKeyTable() called with nil KeyTable") } if len(s.table.m) != 0 { - panic("SetKeyTable() called on already initialized Subspace") + panic("WithKeyTable() called on already initialized Subspace") } for k, v := range table.m { diff --git a/x/slashing/types/params_legacy.go b/x/slashing/types/params_legacy.go index bd97023f6a47..f7ea30db0d55 100644 --- a/x/slashing/types/params_legacy.go +++ b/x/slashing/types/params_legacy.go @@ -18,16 +18,12 @@ var ( KeySlashFractionDowntime = []byte("SlashFractionDowntime") ) -// ParamKeyTable for slashing module -// -// Deprecated. +// Deprecated: ParamKeyTable for slashing module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -// ParamSetPairs - Implements params.ParamSet -// -// Deprecated. +// Deprecated: ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeySignedBlocksWindow, &p.SignedBlocksWindow, validateSignedBlocksWindow),