refactor: rename migrations from v42, v43, v{SDK} to v1, v2, v{Consensus} (#13772)
* chore: rename migrations from v42, v43 to v1, v2 * group migration should be in #13742 * updates
This commit is contained in:
parent
d6e5bb3669
commit
7efeb826e0
@ -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"
|
||||
)
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package v042
|
||||
package v1
|
||||
|
||||
const (
|
||||
ModuleName = "auth"
|
||||
@ -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
|
||||
@ -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"
|
||||
@ -1,4 +1,4 @@
|
||||
package v043_test
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -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"
|
||||
@ -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)
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v3
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046_test
|
||||
package v3_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
@ -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"
|
||||
@ -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)
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
)
|
||||
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v2
|
||||
|
||||
import (
|
||||
"time"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046_test
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -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"
|
||||
@ -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,6 +3,7 @@ package authz
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
)
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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.
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -11,7 +11,6 @@ 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"
|
||||
@ -19,7 +18,7 @@ import (
|
||||
|
||||
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})
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
package v043
|
||||
|
||||
import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v042distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v042"
|
||||
)
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Change addresses to be length-prefixed.
|
||||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
MigratePrefixAddress(store, v042distribution.ValidatorOutstandingRewardsPrefix)
|
||||
MigratePrefixAddress(store, v042distribution.DelegatorWithdrawAddrPrefix)
|
||||
MigratePrefixAddressAddress(store, v042distribution.DelegatorStartingInfoPrefix)
|
||||
MigratePrefixAddressBytes(store, v042distribution.ValidatorHistoricalRewardsPrefix)
|
||||
MigratePrefixAddress(store, v042distribution.ValidatorCurrentRewardsPrefix)
|
||||
MigratePrefixAddress(store, v042distribution.ValidatorAccumulatedCommissionPrefix)
|
||||
MigratePrefixAddressBytes(store, v042distribution.ValidatorSlashEventPrefix)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -5,7 +5,7 @@ import (
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -59,7 +59,7 @@ var (
|
||||
func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2)
|
||||
addr := key[1:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
return sdk.ValAddress(addr)
|
||||
}
|
||||
|
||||
@ -67,29 +67,29 @@ func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress)
|
||||
func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2)
|
||||
addr := key[1:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
return sdk.AccAddress(addr)
|
||||
}
|
||||
|
||||
// gets the addresses from a delegator starting info key
|
||||
func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2+v042auth.AddrLen)
|
||||
addr := key[1 : 1+v042auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyAtLeastLength(key, 2+v1auth.AddrLen)
|
||||
addr := key[1 : 1+v1auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
valAddr = sdk.ValAddress(addr)
|
||||
addr = key[1+v042auth.AddrLen:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
addr = key[1+v1auth.AddrLen:]
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
delAddr = sdk.AccAddress(addr)
|
||||
return
|
||||
}
|
||||
|
||||
// gets the address & period from a validator's historical rewards key
|
||||
func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) {
|
||||
kv.AssertKeyAtLeastLength(key, 2+v042auth.AddrLen)
|
||||
addr := key[1 : 1+v042auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyAtLeastLength(key, 2+v1auth.AddrLen)
|
||||
addr := key[1 : 1+v1auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
valAddr = sdk.ValAddress(addr)
|
||||
b := key[1+v042auth.AddrLen:]
|
||||
b := key[1+v1auth.AddrLen:]
|
||||
kv.AssertKeyLength(addr, 8)
|
||||
period = binary.LittleEndian.Uint64(b)
|
||||
return
|
||||
@ -99,7 +99,7 @@ func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddr
|
||||
func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2)
|
||||
addr := key[1:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
return sdk.ValAddress(addr)
|
||||
}
|
||||
|
||||
@ -107,17 +107,17 @@ func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||
func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2)
|
||||
addr := key[1:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
return sdk.ValAddress(addr)
|
||||
}
|
||||
|
||||
// gets the height from a validator's slash event key
|
||||
func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) {
|
||||
kv.AssertKeyAtLeastLength(key, 2+v042auth.AddrLen)
|
||||
addr := key[1 : 1+v042auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyAtLeastLength(key, 2+v1auth.AddrLen)
|
||||
addr := key[1 : 1+v1auth.AddrLen]
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
valAddr = sdk.ValAddress(addr)
|
||||
startB := 1 + v042auth.AddrLen
|
||||
startB := 1 + v1auth.AddrLen
|
||||
kv.AssertKeyAtLeastLength(key, startB+9)
|
||||
b := key[startB : startB+8] // the next 8 bytes represent the height
|
||||
height = binary.BigEndian.Uint64(b)
|
||||
@ -1,10 +1,10 @@
|
||||
package v043
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
|
||||
v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
|
||||
)
|
||||
|
||||
// MigratePrefixAddress is a helper function that migrates all keys of format:
|
||||
@ -39,8 +39,8 @@ func MigratePrefixAddressBytes(store sdk.KVStore, prefixBz []byte) {
|
||||
defer oldStoreIter.Close()
|
||||
|
||||
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
||||
addr := oldStoreIter.Key()[:v042auth.AddrLen]
|
||||
endBz := oldStoreIter.Key()[v042auth.AddrLen:]
|
||||
addr := oldStoreIter.Key()[:v1auth.AddrLen]
|
||||
endBz := oldStoreIter.Key()[v1auth.AddrLen:]
|
||||
newStoreKey := append(append(prefixBz, address.MustLengthPrefix(addr)...), endBz...)
|
||||
|
||||
// Set new key on store. Values don't change.
|
||||
@ -60,8 +60,8 @@ func MigratePrefixAddressAddress(store sdk.KVStore, prefixBz []byte) {
|
||||
defer oldStoreIter.Close()
|
||||
|
||||
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
||||
addr1 := oldStoreIter.Key()[:v042auth.AddrLen]
|
||||
addr2 := oldStoreIter.Key()[v042auth.AddrLen:]
|
||||
addr1 := oldStoreIter.Key()[:v1auth.AddrLen]
|
||||
addr2 := oldStoreIter.Key()[v1auth.AddrLen:]
|
||||
newStoreKey := append(append(prefixBz, address.MustLengthPrefix(addr1)...), address.MustLengthPrefix(addr2)...)
|
||||
|
||||
// Set new key on store. Values don't change.
|
||||
24
x/distribution/migrations/v2/store.go
Normal file
24
x/distribution/migrations/v2/store.go
Normal file
@ -0,0 +1,24 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v1"
|
||||
)
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Change addresses to be length-prefixed.
|
||||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
MigratePrefixAddress(store, v1.ValidatorOutstandingRewardsPrefix)
|
||||
MigratePrefixAddress(store, v1.DelegatorWithdrawAddrPrefix)
|
||||
MigratePrefixAddressAddress(store, v1.DelegatorStartingInfoPrefix)
|
||||
MigratePrefixAddressBytes(store, v1.ValidatorHistoricalRewardsPrefix)
|
||||
MigratePrefixAddress(store, v1.ValidatorCurrentRewardsPrefix)
|
||||
MigratePrefixAddress(store, v1.ValidatorAccumulatedCommissionPrefix)
|
||||
MigratePrefixAddressBytes(store, v1.ValidatorSlashEventPrefix)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package v043_test
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v042distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v042"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v1"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v2"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
)
|
||||
|
||||
@ -32,47 +32,47 @@ func TestStoreMigration(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"FeePoolKey",
|
||||
v042distribution.FeePoolKey,
|
||||
v1.FeePoolKey,
|
||||
types.FeePoolKey,
|
||||
},
|
||||
{
|
||||
"ProposerKey",
|
||||
v042distribution.ProposerKey,
|
||||
v1.ProposerKey,
|
||||
types.ProposerKey,
|
||||
},
|
||||
{
|
||||
"ValidatorOutstandingRewards",
|
||||
v042distribution.GetValidatorOutstandingRewardsKey(valAddr),
|
||||
v1.GetValidatorOutstandingRewardsKey(valAddr),
|
||||
types.GetValidatorOutstandingRewardsKey(valAddr),
|
||||
},
|
||||
{
|
||||
"DelegatorWithdrawAddr",
|
||||
v042distribution.GetDelegatorWithdrawAddrKey(addr2),
|
||||
v1.GetDelegatorWithdrawAddrKey(addr2),
|
||||
types.GetDelegatorWithdrawAddrKey(addr2),
|
||||
},
|
||||
{
|
||||
"DelegatorStartingInfo",
|
||||
v042distribution.GetDelegatorStartingInfoKey(valAddr, addr2),
|
||||
v1.GetDelegatorStartingInfoKey(valAddr, addr2),
|
||||
types.GetDelegatorStartingInfoKey(valAddr, addr2),
|
||||
},
|
||||
{
|
||||
"ValidatorHistoricalRewards",
|
||||
v042distribution.GetValidatorHistoricalRewardsKey(valAddr, 6),
|
||||
v1.GetValidatorHistoricalRewardsKey(valAddr, 6),
|
||||
types.GetValidatorHistoricalRewardsKey(valAddr, 6),
|
||||
},
|
||||
{
|
||||
"ValidatorCurrentRewards",
|
||||
v042distribution.GetValidatorCurrentRewardsKey(valAddr),
|
||||
v1.GetValidatorCurrentRewardsKey(valAddr),
|
||||
types.GetValidatorCurrentRewardsKey(valAddr),
|
||||
},
|
||||
{
|
||||
"ValidatorAccumulatedCommission",
|
||||
v042distribution.GetValidatorAccumulatedCommissionKey(valAddr),
|
||||
v1.GetValidatorAccumulatedCommissionKey(valAddr),
|
||||
types.GetValidatorAccumulatedCommissionKey(valAddr),
|
||||
},
|
||||
{
|
||||
"ValidatorSlashEvent",
|
||||
v042distribution.GetValidatorSlashEventKey(valAddr, 6, 8),
|
||||
v1.GetValidatorSlashEventKey(valAddr, 6, 8),
|
||||
types.GetValidatorSlashEventKey(valAddr, 6, 8),
|
||||
},
|
||||
}
|
||||
@ -83,7 +83,7 @@ func TestStoreMigration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Run migrations.
|
||||
err := v043distribution.MigrateStore(ctx, distributionKey)
|
||||
err := v2.MigrateStore(ctx, distributionKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure the new keys are set and old keys are deleted.
|
||||
@ -2,7 +2,7 @@ package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v046 "github.com/cosmos/cosmos-sdk/x/feegrant/migrations/v046"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/feegrant/migrations/v2"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v2
|
||||
|
||||
import (
|
||||
"time"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -1,4 +1,4 @@
|
||||
package v046_test
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
||||
v046 "github.com/cosmos/cosmos-sdk/x/feegrant/migrations/v046"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/feegrant/migrations/v2"
|
||||
feegranttestutil "github.com/cosmos/cosmos-sdk/x/feegrant/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -19,7 +19,7 @@ func TestMigration(t *testing.T) {
|
||||
var cdc codec.Codec
|
||||
depinject.Inject(feegranttestutil.AppConfig, &cdc)
|
||||
|
||||
feegrantKey := sdk.NewKVStoreKey(v046.ModuleName)
|
||||
feegrantKey := sdk.NewKVStoreKey(v2.ModuleName)
|
||||
ctx := testutil.DefaultContext(feegrantKey, sdk.NewTransientStoreKey("transient_test"))
|
||||
granter1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||
grantee1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||
@ -72,15 +72,15 @@ func TestMigration(t *testing.T) {
|
||||
bz, err := cdc.Marshal(&newGrant)
|
||||
require.NoError(t, err)
|
||||
|
||||
store.Set(v046.FeeAllowanceKey(grant.granter, grant.grantee), bz)
|
||||
store.Set(v2.FeeAllowanceKey(grant.granter, grant.grantee), bz)
|
||||
}
|
||||
|
||||
ctx = ctx.WithBlockTime(now.Add(30 * time.Hour))
|
||||
require.NoError(t, v046.MigrateStore(ctx, feegrantKey, cdc))
|
||||
require.NoError(t, v2.MigrateStore(ctx, feegrantKey, cdc))
|
||||
store = ctx.KVStore(feegrantKey)
|
||||
|
||||
require.NotNil(t, store.Get(v046.FeeAllowanceKey(granter1, grantee1)))
|
||||
require.Nil(t, store.Get(v046.FeeAllowanceKey(granter2, grantee2)))
|
||||
require.NotNil(t, store.Get(v046.FeeAllowanceKey(granter1, grantee2)))
|
||||
require.Nil(t, store.Get(v046.FeeAllowanceKey(granter2, grantee1)))
|
||||
require.NotNil(t, store.Get(v2.FeeAllowanceKey(granter1, grantee1)))
|
||||
require.Nil(t, store.Get(v2.FeeAllowanceKey(granter2, grantee2)))
|
||||
require.NotNil(t, store.Get(v2.FeeAllowanceKey(granter1, grantee2)))
|
||||
require.Nil(t, store.Get(v2.FeeAllowanceKey(granter2, grantee1)))
|
||||
}
|
||||
@ -3,6 +3,7 @@ package module
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
@ -56,7 +57,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
err := cfg.RegisterMigration(feegrant.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("failed to migrate x/feegrant from version 1 to 2: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -154,7 +154,7 @@ func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
|
||||
}
|
||||
|
||||
func splitKeyWithAddress(key []byte) (proposalID uint64, addr sdk.AccAddress) {
|
||||
kv.AssertKeyLength(key[1:], 8+v042auth.AddrLen)
|
||||
kv.AssertKeyLength(key[1:], 8+v1auth.AddrLen)
|
||||
|
||||
kv.AssertKeyAtLeastLength(key, 10)
|
||||
proposalID = GetProposalIDFromBytes(key[1:9])
|
||||
|
||||
@ -280,15 +280,15 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
m := keeper.NewMigrator(am.keeper, am.legacySubspace)
|
||||
err := cfg.RegisterMigration(govtypes.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 1 to 2: %v", err))
|
||||
}
|
||||
err = cfg.RegisterMigration(govtypes.ModuleName, 2, m.Migrate2to3)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 2 to 3: %v", err))
|
||||
}
|
||||
err = cfg.RegisterMigration(govtypes.ModuleName, 3, m.Migrate3to4)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 3 to 4: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package keeper
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/exported"
|
||||
v043 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v043"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2"
|
||||
v3 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v3"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ func NewMigrator(keeper Keeper, ss 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/slashing module state from the consensus
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
package v043
|
||||
|
||||
import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
|
||||
v042slashing "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v042"
|
||||
)
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Change addresses to be length-prefixed.
|
||||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
v043distribution.MigratePrefixAddress(store, v042slashing.ValidatorSigningInfoKeyPrefix)
|
||||
v043distribution.MigratePrefixAddressBytes(store, v042slashing.ValidatorMissedBlockBitArrayKeyPrefix)
|
||||
v043distribution.MigratePrefixAddress(store, v042slashing.AddrPubkeyRelationKeyPrefix)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -47,7 +47,7 @@ func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
||||
func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
|
||||
kv.AssertKeyAtLeastLength(key, 2)
|
||||
addr := key[1:]
|
||||
kv.AssertKeyLength(addr, v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addr, v1auth.AddrLen)
|
||||
return sdk.ConsAddress(addr)
|
||||
}
|
||||
|
||||
21
x/slashing/migrations/v2/store.go
Normal file
21
x/slashing/migrations/v2/store.go
Normal file
@ -0,0 +1,21 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v2distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v2"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v1"
|
||||
)
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Change addresses to be length-prefixed.
|
||||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
v2distribution.MigratePrefixAddress(store, v1.ValidatorSigningInfoKeyPrefix)
|
||||
v2distribution.MigratePrefixAddressBytes(store, v1.ValidatorMissedBlockBitArrayKeyPrefix)
|
||||
v2distribution.MigratePrefixAddress(store, v1.AddrPubkeyRelationKeyPrefix)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package v043_test
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040slashing "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v042"
|
||||
v043slashing "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v043"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v1"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
)
|
||||
|
||||
@ -31,17 +31,17 @@ func TestStoreMigration(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"ValidatorSigningInfoKey",
|
||||
v040slashing.ValidatorSigningInfoKey(consAddr),
|
||||
v1.ValidatorSigningInfoKey(consAddr),
|
||||
types.ValidatorSigningInfoKey(consAddr),
|
||||
},
|
||||
{
|
||||
"ValidatorMissedBlockBitArrayKey",
|
||||
v040slashing.ValidatorMissedBlockBitArrayKey(consAddr, 2),
|
||||
v1.ValidatorMissedBlockBitArrayKey(consAddr, 2),
|
||||
types.ValidatorMissedBlockBitArrayKey(consAddr, 2),
|
||||
},
|
||||
{
|
||||
"AddrPubkeyRelationKey",
|
||||
v040slashing.AddrPubkeyRelationKey(consAddr),
|
||||
v1.AddrPubkeyRelationKey(consAddr),
|
||||
types.AddrPubkeyRelationKey(consAddr),
|
||||
},
|
||||
}
|
||||
@ -52,7 +52,7 @@ func TestStoreMigration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Run migrations.
|
||||
err := v043slashing.MigrateStore(ctx, slashingKey)
|
||||
err := v2.MigrateStore(ctx, slashingKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure the new keys are set and old keys are deleted.
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
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/staking/types"
|
||||
)
|
||||
|
||||
@ -90,7 +90,7 @@ func GetValidatorsByPowerIndexKey(validator types.Validator) []byte {
|
||||
powerBytesLen := len(powerBytes) // 8
|
||||
|
||||
// key is of format prefix || powerbytes || addrBytes
|
||||
key := make([]byte, 1+powerBytesLen+v042auth.AddrLen)
|
||||
key := make([]byte, 1+powerBytesLen+v1auth.AddrLen)
|
||||
|
||||
key[0] = ValidatorsByPowerIndexKey[0]
|
||||
copy(key[1:powerBytesLen+1], powerBytes)
|
||||
@ -117,11 +117,11 @@ func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte {
|
||||
// GetREDKey returns a key prefix for indexing a redelegation from a delegator
|
||||
// and source validator to a destination validator.
|
||||
func GetREDKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) []byte {
|
||||
key := make([]byte, 1+v042auth.AddrLen*3)
|
||||
key := make([]byte, 1+v1auth.AddrLen*3)
|
||||
|
||||
copy(key[0:v042auth.AddrLen+1], GetREDsKey(delAddr.Bytes()))
|
||||
copy(key[v042auth.AddrLen+1:2*v042auth.AddrLen+1], valSrcAddr.Bytes())
|
||||
copy(key[2*v042auth.AddrLen+1:3*v042auth.AddrLen+1], valDstAddr.Bytes())
|
||||
copy(key[0:v1auth.AddrLen+1], GetREDsKey(delAddr.Bytes()))
|
||||
copy(key[v1auth.AddrLen+1:2*v1auth.AddrLen+1], valSrcAddr.Bytes())
|
||||
copy(key[2*v1auth.AddrLen+1:3*v1auth.AddrLen+1], valDstAddr.Bytes())
|
||||
|
||||
return key
|
||||
}
|
||||
@ -133,10 +133,10 @@ func GetREDByValSrcIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
|
||||
offset := len(REDSFromValsSrcKey)
|
||||
|
||||
// key is of the form REDSFromValsSrcKey || delAddr || valDstAddr
|
||||
key := make([]byte, len(REDSFromValsSrcKey)+2*v042auth.AddrLen)
|
||||
key := make([]byte, len(REDSFromValsSrcKey)+2*v1auth.AddrLen)
|
||||
copy(key[0:offset], REDSFromValsSrcKey)
|
||||
copy(key[offset:offset+v042auth.AddrLen], delAddr.Bytes())
|
||||
copy(key[offset+v042auth.AddrLen:offset+2*v042auth.AddrLen], valDstAddr.Bytes())
|
||||
copy(key[offset:offset+v1auth.AddrLen], delAddr.Bytes())
|
||||
copy(key[offset+v1auth.AddrLen:offset+2*v1auth.AddrLen], valDstAddr.Bytes())
|
||||
|
||||
return key
|
||||
}
|
||||
@ -148,10 +148,10 @@ func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
|
||||
offset := len(REDSToValsDstKey)
|
||||
|
||||
// key is of the form REDSToValsDstKey || delAddr || valSrcAddr
|
||||
key := make([]byte, len(REDSToValsDstKey)+2*v042auth.AddrLen)
|
||||
key := make([]byte, len(REDSToValsDstKey)+2*v1auth.AddrLen)
|
||||
copy(key[0:offset], REDSToValsDstKey)
|
||||
copy(key[offset:offset+v042auth.AddrLen], delAddr.Bytes())
|
||||
copy(key[offset+v042auth.AddrLen:offset+2*v042auth.AddrLen], valSrcAddr.Bytes())
|
||||
copy(key[offset:offset+v1auth.AddrLen], delAddr.Bytes())
|
||||
copy(key[offset+v1auth.AddrLen:offset+2*v1auth.AddrLen], valSrcAddr.Bytes())
|
||||
|
||||
return key
|
||||
}
|
||||
@ -159,11 +159,11 @@ func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
|
||||
// GetREDKeyFromValSrcIndexKey rearranges the ValSrcIndexKey to get the REDKey
|
||||
func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
|
||||
// note that first byte is prefix byte
|
||||
kv.AssertKeyLength(indexKey, 3*v042auth.AddrLen+1)
|
||||
kv.AssertKeyLength(indexKey, 3*v1auth.AddrLen+1)
|
||||
|
||||
valSrcAddr := indexKey[1 : v042auth.AddrLen+1]
|
||||
delAddr := indexKey[v042auth.AddrLen+1 : 2*v042auth.AddrLen+1]
|
||||
valDstAddr := indexKey[2*v042auth.AddrLen+1 : 3*v042auth.AddrLen+1]
|
||||
valSrcAddr := indexKey[1 : v1auth.AddrLen+1]
|
||||
delAddr := indexKey[v1auth.AddrLen+1 : 2*v1auth.AddrLen+1]
|
||||
valDstAddr := indexKey[2*v1auth.AddrLen+1 : 3*v1auth.AddrLen+1]
|
||||
|
||||
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||
}
|
||||
@ -171,11 +171,11 @@ func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
|
||||
// GetREDKeyFromValDstIndexKey rearranges the ValDstIndexKey to get the REDKey
|
||||
func GetREDKeyFromValDstIndexKey(indexKey []byte) []byte {
|
||||
// note that first byte is prefix byte
|
||||
kv.AssertKeyLength(indexKey, 3*v042auth.AddrLen+1)
|
||||
kv.AssertKeyLength(indexKey, 3*v1auth.AddrLen+1)
|
||||
|
||||
valDstAddr := indexKey[1 : v042auth.AddrLen+1]
|
||||
delAddr := indexKey[v042auth.AddrLen+1 : 2*v042auth.AddrLen+1]
|
||||
valSrcAddr := indexKey[2*v042auth.AddrLen+1 : 3*v042auth.AddrLen+1]
|
||||
valDstAddr := indexKey[1 : v1auth.AddrLen+1]
|
||||
delAddr := indexKey[v1auth.AddrLen+1 : 2*v1auth.AddrLen+1]
|
||||
valSrcAddr := indexKey[2*v1auth.AddrLen+1 : 3*v1auth.AddrLen+1]
|
||||
|
||||
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||
}
|
||||
@ -259,11 +259,11 @@ func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte
|
||||
func GetUBDKeyFromValIndexKey(indexKey []byte) []byte {
|
||||
kv.AssertKeyAtLeastLength(indexKey, 2)
|
||||
addrs := indexKey[1:] // remove prefix bytes
|
||||
kv.AssertKeyLength(addrs, 2*v042auth.AddrLen)
|
||||
kv.AssertKeyLength(addrs, 2*v1auth.AddrLen)
|
||||
|
||||
kv.AssertKeyAtLeastLength(addrs, v042auth.AddrLen+1)
|
||||
valAddr := addrs[:v042auth.AddrLen]
|
||||
delAddr := addrs[v042auth.AddrLen:]
|
||||
kv.AssertKeyAtLeastLength(addrs, v1auth.AddrLen+1)
|
||||
valAddr := addrs[:v1auth.AddrLen]
|
||||
delAddr := addrs[v1auth.AddrLen:]
|
||||
|
||||
return GetUBDKey(delAddr, valAddr)
|
||||
}
|
||||
|
||||
@ -5,8 +5,8 @@ import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
|
||||
v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
|
||||
v2distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v2"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@ -22,9 +22,9 @@ func migratePrefixAddressAddressAddress(store sdk.KVStore, prefixBz []byte) {
|
||||
defer oldStoreIter.Close()
|
||||
|
||||
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
||||
addr1 := oldStoreIter.Key()[:v042auth.AddrLen]
|
||||
addr2 := oldStoreIter.Key()[v042auth.AddrLen : 2*v042auth.AddrLen]
|
||||
addr3 := oldStoreIter.Key()[2*v042auth.AddrLen:]
|
||||
addr1 := oldStoreIter.Key()[:v1auth.AddrLen]
|
||||
addr2 := oldStoreIter.Key()[v1auth.AddrLen : 2*v1auth.AddrLen]
|
||||
addr3 := oldStoreIter.Key()[2*v1auth.AddrLen:]
|
||||
newStoreKey := append(append(append(
|
||||
prefixBz,
|
||||
address.MustLengthPrefix(addr1)...), address.MustLengthPrefix(addr2)...), address.MustLengthPrefix(addr3)...,
|
||||
@ -62,15 +62,15 @@ func migrateValidatorsByPowerIndexKey(store sdk.KVStore) {
|
||||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
|
||||
v043distribution.MigratePrefixAddress(store, v1.LastValidatorPowerKey)
|
||||
v2distribution.MigratePrefixAddress(store, v1.LastValidatorPowerKey)
|
||||
|
||||
v043distribution.MigratePrefixAddress(store, v1.ValidatorsKey)
|
||||
v043distribution.MigratePrefixAddress(store, v1.ValidatorsByConsAddrKey)
|
||||
v2distribution.MigratePrefixAddress(store, v1.ValidatorsKey)
|
||||
v2distribution.MigratePrefixAddress(store, v1.ValidatorsByConsAddrKey)
|
||||
migrateValidatorsByPowerIndexKey(store)
|
||||
|
||||
v043distribution.MigratePrefixAddressAddress(store, v1.DelegationKey)
|
||||
v043distribution.MigratePrefixAddressAddress(store, v1.UnbondingDelegationKey)
|
||||
v043distribution.MigratePrefixAddressAddress(store, v1.UnbondingDelegationByValIndexKey)
|
||||
v2distribution.MigratePrefixAddressAddress(store, v1.DelegationKey)
|
||||
v2distribution.MigratePrefixAddressAddress(store, v1.UnbondingDelegationKey)
|
||||
v2distribution.MigratePrefixAddressAddress(store, v1.UnbondingDelegationByValIndexKey)
|
||||
migratePrefixAddressAddressAddress(store, v1.RedelegationKey)
|
||||
migratePrefixAddressAddressAddress(store, v1.RedelegationByValSrcIndexKey)
|
||||
migratePrefixAddressAddressAddress(store, v1.RedelegationByValDstIndexKey)
|
||||
|
||||
@ -3,6 +3,7 @@ package upgrade
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
|
||||
@ -104,7 +105,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user