Skip to content

Commit

Permalink
fix(x/gov): migrations from 2 to 3 (min proposer deposit) (cosmos#298) (
Browse files Browse the repository at this point in the history
cosmos#302)

* git checkout -b roman/fix-gov-migrations

* register migrations
  • Loading branch information
p0mvn authored and [email protected] committed Jul 30, 2022
1 parent 643737b commit 5bcba4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions x/gov/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v043 "github.com/cosmos/cosmos-sdk/x/gov/legacy/v043"
v3 "github.com/cosmos/cosmos-sdk/x/gov/legacy/v3"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -19,3 +20,8 @@ func NewMigrator(keeper Keeper) Migrator {
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v043.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}

// Migrate2to3 migrates from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, m.keeper.paramSpace)
}
5 changes: 2 additions & 3 deletions x/gov/legacy/v3/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v3
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var minInitialDepositRatio = sdk.NewDec(25).Quo(sdk.NewDec(100))
Expand All @@ -16,12 +15,12 @@ var minInitialDepositRatio = sdk.NewDec(25).Quo(sdk.NewDec(100))
// The migration includes:
//
// - Setting the minimum deposit param in the paramstore.
func MigrateStore(ctx sdk.Context, paramstore paramtypes.Subspace) error {
func MigrateStore(ctx sdk.Context, paramstore types.ParamSubspace) error {
migrateParamsStore(ctx, paramstore)
return nil
}

func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
func migrateParamsStore(ctx sdk.Context, paramstore types.ParamSubspace) {
var depositParams types.DepositParams
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams)
depositParams.MinInitialDepositRatio = minInitialDepositRatio
Expand Down
4 changes: 4 additions & 0 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err != nil {
panic(err)
}
cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3)
if err != nil {
panic(err)
}
}

// InitGenesis performs genesis initialization for the gov module. It returns
Expand Down

0 comments on commit 5bcba4f

Please sign in to comment.