fix: add params migration (#14992)
This commit is contained in:
parent
cee91a5fc5
commit
0f99829fab
33
UPGRADING.md
33
UPGRADING.md
@ -47,8 +47,9 @@ ClevelDB, BoltDB and BadgerDB are not supported anymore. To migrate from a unsup
|
||||
|
||||
GoLevelDB version has been pinned to `v1.0.1-0.20210819022825-2ae1ddf74ef7`, following versions might cause unexpected behavior.
|
||||
See related issues:
|
||||
- [issue #14949 on cosmos-sdk](https://github.com/cosmos/cosmos-sdk/issues/14949)
|
||||
- [issue #25413 on go-ethereum](https://github.com/ethereum/go-ethereum/pull/25413)
|
||||
|
||||
* [issue #14949 on cosmos-sdk](https://github.com/cosmos/cosmos-sdk/issues/14949)
|
||||
* [issue #25413 on go-ethereum](https://github.com/ethereum/go-ethereum/pull/25413)
|
||||
|
||||
### Protobuf
|
||||
|
||||
@ -266,6 +267,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
|
||||
@ -336,20 +346,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`
|
||||
|
||||
@ -442,7 +449,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`
|
||||
|
||||
@ -18,21 +18,19 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
|
||||
simappparams "cosmossdk.io/simapp/params"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/evidence"
|
||||
evidencekeeper "cosmossdk.io/x/evidence/keeper"
|
||||
evidencetypes "cosmossdk.io/x/evidence/types"
|
||||
"cosmossdk.io/x/nft"
|
||||
nftkeeper "cosmossdk.io/x/nft/keeper"
|
||||
nftmodule "cosmossdk.io/x/nft/module"
|
||||
|
||||
"cosmossdk.io/x/upgrade"
|
||||
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
|
||||
upgradetypes "cosmossdk.io/x/upgrade/types"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/feegrant"
|
||||
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
|
||||
feegrantmodule "cosmossdk.io/x/feegrant/module"
|
||||
"cosmossdk.io/x/nft"
|
||||
nftkeeper "cosmossdk.io/x/nft/keeper"
|
||||
nftmodule "cosmossdk.io/x/nft/module"
|
||||
"cosmossdk.io/x/upgrade"
|
||||
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
|
||||
upgradetypes "cosmossdk.io/x/upgrade/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -85,7 +83,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 +279,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])
|
||||
@ -741,7 +738,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
|
||||
|
||||
@ -7,7 +7,17 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
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"
|
||||
)
|
||||
|
||||
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
|
||||
@ -19,17 +29,45 @@ 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()
|
||||
case banktypes.ModuleName:
|
||||
keyTable = banktypes.ParamKeyTable()
|
||||
case stakingtypes.ModuleName:
|
||||
keyTable = stakingtypes.ParamKeyTable()
|
||||
case minttypes.ModuleName:
|
||||
keyTable = minttypes.ParamKeyTable()
|
||||
case distrtypes.ModuleName:
|
||||
keyTable = distrtypes.ParamKeyTable()
|
||||
case slashingtypes.ModuleName:
|
||||
keyTable = slashingtypes.ParamKeyTable()
|
||||
case govtypes.ModuleName:
|
||||
keyTable = govv1.ParamKeyTable()
|
||||
case crisistypes.ModuleName:
|
||||
keyTable = crisistypes.ParamKeyTable()
|
||||
}
|
||||
|
||||
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 CometBFT consensus parameters from x/params module to a
|
||||
// dedicated x/consensus module.
|
||||
// Migrate CometBFT 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 at [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md)
|
||||
// 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)
|
||||
},
|
||||
@ -41,7 +79,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))
|
||||
|
||||
@ -9,7 +9,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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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{})
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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{})
|
||||
}
|
||||
|
||||
@ -51,10 +51,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 {
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user