From ba64397d1b7d15cf921d943d337e664922950817 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 3 Nov 2023 18:08:30 -0700 Subject: [PATCH 1/3] add postTxProcess to evm interface --- testutil/keeper/mocks/fungible/evm.go | 16 ++++++++++++++++ x/fungible/types/expected_keepers.go | 3 +++ 2 files changed, 19 insertions(+) diff --git a/testutil/keeper/mocks/fungible/evm.go b/testutil/keeper/mocks/fungible/evm.go index 0dbfc1fe14..fd19003814 100644 --- a/testutil/keeper/mocks/fungible/evm.go +++ b/testutil/keeper/mocks/fungible/evm.go @@ -10,6 +10,8 @@ import ( core "github.com/ethereum/go-ethereum/core" + coretypes "github.com/ethereum/go-ethereum/core/types" + evmtypes "github.com/evmos/ethermint/x/evm/types" mock "github.com/stretchr/testify/mock" @@ -140,6 +142,20 @@ func (_m *FungibleEVMKeeper) GetLogSizeTransient(ctx types.Context) uint64 { return r0 } +// PostTxProcessing provides a mock function with given fields: ctx, _a1, receipt +func (_m *FungibleEVMKeeper) PostTxProcessing(ctx types.Context, _a1 core.Message, receipt *coretypes.Receipt) error { + ret := _m.Called(ctx, _a1, receipt) + + var r0 error + if rf, ok := ret.Get(0).(func(types.Context, core.Message, *coretypes.Receipt) error); ok { + r0 = rf(ctx, _a1, receipt) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // SetAccount provides a mock function with given fields: ctx, addr, account func (_m *FungibleEVMKeeper) SetAccount(ctx types.Context, addr common.Address, account statedb.Account) error { ret := _m.Called(ctx, addr, account) diff --git a/x/fungible/types/expected_keepers.go b/x/fungible/types/expected_keepers.go index 46450aab09..170722360b 100644 --- a/x/fungible/types/expected_keepers.go +++ b/x/fungible/types/expected_keepers.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + ethtypes "github.com/ethereum/go-ethereum/core/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -67,4 +69,5 @@ type EVMKeeper interface { ) (*evmtypes.MsgEthereumTxResponse, error) GetAccount(ctx sdk.Context, addr ethcommon.Address) *statedb.Account SetAccount(ctx sdk.Context, addr ethcommon.Address, account statedb.Account) error + PostTxProcessing(ctx sdk.Context, _ core.Message, receipt *ethtypes.Receipt) error } From b91a86164acf8e810ecc16159c932f2005e7960e Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 3 Nov 2023 18:08:42 -0700 Subject: [PATCH 2/3] add post tx process in evm call --- x/fungible/keeper/evm.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x/fungible/keeper/evm.go b/x/fungible/keeper/evm.go index f0683deb60..8b952af0f5 100644 --- a/x/fungible/keeper/evm.go +++ b/x/fungible/keeper/evm.go @@ -649,9 +649,21 @@ func (k Keeper) CallEVMWithData( if err != nil { return nil, err } + logs := evmtypes.LogsToEthereum(res.Logs) if res.Failed() { return res, cosmoserrors.Wrap(evmtypes.ErrVMExecution, fmt.Sprintf("%s: ret 0x%x", res.VmError, res.Ret)) + } else { + // call PostTxProcessing hook + receipt := ðtypes.Receipt{ + Logs: logs, + TxHash: common.HexToHash(res.Hash), + } + if err = k.evmKeeper.PostTxProcessing(ctx, msg, receipt); err != nil { + // if post-processing return error, revert the whole tx + k.Logger(ctx).Error("tx post processing failed", "error", err) + return nil, cosmoserrors.Wrap(evmtypes.ErrPostTxProcessing, err.Error()) + } } // Emit events and log for the transaction if it is committed @@ -715,7 +727,6 @@ func (k Keeper) CallEVMWithData( }) } - logs := evmtypes.LogsToEthereum(res.Logs) var bloomReceipt ethtypes.Bloom if len(logs) > 0 { bloom := k.evmKeeper.GetBlockBloomTransient(ctx) From 20459364f7623f08aa6c4d40e98eb64d0803104e Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 8 Nov 2023 17:09:47 -0800 Subject: [PATCH 3/3] fix lint --- x/fungible/keeper/evm.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/x/fungible/keeper/evm.go b/x/fungible/keeper/evm.go index 8b952af0f5..041ef4cd9c 100644 --- a/x/fungible/keeper/evm.go +++ b/x/fungible/keeper/evm.go @@ -653,20 +653,20 @@ func (k Keeper) CallEVMWithData( if res.Failed() { return res, cosmoserrors.Wrap(evmtypes.ErrVMExecution, fmt.Sprintf("%s: ret 0x%x", res.VmError, res.Ret)) - } else { - // call PostTxProcessing hook - receipt := ðtypes.Receipt{ - Logs: logs, - TxHash: common.HexToHash(res.Hash), - } - if err = k.evmKeeper.PostTxProcessing(ctx, msg, receipt); err != nil { - // if post-processing return error, revert the whole tx - k.Logger(ctx).Error("tx post processing failed", "error", err) - return nil, cosmoserrors.Wrap(evmtypes.ErrPostTxProcessing, err.Error()) - } } - // Emit events and log for the transaction if it is committed + // call PostTxProcessing hook + receipt := ðtypes.Receipt{ + Logs: logs, + TxHash: common.HexToHash(res.Hash), + } + if err = k.evmKeeper.PostTxProcessing(ctx, msg, receipt); err != nil { + // if post-processing return error, revert the whole tx + k.Logger(ctx).Error("tx post processing failed", "error", err) + return nil, cosmoserrors.Wrap(evmtypes.ErrPostTxProcessing, err.Error()) + } + + // emit events and log for the transaction if it is committed if commit { msgBytes, err := json.Marshal(msg) if err != nil {