Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
fix: avoid duplicate register proto type in evm & feemarket (#1586)
Browse files Browse the repository at this point in the history
* update dep

* make proto-all

* avoid duplicate register proto type in evm

* set KeyTable

* update from version to v.19.x which support submit-proposal

* test AvailableExtraEIPs

* keep grpc query compatible with version before migrate

* fix duplicate register & migrate in feemarket

* update nix

* support typed event for bloom & txLog

* partial revert typed ethereumTx

* Revert "partial revert typed ethereumTx"

This reverts commit 314bb28.

* Revert "support typed event for bloom & txLog"

This reverts commit 287d3ae.

Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com>
  • Loading branch information
3 people authored Jan 12, 2023
1 parent 06ca052 commit 5f7ee9b
Show file tree
Hide file tree
Showing 21 changed files with 2,070 additions and 273 deletions.
14 changes: 8 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,18 @@ func NewEthermintApp(
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))

// Create Ethermint keepers
feeMarketSs := app.GetSubspace(feemarkettypes.ModuleName)
app.FeeMarketKeeper = feemarketkeeper.NewKeeper(
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey],
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], feeMarketSs,
)

// Set authority to x/gov module account to only expect the module account to update params
evmSs := app.GetSubspace(evmtypes.ModuleName)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
nil, geth.NewEVM, tracer,
nil, geth.NewEVM, tracer, evmSs,
)

// Create IBC Keeper
Expand Down Expand Up @@ -507,8 +509,8 @@ func NewEthermintApp(
ibc.NewAppModule(app.IBCKeeper),
transferModule,
// Ethermint app modules
feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)),
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
feemarket.NewAppModule(app.FeeMarketKeeper, feeMarketSs),
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -861,7 +863,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
// ethermint subspaces
paramsKeeper.Subspace(evmtypes.ModuleName)
paramsKeeper.Subspace(feemarkettypes.ModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())
return paramsKeeper
}
14 changes: 7 additions & 7 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ schema = 3
hash = "sha256-EmpRZ48pjPFq/fIHneut9Vyo5QJATfb3ZO7KzWnqs9g="
[mod."github.com/cosmos/ibc-go/v6"]
version = "v6.1.0"
hash = "sha256-Gfqhdz9ZKEgb7LCkHiXCwYZYUYluQ+vMew/GkssfVj8="
hash = "sha256-mHYCqLedcveDjfm1EiO2EMMNJqLm9u4WHwQTy1muOoc="
[mod."github.com/cosmos/ledger-cosmos-go"]
version = "v0.12.1"
hash = "sha256-9+nr+/r4MyiogddS0JcXOuriPqXP4nxln8ts+mYQRcg="
Expand Down Expand Up @@ -406,8 +406,8 @@ schema = 3
version = "v0.9.1"
hash = "sha256-YLGNrHHM+mN4ElW/XWuylOnFrA/VjSY+eBuC4LN//5c="
[mod."github.com/rs/cors"]
version = "v1.8.2"
hash = "sha256-FxBbQVb8zIoDGGaAJKfsYV0+POkh1tyX7P6A/Lk5Vsc="
version = "v1.8.3"
hash = "sha256-VgVB4HKAhPSjNg96mIEUN1bt5ZQng8Fi3ZABy3CDWQE="
[mod."github.com/rs/zerolog"]
version = "v1.27.0"
hash = "sha256-BxQtP2TROeSSpj9l1irocuSfxn55UL4ugzB/og7r8eE="
Expand Down Expand Up @@ -523,11 +523,11 @@ schema = 3
version = "v1.6.7"
hash = "sha256-zIxGRHiq4QBvRqkrhMGMGCaVL4iM4TtlYpAi/hrivS4="
[mod."google.golang.org/genproto"]
version = "v0.0.0-20221116193143-41c2ba794472"
hash = "sha256-uQuxuOvWRsdMii5M5QresisVd1E+Ss8s2WfR2n7QSXk="
version = "v0.0.0-20221118155620-16455021b5e6"
hash = "sha256-FFSliEzgr7AceO8B+ZoPAlZDFVPLeqAFg+25VQw6cFs="
[mod."google.golang.org/grpc"]
version = "v1.51.0"
hash = "sha256-RzH5DU13D/ulxxOouIKpdNt8eHdff7mrEnB+JUupbLU="
version = "v1.52.0"
hash = "sha256-wYJ/ysugKxz1O9u6BxECTIGFJ3sv0XmxOfM+Y0jW3KQ="
[mod."google.golang.org/protobuf"]
version = "v1.28.2-0.20220831092852-f930b1dc76e8"
hash = "sha256-li5hXlXwTJ5LIZ8bVki1AZ6UFI2gXHl33JwdX1dOrtM="
Expand Down
5 changes: 2 additions & 3 deletions tests/integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ let
fetchEthermint = rev: builtins.fetchTarball "https://github.com/evmos/ethermint/archive/${rev}.tar.gz";
released = pkgs.buildGo118Module rec {
name = "ethermintd";
# the commit before https://github.com/evmos/ethermint/pull/943
src = fetchEthermint "8866ae0ffd67a104e9d1cf4e50fba8391dda6c45";
src = fetchEthermint "d29cdad6e667f6089dfecbedd36bb8d3a2a7d025";
subPackages = [ "cmd/ethermintd" ];
vendorSha256 = "sha256-oDtMamNlwe/393fZd+RNtRy6ipWpusbco8Xg1ZuKWYw=";
vendorSha256 = "sha256-cQAol54b6hNzsA4Q3MP9mTqFWM1MvR5uMPrYpaoj3SY=";
doCheck = false;
};
current = pkgs.callPackage ../../../. { };
Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,8 @@ def edit_validator(
)

