Skip to content

Commit

Permalink
Merge pull request #17 from hyle-team/feature/migrations-staking
Browse files Browse the repository at this point in the history
Feature/migrations staking
  • Loading branch information
EduardMikhrin authored Nov 21, 2024
2 parents fce53ff + 1f4912c commit d3145c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions x/staking/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
v043 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v043"
v046 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v046"
v04626 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v046_26"
v04628 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v046_28"
)

// Migrator is a struct for handling in-place store migrations.
Expand Down Expand Up @@ -33,3 +34,8 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v04626.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}

// Migrate4to5 migrates x/staking state from consensus version 4 to 5.
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
return v04628.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc, m.keeper.paramstore)
}
28 changes: 28 additions & 0 deletions x/staking/migrations/v046_28/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v046_28

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

// MigrateStore performs in-place store migrations from v0.43/v0.44/v0.45 to v0.46.
// The migration includes:
//
// - Setting the MinDelegationAmount param in the paramstore
func MigrateStore(ctx sdk.Context, _ storetypes.StoreKey, _ codec.BinaryCodec, paramstore paramtypes.Subspace) error {
migrateParamsStore(ctx, paramstore)

return nil
}

func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
if paramstore.HasKeyTable() {
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
return
}
paramstore.WithKeyTable(types.ParamKeyTable())
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate)
}
6 changes: 4 additions & 2 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const (
consensusVersion uint64 = 4
consensusVersion uint64 = 5
)

var (
Expand Down Expand Up @@ -143,7 +143,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
panic(err)
}

if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil {
panic(err)
}
}

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

0 comments on commit d3145c3

Please sign in to comment.