Skip to content

Commit

Permalink
chore: rename migrations from v42, v43 to v1, v2
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 4, 2022
1 parent d6e5bb3 commit bb6cc7d
Show file tree
Hide file tree
Showing 44 changed files with 251 additions and 190 deletions.
8 changes: 4 additions & 4 deletions x/auth/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
v043 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v043"
v046 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v046"
v2 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v2"
v3 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v3"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand All @@ -28,7 +28,7 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
var iterErr error

m.keeper.IterateAccounts(ctx, func(account types.AccountI) (stop bool) {
wb, err := v043.MigrateAccount(ctx, account, m.queryServer)
wb, err := v2.MigrateAccount(ctx, account, m.queryServer)
if err != nil {
iterErr = err
return true
Expand All @@ -48,7 +48,7 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
// Migrate2to3 migrates from consensus version 2 to version 3. Specifically, for each account
// we index the account's ID to their address.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v046.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
return v3.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}

// Migrate3to4 migrates the x/auth module state from the consensus version 3 to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v042
package v1

const (
ModuleName = "auth"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package v043 creates in-place store migrations for fixing tracking
// Package v2 creates in-place store migrations for fixing tracking
// delegations with vesting accounts.
// ref: https://github.com/cosmos/cosmos-sdk/issues/8601
// ref: https://github.com/cosmos/cosmos-sdk/issues/8812
Expand All @@ -15,7 +15,7 @@
// https://github.com/cosmos/cosmos-sdk/issues/9070
// The preferred solution is to use inter-module communication (ADR-033), and
// this file will be refactored to use ADR-033 once it's ready.
package v043
package v2

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v043_test
package v2_test

import (
"fmt"
Expand All @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v4.ModuleName)
storeKey := sdk.NewKVStoreKey(v1.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v3

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046_test
package v3_test

import (
"math/rand"
Expand All @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -38,7 +39,7 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v4.ModuleName)
storeKey := sdk.NewKVStoreKey(v1.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
Expand Down
4 changes: 0 additions & 4 deletions x/auth/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

const (
ModuleName = "auth"
)

var ParamsKey = []byte{0x01}

// Migrate migrates the x/auth module state from the consensus version 3 to
Expand Down
3 changes: 2 additions & 1 deletion x/auth/migrations/v4/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
v1 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand All @@ -30,7 +31,7 @@ func TestMigrate(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v4.ModuleName)
storeKey := sdk.NewKVStoreKey(v1.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
Expand Down
4 changes: 2 additions & 2 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {

m := keeper.NewMigrator(am.accountKeeper, cfg.QueryServer(), am.legacySubspace)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(err)
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
}

if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
panic(err)
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
}

if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/authz/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v046 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v046"
v2 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -17,5 +17,5 @@ func NewMigrator(keeper Keeper) Migrator {

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v046.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v2

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v2

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v2

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046_test
package v2_test

import (
"testing"
Expand All @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
v046 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v046"
v2 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v2"
authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand Down Expand Up @@ -101,13 +101,13 @@ func TestMigration(t *testing.T) {

for _, g := range grants {
grant := g.authorization()
store.Set(v046.GrantStoreKey(g.grantee, g.granter, g.msgType), cdc.MustMarshal(&grant))
store.Set(v2.GrantStoreKey(g.grantee, g.granter, g.msgType), cdc.MustMarshal(&grant))
}

ctx = ctx.WithBlockTime(ctx.BlockTime().Add(1 * time.Hour))
require.NoError(t, v046.MigrateStore(ctx, authzKey, cdc))
require.NoError(t, v2.MigrateStore(ctx, authzKey, cdc))

require.NotNil(t, store.Get(v046.GrantStoreKey(grantee1, granter2, genericMsgType)))
require.NotNil(t, store.Get(v046.GrantStoreKey(grantee1, granter1, sendMsgType)))
require.Nil(t, store.Get(v046.GrantStoreKey(grantee2, granter2, genericMsgType)))
require.NotNil(t, store.Get(v2.GrantStoreKey(grantee1, granter2, genericMsgType)))
require.NotNil(t, store.Get(v2.GrantStoreKey(grantee1, granter1, sendMsgType)))
require.Nil(t, store.Get(v2.GrantStoreKey(grantee2, granter2, genericMsgType)))
}
3 changes: 2 additions & 1 deletion x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package authz
import (
"context"
"encoding/json"
"fmt"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
m := keeper.NewMigrator(am.keeper)
err := cfg.RegisterMigration(authz.ModuleName, 1, m.Migrate1to2)
if err != nil {
panic(err)
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", authz.ModuleName, err))
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/bank/migrations/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
"github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/golang/protobuf/proto"
)
Expand Down Expand Up @@ -40,9 +40,9 @@ func DenomMetadataKey(denom string) []byte {
// store. The key must not contain the perfix BalancesPrefix as the prefix store
// iterator discards the actual prefix.
func AddressFromBalancesStore(key []byte) sdk.AccAddress {
kv.AssertKeyAtLeastLength(key, 1+v042auth.AddrLen)
addr := key[:v042auth.AddrLen]
kv.AssertKeyLength(addr, v042auth.AddrLen)
kv.AssertKeyAtLeastLength(key, 1+v1auth.AddrLen)
addr := key[:v1auth.AddrLen]
kv.AssertKeyLength(addr, v1auth.AddrLen)
return sdk.AccAddress(addr)
}

Expand Down
4 changes: 2 additions & 2 deletions x/bank/migrations/v2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
v1 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v1"
"github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -63,7 +63,7 @@ func migrateBalanceKeys(store sdk.KVStore, logger log.Logger) {

for ; oldStoreIter.Valid(); oldStoreIter.Next() {
addr := v1.AddressFromBalancesStore(oldStoreIter.Key())
denom := oldStoreIter.Key()[v042auth.AddrLen:]
denom := oldStoreIter.Key()[v1auth.AddrLen:]
newStoreKey := types.CreatePrefixedAccountStoreKey(addr, denom)

// Set new key on store. Values don't change.
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/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"
"github.com/cosmos/cosmos-sdk/x/distribution/exported"
v043 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
v2 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v2"
v3 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v3"
)

Expand All @@ -20,7 +20,7 @@ func NewMigrator(keeper Keeper, legacySubspace exported.Subspace) Migrator {

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v043.MigrateStore(ctx, m.keeper.storeKey)
return v2.MigrateStore(ctx, m.keeper.storeKey)
}

// Migrate2to3 migrates the x/distribution module state from the consensus
Expand Down
3 changes: 1 addition & 2 deletions x/distribution/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtestutil "github.com/cosmos/cosmos-sdk/x/distribution/testutil"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

func TestParams(t *testing.T) {
ctrl := gomock.NewController(t)
key := sdk.NewKVStoreKey(disttypes.StoreKey)
key := sdk.NewKVStoreKey(types.StoreKey)
testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1})
Expand Down
24 changes: 0 additions & 24 deletions x/distribution/migrations/v043/store.go

This file was deleted.

Loading

0 comments on commit bb6cc7d

Please sign in to comment.