def gov_propose(self, proposer, kind, proposal, **kwargs):
method = "submit-legacy-proposal"
method = "submit-proposal"
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("gas", DEFAULT_GAS)
if kind == "software-upgrade":
return json.loads(
self.raw(
Expand All @@ -649,7 +648,6 @@ def gov_propose(self, proposer, kind, proposal, **kwargs):
kind,
proposal["name"],
"-y",
"--no-validate",
from_=proposer,
# content
title=proposal.get("title"),
Expand Down
5 changes: 5 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -75,6 +76,8 @@ type Keeper struct {

// evm constructor function
evmConstructor evm.Constructor
// Legacy subspace
ss paramstypes.Subspace
}

// NewKeeper generates new evm module keeper
Expand All @@ -89,6 +92,7 @@ func NewKeeper(
customPrecompiles evm.PrecompiledContracts,
evmConstructor evm.Constructor,
tracer string,
ss paramstypes.Subspace,
) *Keeper {
// ensure evm module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -113,6 +117,7 @@ func NewKeeper(
customPrecompiles: customPrecompiles,
evmConstructor: evmConstructor,
tracer: tracer,
ss: ss,
}
}

Expand Down
9 changes: 4 additions & 5 deletions x/evm/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package keeper_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
v4types "github.com/evmos/ethermint/x/evm/migrations/v4/types"
"github.com/evmos/ethermint/x/evm/types"
)

type mockSubspace struct {
ps v4types.V4Params
ps types.Params
}

func newMockSubspace(ps v4types.V4Params) mockSubspace {
func newMockSubspace(ps types.Params) mockSubspace {
return mockSubspace{ps: ps}
}

func (ms mockSubspace) GetParamSetIfExists(_ sdk.Context, ps types.LegacyParams) {
*ps.(*v4types.V4Params) = ms.ps
*ps.(*types.Params) = ms.ps
}

func (suite *KeeperTestSuite) TestMigrations() {
legacySubspace := newMockSubspace(v4types.DefaultParams())
legacySubspace := newMockSubspace(types.DefaultParams())
migrator := evmkeeper.NewMigrator(*suite.app.EvmKeeper, legacySubspace)

testCases := []struct {
Expand Down
31 changes: 25 additions & 6 deletions x/evm/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
return nil
}

// GetLegacyParams returns param set for version before migrate
func (k Keeper) GetLegacyParams(ctx sdk.Context) types.Params {
var params types.Params
k.ss.GetParamSetIfExists(ctx, &params)
return params
}

// GetExtraEIPs returns the extra EIPs enabled on the chain.
func (k Keeper) GetExtraEIPs(ctx sdk.Context) types.ExtraEIPs {
var extraEIPs types.ExtraEIPs
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyExtraEIPs)
if len(bz) == 0 {
return extraEIPs
return k.GetLegacyParams(ctx).ExtraEIPs
}
k.cdc.MustUnmarshal(bz, &extraEIPs)
return extraEIPs
Expand All @@ -66,7 +73,7 @@ func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyChainConfig)
if len(bz) == 0 {
return chainCfg
return k.GetLegacyParams(ctx).ChainConfig
}
k.cdc.MustUnmarshal(bz, &chainCfg)
return chainCfg
Expand All @@ -77,27 +84,39 @@ func (k Keeper) GetEVMDenom(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyEVMDenom)
if len(bz) == 0 {
return ""
return k.GetLegacyParams(ctx).EvmDenom
}
return string(bz)
}

// GetEnableCall returns true if the EVM Call operation is enabled.
func (k Keeper) GetEnableCall(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.ParamStoreKeyEnableCall)
exist := store.Has(types.ParamStoreKeyEnableCall)
if !exist {
exist = k.GetLegacyParams(ctx).EnableCall
}
return exist
}

