Skip to content

Commit

Permalink
chore: change migrate funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jan 15, 2024
1 parent 5bbc773 commit a2ebdd2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
10 changes: 5 additions & 5 deletions ethereum/eip712/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,6 @@ func (suite *EIP712TestSuite) TestEIP712() {
anyPk, err := codectypes.NewAnyWithValue(pubKey)
suite.Require().NoError(err)

builtTx := txBuilder.GetTx()
adaptableTx, ok := builtTx.(authsigning.V2AdaptableTx)
suite.Require().True(ok)
txData := adaptableTx.GetSigningTxData()

signerData := txsigning.SignerData{
ChainID: chainID,
AccountNumber: params.accountNumber,
Expand All @@ -358,6 +353,11 @@ func (suite *EIP712TestSuite) TestEIP712() {
Address: sdk.MustBech32ifyAddressBytes(config.Bech32Prefix, pubKey.Bytes()),
}

builtTx := txBuilder.GetTx()
adaptableTx, ok := builtTx.(authsigning.V2AdaptableTx)
suite.Require().True(ok)
txData := adaptableTx.GetSigningTxData()

bz, err := suite.clientCtx.TxConfig.SignModeHandler().GetSignBytes(
context.Background(),
signingv1beta1.SignMode(signMode),
Expand Down
7 changes: 2 additions & 5 deletions x/evm/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
v5 "github.com/evmos/ethermint/x/evm/migrations/v5"
Expand All @@ -39,12 +38,10 @@ func NewMigrator(keeper Keeper, legacySubspace types.Subspace) Migrator {

// Migrate3to4 migrates the store from consensus version 3 to 4
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
return v4.MigrateStore(ctx, store, m.legacySubspace, m.keeper.cdc)
return v4.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
}

// Migrate4to5 migrates the store from consensus version 4 to 5
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
return v5.MigrateStore(ctx, store, m.keeper.cdc)
return v5.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
}
32 changes: 24 additions & 8 deletions x/evm/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v4

import (
storetypes "cosmossdk.io/store/types"
corestore "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -14,7 +14,7 @@ import (
// and managed by the Cosmos SDK params module and stores them directly into the x/evm module state.
func MigrateStore(
ctx sdk.Context,
store storetypes.KVStore,
storeService corestore.KVStoreService,
legacySubspace types.Subspace,
cdc codec.BinaryCodec,
) error {
Expand All @@ -29,20 +29,36 @@ func MigrateStore(
chainCfgBz := cdc.MustMarshal(&params.ChainConfig)
extraEIPsBz := cdc.MustMarshal(&v4types.ExtraEIPs{EIPs: params.ExtraEIPs})

store.Set(types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom))
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)
store := storeService.OpenKVStore(ctx)

if err := store.Set(types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom)); err != nil {
return err
}

if err := store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz); err != nil {
return err
}

if err := store.Set(types.ParamStoreKeyChainConfig, chainCfgBz); err != nil {
return err
}

if params.AllowUnprotectedTxs {
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
if err := store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01}); err != nil {
return err
}
}

if params.EnableCall {
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
if err := store.Set(types.ParamStoreKeyEnableCall, []byte{0x01}); err != nil {
return err
}
}

if params.EnableCreate {
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
if err := store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01}); err != nil {
return err
}
}

return nil
Expand Down
28 changes: 20 additions & 8 deletions x/evm/migrations/v5/migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v5

import (
storetypes "cosmossdk.io/store/types"
corestore "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/evmos/ethermint/x/evm/types"
Expand All @@ -15,7 +15,7 @@ import (
// a single params key.
func MigrateStore(
ctx sdk.Context,
store storetypes.KVStore,
storeService corestore.KVStoreService,
cdc codec.BinaryCodec,
) error {
var (
Expand All @@ -24,25 +24,37 @@ func MigrateStore(
params types.Params
)

denom := string(store.Get(types.ParamStoreKeyEVMDenom))
store := storeService.OpenKVStore(ctx)

extraEIPsBz := store.Get(types.ParamStoreKeyExtraEIPs)
value, err := store.Get(types.ParamStoreKeyEVMDenom)
if err != nil {
return err
}
denom := string(value)

extraEIPsBz, err := store.Get(types.ParamStoreKeyExtraEIPs)
if err != nil {
return err
}
cdc.MustUnmarshal(extraEIPsBz, &extraEIPs)

// revert ExtraEIP change for Evmos testnet
if ctx.ChainID() == "evmos_9000-4" {
extraEIPs.EIPs = []int64{}
}

chainCfgBz := store.Get(types.ParamStoreKeyChainConfig)
chainCfgBz, err := store.Get(types.ParamStoreKeyChainConfig)
if err != nil {
return err
}
cdc.MustUnmarshal(chainCfgBz, &chainConfig)

params.EvmDenom = denom
params.ExtraEIPs = extraEIPs.EIPs
params.ChainConfig = chainConfig
params.EnableCreate = store.Has(types.ParamStoreKeyEnableCreate)
params.EnableCall = store.Has(types.ParamStoreKeyEnableCall)
params.AllowUnprotectedTxs = store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
params.EnableCreate, _ = store.Has(types.ParamStoreKeyEnableCreate)
params.EnableCall, _ = store.Has(types.ParamStoreKeyEnableCall)
params.AllowUnprotectedTxs, _ = store.Has(types.ParamStoreKeyAllowUnprotectedTxs)

store.Delete(types.ParamStoreKeyChainConfig)
store.Delete(types.ParamStoreKeyExtraEIPs)
Expand Down
4 changes: 1 addition & 3 deletions x/feemarket/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
v4 "github.com/evmos/ethermint/x/feemarket/migrations/v4"
"github.com/evmos/ethermint/x/feemarket/types"
Expand All @@ -38,6 +37,5 @@ func NewMigrator(keeper Keeper, legacySubspace types.Subspace) Migrator {

// Migrate3to4 migrates the store from consensus version 3 to 4
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
return v4.MigrateStore(ctx, store, m.legacySubspace, m.keeper.cdc)
return v4.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
}
5 changes: 3 additions & 2 deletions x/feemarket/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v4

import (
storetypes "cosmossdk.io/store/types"
corestore "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/evmos/ethermint/x/feemarket/types"
Expand All @@ -12,7 +12,7 @@ import (
// and managed by the Cosmos SDK params module and stores them directly into the x/evm module state.
func MigrateStore(
ctx sdk.Context,
store storetypes.KVStore,
storeService corestore.KVStoreService,
legacySubspace types.Subspace,
cdc codec.BinaryCodec,
) error {
Expand All @@ -29,6 +29,7 @@ func MigrateStore(
return err
}

store := storeService.OpenKVStore(ctx)
store.Set(types.ParamsKey, bz)

return nil
Expand Down

0 comments on commit a2ebdd2

Please sign in to comment.