From b81ad24550fa205d6c3553b9f64f7d5818dbe212 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 14 Jul 2022 18:31:38 -0400 Subject: [PATCH] fix: increase consensus version for staking module (#289) * fix: increase consensus version for staking module * consensus version for package names * fix panic: SetKeyTable() called on already initialized Subspace * fix test --- x/staking/keeper/migrations.go | 4 ++-- x/staking/legacy/{v046 => v3}/store.go | 9 ++++++--- x/staking/legacy/{v046 => v3}/store_test.go | 8 +++++--- x/staking/module.go | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) rename x/staking/legacy/{v046 => v3}/store.go (67%) rename x/staking/legacy/{v046 => v3}/store_test.go (83%) diff --git a/x/staking/keeper/migrations.go b/x/staking/keeper/migrations.go index 55a15aca0294..2ada854c0caf 100644 --- a/x/staking/keeper/migrations.go +++ b/x/staking/keeper/migrations.go @@ -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. @@ -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) } diff --git a/x/staking/legacy/v046/store.go b/x/staking/legacy/v3/store.go similarity index 67% rename from x/staking/legacy/v046/store.go rename to x/staking/legacy/v3/store.go index 07e2e701f132..6dcfe5ec9a5b 100644 --- a/x/staking/legacy/v046/store.go +++ b/x/staking/legacy/v3/store.go @@ -1,4 +1,4 @@ -package v046 +package v3 import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -6,7 +6,11 @@ import ( "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 @@ -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) } diff --git a/x/staking/legacy/v046/store_test.go b/x/staking/legacy/v3/store_test.go similarity index 83% rename from x/staking/legacy/v046/store_test.go rename to x/staking/legacy/v3/store_test.go index f4897be0effd..67ed29cbcdaf 100644 --- a/x/staking/legacy/v046/store_test.go +++ b/x/staking/legacy/v3/store_test.go @@ -1,4 +1,4 @@ -package v046_test +package v3_test import ( "testing" @@ -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" ) @@ -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. diff --git a/x/staking/module.go b/x/staking/module.go index 7ee442ad7660..087b79677b54 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -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) {