Skip to content

Commit f50837e

Browse files
author
Wojciech Małota-Wójcik
authored
Return evm logs from cosmos interface (#1825)
1 parent 7aeb9d1 commit f50837e

File tree

6 files changed

+170
-74
lines changed

6 files changed

+170
-74
lines changed

proto/evm/tx.proto

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "google/protobuf/any.proto";
55
import "gogoproto/gogo.proto";
66
import "cosmos/base/v1beta1/coin.proto";
77
import "evm/enums.proto";
8+
import "evm/receipt.proto";
89

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

@@ -26,6 +27,7 @@ message MsgEVMTransactionResponse {
2627
string vm_error = 2;
2728
bytes return_data = 3;
2829
string hash = 4;
30+
repeated Log logs = 5;
2931
}
3032

3133
message MsgInternalEVMCall {
@@ -80,4 +82,4 @@ message MsgAssociate {
8082
string custom_message = 2;
8183
}
8284

83-
message MsgAssociateResponse {}
85+
message MsgAssociateResponse {}

x/evm/keeper/evm.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
ethtypes "github.com/ethereum/go-ethereum/core/types"
1414
"github.com/ethereum/go-ethereum/core/vm"
1515
"github.com/ethereum/go-ethereum/params"
16+
1617
"github.com/sei-protocol/sei-chain/utils"
1718
"github.com/sei-protocol/sei-chain/utils/metrics"
1819
"github.com/sei-protocol/sei-chain/x/evm/state"

x/evm/keeper/msg_server.go

+19-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/ethereum/go-ethereum/core"
2222
ethtypes "github.com/ethereum/go-ethereum/core/types"
2323
"github.com/ethereum/go-ethereum/core/vm"
24+
2425
"github.com/sei-protocol/sei-chain/precompiles/wasmd"
2526
"github.com/sei-protocol/sei-chain/utils"
2627
"github.com/sei-protocol/sei-chain/x/evm/artifacts/erc20"
@@ -176,23 +177,26 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
176177
},
177178
)
178179

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

184-
telemetry.IncrCounterWithLabels(
185-
[]string{types.ModuleName, "errors", "vm_execution"},
186-
1,
187-
[]metrics.Label{
188-
telemetry.NewLabel("type", serverRes.VmError),
189-
},
190-
)
191-
}
192-
serverRes.GasUsed = res.UsedGas
193-
serverRes.ReturnData = res.ReturnData
183+
// if applyErr is nil then res must be non-nil
184+
if res.Err != nil {
185+
serverRes.VmError = res.Err.Error()
186+
187+
telemetry.IncrCounterWithLabels(
188+
[]string{types.ModuleName, "errors", "vm_execution"},
189+
1,
190+
[]metrics.Label{
191+
telemetry.NewLabel("type", serverRes.VmError),
192+
},
193+
)
194194
}
195195

196+
serverRes.GasUsed = res.UsedGas
197+
serverRes.ReturnData = res.ReturnData
198+
serverRes.Logs = types.NewLogsFromEth(stateDB.GetAllLogs())
199+
196200
return
197201
}
198202

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

240243
func (server msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) {

x/evm/keeper/msg_server_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"github.com/ethereum/go-ethereum/common"
1717
ethtypes "github.com/ethereum/go-ethereum/core/types"
1818
"github.com/ethereum/go-ethereum/crypto"
19+
"github.com/stretchr/testify/require"
20+
abci "github.com/tendermint/tendermint/abci/types"
21+
1922
"github.com/sei-protocol/sei-chain/example/contracts/echo"
2023
"github.com/sei-protocol/sei-chain/example/contracts/sendall"
2124
"github.com/sei-protocol/sei-chain/example/contracts/simplestorage"
@@ -27,8 +30,6 @@ import (
2730
"github.com/sei-protocol/sei-chain/x/evm/state"
2831
"github.com/sei-protocol/sei-chain/x/evm/types"
2932
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
30-
"github.com/stretchr/testify/require"
31-
abci "github.com/tendermint/tendermint/abci/types"
3233
)
3334

3435
type mockTx struct {
@@ -125,6 +126,7 @@ func TestEVMTransaction(t *testing.T) {
125126
require.Nil(t, err)
126127
res, err = msgServer.EVMTransaction(sdk.WrapSDKContext(ctx), req)
127128
require.Nil(t, err)
129+
require.NotEmpty(t, res.Logs)
128130
require.LessOrEqual(t, res.GasUsed, uint64(200000))
129131
require.Empty(t, res.VmError)
130132
require.NoError(t, k.FlushTransientReceipts(ctx))

x/evm/types/logs.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package types
2+
3+
import ethtypes "github.com/ethereum/go-ethereum/core/types"
4+
5+
func NewLogsFromEth(ethlogs []*ethtypes.Log) []*Log {
6+
logs := make([]*Log, 0, len(ethlogs))
7+
for _, ethlog := range ethlogs {
8+
logs = append(logs, newLogFromEth(ethlog))
9+
}
10+
return logs
11+
}
12+
13+
func newLogFromEth(log *ethtypes.Log) *Log {
14+
topics := make([]string, len(log.Topics))
15+
for i, topic := range log.Topics {
16+
topics[i] = topic.String()
17+
}
18+
19+
return &Log{
20+
Address: log.Address.String(),
21+
Topics: topics,
22+
Data: log.Data,
23+
Index: uint32(log.Index),
24+
}
25+
}

x/evm/types/tx.pb.go

+118-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)