// GetEnableCreate returns true if the EVM Create contract operation is enabled.
func (k Keeper) GetEnableCreate(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.ParamStoreKeyEnableCreate)
exist := store.Has(types.ParamStoreKeyEnableCreate)
if !exist {
exist = k.GetLegacyParams(ctx).EnableCreate
}
return exist
}

// GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain.
func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
exist := store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
if !exist {
exist = k.GetLegacyParams(ctx).AllowUnprotectedTxs
}
return exist
}

// setChainConfig sets the ChainConfig in the store
Expand Down
17 changes: 8 additions & 9 deletions x/evm/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
v4types "github.com/evmos/ethermint/x/evm/migrations/v4/types"
"github.com/evmos/ethermint/x/evm/types"
)

Expand All @@ -19,7 +18,7 @@ func MigrateStore(
) error {
var (
store = ctx.KVStore(storeKey)
params v4types.V4Params
params types.Params
)

legacySubspace.GetParamSetIfExists(ctx, &params)
Expand All @@ -29,22 +28,22 @@ func MigrateStore(
}

chainCfgBz := cdc.MustMarshal(&params.ChainConfig)
extraEIPsBz := cdc.MustMarshal(&v4types.ExtraEIPs{EIPs: v4types.AvailableExtraEIPs})
extraEIPsBz := cdc.MustMarshal(&types.ExtraEIPs{EIPs: types.AvailableExtraEIPs})

store.Set(v4types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom))
store.Set(v4types.ParamStoreKeyExtraEIPs, extraEIPsBz)
store.Set(v4types.ParamStoreKeyChainConfig, chainCfgBz)
store.Set(types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom))
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)

if params.AllowUnprotectedTxs {
store.Set(v4types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
}

if params.EnableCall {
store.Set(v4types.ParamStoreKeyEnableCall, []byte{0x01})
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
}

if params.EnableCreate {
store.Set(v4types.ParamStoreKeyEnableCreate, []byte{0x01})
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
}

return nil
Expand Down
28 changes: 14 additions & 14 deletions x/evm/migrations/v4/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ import (
"github.com/evmos/ethermint/app"
"github.com/evmos/ethermint/encoding"
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
v4types "github.com/evmos/ethermint/x/evm/migrations/v4/types"
"github.com/stretchr/testify/require"
)

type mockSubspace struct {
ps v4types.V4Params
ps types.Params
}

func newMockSubspace(ps v4types.V4Params) mockSubspace {
func newMockSubspace(ps types.Params) mockSubspace {
return mockSubspace{ps: ps}
}

func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) {
*ps.(*v4types.V4Params) = ms.ps
*ps.(*types.Params) = ms.ps
}

func TestMigrate(t *testing.T) {
Expand All @@ -36,29 +35,30 @@ func TestMigrate(t *testing.T) {
ctx := testutil.DefaultContext(storeKey, tKey)
kvStore := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(v4types.DefaultParams())
legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))

// Get all the new parameters from the kvStore
var evmDenom string
bz := kvStore.Get(v4types.ParamStoreKeyEVMDenom)
bz := kvStore.Get(types.ParamStoreKeyEVMDenom)
evmDenom = string(bz)

var allowUnprotectedTx gogotypes.BoolValue
bz = kvStore.Get(v4types.ParamStoreKeyAllowUnprotectedTxs)
bz = kvStore.Get(types.ParamStoreKeyAllowUnprotectedTxs)
cdc.MustUnmarshal(bz, &allowUnprotectedTx)

enableCreate := kvStore.Has(v4types.ParamStoreKeyEnableCreate)
enableCall := kvStore.Has(v4types.ParamStoreKeyEnableCall)
enableCreate := kvStore.Has(types.ParamStoreKeyEnableCreate)
enableCall := kvStore.Has(types.ParamStoreKeyEnableCall)

var chainCfg v4types.ChainConfig
bz = kvStore.Get(v4types.ParamStoreKeyChainConfig)
var chainCfg types.ChainConfig
bz = kvStore.Get(types.ParamStoreKeyChainConfig)
cdc.MustUnmarshal(bz, &chainCfg)

var extraEIPs v4types.ExtraEIPs
bz = kvStore.Get(v4types.ParamStoreKeyExtraEIPs)
var extraEIPs types.ExtraEIPs
bz = kvStore.Get(types.ParamStoreKeyExtraEIPs)
cdc.MustUnmarshal(bz, &extraEIPs)
require.Equal(t, types.AvailableExtraEIPs, extraEIPs.EIPs)

params := v4types.NewParams(evmDenom, allowUnprotectedTx.Value, enableCreate, enableCall, chainCfg, extraEIPs)
params := types.NewParams(evmDenom, allowUnprotectedTx.Value, enableCreate, enableCall, chainCfg, extraEIPs)
require.Equal(t, legacySubspace.ps, params)
}
Loading

0 comments on commit 5f7ee9b

Please sign in to comment.