Skip to content

Commit

Permalink
fix: increase consensus version for staking module (#289)
Browse files Browse the repository at this point in the history
* fix: increase consensus version for staking module

* consensus version for package names

* fix panic: SetKeyTable() called on already initialized Subspace

* fix test
  • Loading branch information
p0mvn committed Jul 14, 2022
1 parent 2c4e05d commit b81ad24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions x/staking/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v043 "github.com/cosmos/cosmos-sdk/x/staking/legacy/v043"
v046 "github.com/cosmos/cosmos-sdk/x/staking/legacy/v046"
v3 "github.com/cosmos/cosmos-sdk/x/staking/legacy/v3"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -23,5 +23,5 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {

// Migrate1to2 migrates from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v046.MigrateStore(ctx, m.keeper.paramstore)
return v3.MigrateStore(ctx, m.keeper.paramstore)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package v046
package v3

import (
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 to v0.45.
// MigrateStore performs in-place store migrations for consensus version 3
// in the staking module.
// Please note that this is the first version that switches from using
// SDK versioning (v046 etc) for package names to consensus versioning
// of the staking module.
// The migration includes:
//
// - Setting the MinCommissionRate param in the paramstore
Expand All @@ -18,6 +22,5 @@ func MigrateStore(ctx sdk.Context, paramstore paramtypes.Subspace) error {

func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
DefaultMinSelfDelegation := sdk.ZeroInt()
paramstore.WithKeyTable(types.ParamKeyTable())
paramstore.Set(ctx, types.KeyMinSelfDelegation, DefaultMinSelfDelegation)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046_test
package v3_test

import (
"testing"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
v046staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v046"
v3 "github.com/cosmos/cosmos-sdk/x/staking/legacy/v3"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -23,8 +23,10 @@ func TestStoreMigration(t *testing.T) {
// Check no params
require.False(t, paramstore.Has(ctx, types.KeyMinSelfDelegation))

paramstore = paramstore.WithKeyTable(types.ParamKeyTable())

// Run migrations.
err := v046staking.MigrateStore(ctx, paramstore)
err := v3.MigrateStore(ctx, paramstore)
require.NoError(t, err)

// Make sure the new params are set.
Expand Down
2 changes: 1 addition & 1 deletion x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }
func (AppModule) ConsensusVersion() uint64 { return 3 }

// BeginBlock returns the begin blocker for the staking module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down

0 comments on commit b81ad24

Please sign in to comment.