From a2ebdd29c0519fa44c4f6fc8f85c2d3ac52023bc Mon Sep 17 00:00:00 2001 From: dudong2 Date: Mon, 15 Jan 2024 13:54:06 +0900 Subject: [PATCH] chore: change migrate funcs --- ethereum/eip712/eip712_test.go | 10 ++++----- x/evm/keeper/migrations.go | 7 ++---- x/evm/migrations/v4/migrate.go | 32 +++++++++++++++++++++------- x/evm/migrations/v5/migrate.go | 28 +++++++++++++++++------- x/feemarket/keeper/migrations.go | 4 +--- x/feemarket/migrations/v4/migrate.go | 5 +++-- 6 files changed, 55 insertions(+), 31 deletions(-) diff --git a/ethereum/eip712/eip712_test.go b/ethereum/eip712/eip712_test.go index 1e10007b1e..95d76a42e9 100644 --- a/ethereum/eip712/eip712_test.go +++ b/ethereum/eip712/eip712_test.go @@ -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, @@ -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), diff --git a/x/evm/keeper/migrations.go b/x/evm/keeper/migrations.go index 733ba95216..bdb18ffd2a 100644 --- a/x/evm/keeper/migrations.go +++ b/x/evm/keeper/migrations.go @@ -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" @@ -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) } diff --git a/x/evm/migrations/v4/migrate.go b/x/evm/migrations/v4/migrate.go index e1e9b6aeaf..79b8bad507 100644 --- a/x/evm/migrations/v4/migrate.go +++ b/x/evm/migrations/v4/migrate.go @@ -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" @@ -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 { @@ -29,20 +29,36 @@ func MigrateStore( chainCfgBz := cdc.MustMarshal(¶ms.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 diff --git a/x/evm/migrations/v5/migrate.go b/x/evm/migrations/v5/migrate.go index b42190060c..db353a5630 100644 --- a/x/evm/migrations/v5/migrate.go +++ b/x/evm/migrations/v5/migrate.go @@ -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" @@ -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 ( @@ -24,9 +24,18 @@ 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 @@ -34,15 +43,18 @@ func MigrateStore( 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) diff --git a/x/feemarket/keeper/migrations.go b/x/feemarket/keeper/migrations.go index 41e91cd7bd..1e932d2d77 100644 --- a/x/feemarket/keeper/migrations.go +++ b/x/feemarket/keeper/migrations.go @@ -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" @@ -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) } diff --git a/x/feemarket/migrations/v4/migrate.go b/x/feemarket/migrations/v4/migrate.go index 0a4051cd04..dc93d9824d 100644 --- a/x/feemarket/migrations/v4/migrate.go +++ b/x/feemarket/migrations/v4/migrate.go @@ -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" @@ -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 { @@ -29,6 +29,7 @@ func MigrateStore( return err } + store := storeService.OpenKVStore(ctx) store.Set(types.ParamsKey, bz) return nil