Skip to content

Commit

Permalink
fix(x/gov): migrations from 2 to 3 (min proposer deposit) (#298)
Browse files Browse the repository at this point in the history
* git checkout -b roman/fix-gov-migrations

* register migrations

(cherry picked from commit 51bfa90)

# Conflicts:
#	x/gov/legacy/v3/store.go
  • Loading branch information
p0mvn authored and mergify[bot] committed Jul 27, 2022
1 parent df75693 commit ebdf2c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 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)
}
28 changes: 28 additions & 0 deletions x/gov/legacy/v3/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)

var minInitialDepositRatio = sdk.NewDec(25).Quo(sdk.NewDec(100))

// MigrateStore performs in-place store migrations for consensus version 3
// in the gov module.
// Please note that this is the first version that switches from using
// SDK versioning (v043 etc) for package names to consensus versioning
// of the gov module.
// The migration includes:
//
// - Setting the minimum deposit param in the paramstore.
func MigrateStore(ctx sdk.Context, paramstore types.ParamSubspace) error {
migrateParamsStore(ctx, paramstore)
return nil
}

func migrateParamsStore(ctx sdk.Context, paramstore types.ParamSubspace) {
var depositParams types.DepositParams
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams)
depositParams.MinInitialDepositRatio = minInitialDepositRatio
paramstore.Set(ctx, types.ParamStoreKeyDepositParams, depositParams)
}
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 ebdf2c3

Please sign in to comment.