Skip to content

Commit

Permalink
Return evm logs from cosmos interface (#1825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Małota-Wójcik authored Aug 30, 2024
1 parent 7aeb9d1 commit f50837e
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 74 deletions.
4 changes: 3 additions & 1 deletion proto/evm/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "evm/enums.proto";
import "evm/receipt.proto";

option go_package = "github.com/sei-protocol/sei-chain/x/evm/types";

Expand All @@ -26,6 +27,7 @@ message MsgEVMTransactionResponse {
string vm_error = 2;
bytes return_data = 3;
string hash = 4;
repeated Log logs = 5;
}

message MsgInternalEVMCall {
Expand Down Expand Up @@ -80,4 +82,4 @@ message MsgAssociate {
string custom_message = 2;
}

message MsgAssociateResponse {}
message MsgAssociateResponse {}
1 change: 1 addition & 0 deletions x/evm/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"

"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/metrics"
"github.com/sei-protocol/sei-chain/x/evm/state"
Expand Down
35 changes: 19 additions & 16 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"

"github.com/sei-protocol/sei-chain/precompiles/wasmd"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/erc20"
Expand Down Expand Up @@ -176,23 +177,26 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
},
)

} else {
// if applyErr is nil then res must be non-nil
if res.Err != nil {
serverRes.VmError = res.Err.Error()
return
}

telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "errors", "vm_execution"},
1,
[]metrics.Label{
telemetry.NewLabel("type", serverRes.VmError),
},
)
}
serverRes.GasUsed = res.UsedGas
serverRes.ReturnData = res.ReturnData
// if applyErr is nil then res must be non-nil
if res.Err != nil {
serverRes.VmError = res.Err.Error()

telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "errors", "vm_execution"},
1,
[]metrics.Label{
telemetry.NewLabel("type", serverRes.VmError),
},
)
}

serverRes.GasUsed = res.UsedGas
serverRes.ReturnData = res.ReturnData
serverRes.Logs = types.NewLogsFromEth(stateDB.GetAllLogs())

return
}

Expand Down Expand Up @@ -233,8 +237,7 @@ func (k Keeper) applyEVMMessage(ctx sdk.Context, msg *core.Message, stateDB *sta
txCtx := core.NewEVMTxContext(msg)
evmInstance := vm.NewEVM(*blockCtx, txCtx, stateDB, cfg, vm.Config{})
st := core.NewStateTransition(evmInstance, msg, &gp, true) // fee already charged in ante handler
res, err := st.TransitionDb()
return res, err
return st.TransitionDb()
}

func (server msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) {
Expand Down
6 changes: 4 additions & 2 deletions x/evm/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/sei-protocol/sei-chain/example/contracts/echo"
"github.com/sei-protocol/sei-chain/example/contracts/sendall"
"github.com/sei-protocol/sei-chain/example/contracts/simplestorage"
Expand All @@ -27,8 +30,6 @@ import (
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)

type mockTx struct {
Expand Down Expand Up @@ -125,6 +126,7 @@ func TestEVMTransaction(t *testing.T) {
require.Nil(t, err)
res, err = msgServer.EVMTransaction(sdk.WrapSDKContext(ctx), req)
require.Nil(t, err)
require.NotEmpty(t, res.Logs)
require.LessOrEqual(t, res.GasUsed, uint64(200000))
require.Empty(t, res.VmError)
require.NoError(t, k.FlushTransientReceipts(ctx))
Expand Down
25 changes: 25 additions & 0 deletions x/evm/types/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

import ethtypes "github.com/ethereum/go-ethereum/core/types"

func NewLogsFromEth(ethlogs []*ethtypes.Log) []*Log {
logs := make([]*Log, 0, len(ethlogs))
for _, ethlog := range ethlogs {
logs = append(logs, newLogFromEth(ethlog))
}
return logs
}

func newLogFromEth(log *ethtypes.Log) *Log {
topics := make([]string, len(log.Topics))
for i, topic := range log.Topics {
topics[i] = topic.String()
}

return &Log{
Address: log.Address.String(),
Topics: topics,
Data: log.Data,
Index: uint32(log.Index),
}
}
173 changes: 118 additions & 55 deletions x/evm/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f50837e

Please sign in to comment.