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

chore(evm, feemarket) - Migrate Event emitting to TypedEvent #1544

Merged
merged 23 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9b9ac23
(refactor): Migrated to new Typed Events
Vvaradinov Dec 8, 2022
c58284a
(fix): fixed tests and initialized the logs array in the proto message
Vvaradinov Dec 8, 2022
0e605f7
Added CHANGELOG entry
Vvaradinov Dec 8, 2022
0a3b9e1
(refactor): Made migration to Typedevent to feemarket module
Vvaradinov Dec 8, 2022
360281c
(fix): replace error returning with error logging.
Vvaradinov Dec 12, 2022
91c6237
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Dec 12, 2022
dd88d7e
fix: linter and formatter
Vvaradinov Dec 12, 2022
45e4bbf
fix: handle error by logging it
Vvaradinov Dec 21, 2022
da2986e
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Dec 21, 2022
404d131
fix: ran formatter and linter
Vvaradinov Dec 21, 2022
84b41cb
Merge branch 'Vvaradinov/evm-migrate-typed-events' of https://github.…
Vvaradinov Dec 21, 2022
f33bf9d
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Dec 22, 2022
ee4fd42
Apply suggestions from code review
Vvaradinov Jan 3, 2023
507daca
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Jan 3, 2023
dc10ccc
fix: increase sleep time to 5s initially
Vvaradinov Jan 3, 2023
61cedbc
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Jan 3, 2023
7e3ba13
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Jan 4, 2023
33ccf17
fix: comment out failing tests to investigate in a separate PR
Vvaradinov Jan 4, 2023
dc9196a
fix: update timeout to 10 minutes
Vvaradinov Jan 4, 2023
8e52c0c
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Jan 4, 2023
a4c03fa
fix: added 15 min timeout
Vvaradinov Jan 4, 2023
1c0cda1
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
Vvaradinov Jan 4, 2023
9ce6547
Merge branch 'main' into Vvaradinov/evm-migrate-typed-events
fedekunze Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (evm) [#1544](https://github.com/evmos/ethermint/pull/1544) Migrate deprecated event emitting to new TypedEvent
* (tests) [#1507](https://github.com/evmos/ethermint/pull/1507) Remove legacy sim tests
* (feemarket) [#1508](https://github.com/evmos/ethermint/pull/1508) Remove old x/params migration logic
* (evm) [#1499](https://github.com/evmos/ethermint/pull/1499) Add Shanghai and Cancun block
Expand Down
44 changes: 44 additions & 0 deletions proto/ethermint/evm/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
syntax = "proto3";
package ethermint.evm.v1;

option go_package = "github.com/evmos/ethermint/x/evm/types";

// EventEthereumTx defines the event for a Ethereum transaction
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message EventEthereumTx {
// amount
string amount = 1;
// eth_hash Ethereum hash of the transaction
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string eth_hash = 2;
// index of the transaction in the block
string index = 3;
// gas_used is the amount of gas used by the transaction
string gas_used = 4;
// hash Tendermint hash of the transaction
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string hash = 5;
// recipient of the transaction
string recipient = 6;
// eth_tx_failed the VM error
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string eth_tx_failed = 7;
}

// EventTxLog defines the event for a Ethereum transaction log
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message EventTxLog {
// tx_logs is the log of the transaction
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
repeated string tx_logs = 1;
}

// EventMessage
message EventMessage {
// module is the module of the message
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string module = 1;
// sender is the sender of the message
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string sender = 2;
// tx_type is the type of the message
string tx_type = 3;
}

// EventBlockBloom defines the event for a Ethereum block bloom filter
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message EventBlockBloom {
// bloom is the bloom filter of the block
string bloom = 1;
}
18 changes: 18 additions & 0 deletions proto/ethermint/feemarket/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package ethermint.feemarket.v1;

option go_package = "github.com/evmos/ethermint/x/feemarket/types";

// EventFeeMarket is the event type for the fee market module
message EventFeeMarket {
// base_fee for EIP-1559 blocks
string base_fee = 1;
}

// EventBlockGas defines the event for a Ethereum block gas
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message EventBlockGas {
// height is the height of the block
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
string height = 1;
// amount of gas wanted by the block
string amount = 2;
}
3 changes: 2 additions & 1 deletion x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package evm_test

import (
"errors"
"github.com/evmos/ethermint/x/evm/keeper"
"math/big"
"testing"
"time"

"github.com/evmos/ethermint/x/evm/keeper"

sdkmath "cosmossdk.io/math"
"github.com/gogo/protobuf/proto"

Expand Down
3 changes: 1 addition & 2 deletions x/evm/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/tendermint/tendermint/abci/types"
)

Expand All @@ -14,5 +13,5 @@ func (suite *KeeperTestSuite) TestEndBlock() {

// should emit 1 EventTypeBlockBloom event on EndBlock
suite.Require().Equal(1, len(em.Events()))
suite.Require().Equal(evmtypes.EventTypeBlockBloom, em.Events()[0].Type)
suite.Require().Equal("ethermint.evm.v1.EventBlockBloom", em.Events()[0].Type)
}
8 changes: 3 additions & 5 deletions x/evm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
"enough balance",
func() {
args = types.TransactionArgs{To: &common.Address{}, From: &suite.address, Value: (*hexutil.Big)(big.NewInt(100))}
}, false, 0, false},
}, false, 0, false,
},
// should success, because gas limit lower than 21000 is ignored
{
"gas exceed allowance",
Expand Down Expand Up @@ -1261,9 +1262,7 @@ func (suite *KeeperTestSuite) TestQueryBaseFee() {
}

func (suite *KeeperTestSuite) TestEthCall() {
var (
req *types.EthCallRequest
)
var req *types.EthCallRequest

address := tests.GenerateAddress()
suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetNonce(suite.ctx, address))
Expand Down Expand Up @@ -1334,7 +1333,6 @@ func (suite *KeeperTestSuite) TestEthCall() {
}
})
}

}

func (suite *KeeperTestSuite) TestEmptyRequest() {
Expand Down
9 changes: 4 additions & 5 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ func (k Keeper) ChainID() *big.Int {

// EmitBlockBloomEvent emit block bloom events
func (k Keeper) EmitBlockBloomEvent(ctx sdk.Context, bloom ethtypes.Bloom) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeBlockBloom,
sdk.NewAttribute(types.AttributeKeyEthereumBloom, string(bloom.Bytes())),
),
_ = ctx.EventManager().EmitTypedEvent(
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
&types.EventBlockBloom{
Bloom: string(bloom.Bytes()),
},
)
}

Expand Down
3 changes: 0 additions & 3 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,8 @@ func (suite *KeeperTestSuite) TestGetAccountStorage() {
i++
return false
})

})
}

}

func (suite *KeeperTestSuite) TestGetAccountOrEmpty() {
Expand Down Expand Up @@ -520,7 +518,6 @@ func (suite *KeeperTestSuite) TestGetAccountOrEmpty() {
} else {
suite.Require().NotEqual(empty, res)
}

})
}
}
50 changes: 23 additions & 27 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,56 +72,52 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
}
}()

attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()),
eventEthereumTx := &types.EventEthereumTx{
Amount: tx.Value().String(),
// add event for ethereum transaction hash format
sdk.NewAttribute(types.AttributeKeyEthereumTxHash, response.Hash),
EthHash: response.Hash,
// add event for index of valid ethereum tx
sdk.NewAttribute(types.AttributeKeyTxIndex, strconv.FormatUint(txIndex, 10)),
Index: strconv.FormatUint(txIndex, 10),
// add event for eth tx gas used, we can't get it from cosmos tx result when it contains multiple eth tx msgs.
sdk.NewAttribute(types.AttributeKeyTxGasUsed, strconv.FormatUint(response.GasUsed, 10)),
GasUsed: strconv.FormatUint(response.GasUsed, 10),
}

if len(ctx.TxBytes()) > 0 {
// add event for tendermint transaction hash format
hash := tmbytes.HexBytes(tmtypes.Tx(ctx.TxBytes()).Hash())
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String()))
eventEthereumTx.Hash = hash.String()
}

if to := tx.To(); to != nil {
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, to.Hex()))
eventEthereumTx.Recipient = to.Hex()
}

if response.Failed() {
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyEthereumTxFailed, response.VmError))
eventEthereumTx.EthTxFailed = response.VmError
}

txLogAttrs := make([]sdk.Attribute, len(response.Logs))
eventTxLogs := &types.EventTxLog{TxLogs: make([]string, len(response.Logs))}
for i, log := range response.Logs {
value, err := json.Marshal(log)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to encode log")
}
txLogAttrs[i] = sdk.NewAttribute(types.AttributeKeyTxLog, string(value))
eventTxLogs.TxLogs[i] = string(value)
}

// emit events
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeEthereumTx,
attrs...,
),
sdk.NewEvent(
types.EventTypeTxLog,
txLogAttrs...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender),
sdk.NewAttribute(types.AttributeKeyTxType, fmt.Sprintf("%d", tx.Type())),
),
})
err = ctx.EventManager().EmitTypedEvents(
eventEthereumTx,
eventTxLogs,
&types.EventMessage{
Module: types.AttributeValueCategory,
Sender: sender,
TxType: fmt.Sprintf("%d", tx.Type()),
},
)

if err != nil {
k.Logger(ctx).Error(err.Error())
}

return response, nil
}
4 changes: 2 additions & 2 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package keeper_test

import (
"github.com/evmos/ethermint/x/evm/types"
"reflect"

"github.com/evmos/ethermint/x/evm/types"
)

func (suite *KeeperTestSuite) TestParams() {
Expand Down Expand Up @@ -91,5 +92,4 @@ func (suite *KeeperTestSuite) TestParams() {
suite.Require().Equal(tc.expected, outcome)
})
}

}
3 changes: 2 additions & 1 deletion x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
} else if commit != nil {
// PostTxProcessing is successful, commit the tmpCtx
commit()
// Since the post processing can alter the log, we need to update the result
// Since the post-processing can alter the log, we need to update the result
res.Logs = types.NewLogsFromEth(receipt.Logs)
// TODO: figure out how to make this work with typed events
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
ctx.EventManager().EmitEvents(tmpCtx.EventManager().Events())
}
}
Expand Down
1 change: 0 additions & 1 deletion x/evm/keeper/state_transition_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func newNativeMessage(
msgSigner := ethtypes.MakeSigner(cfg, big.NewInt(blockHeight))

msg, baseFee, err := newEthMsgTx(nonce, blockHeight, address, cfg, krSigner, ethSigner, txType, data, accessList)

if err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions x/evm/keeper/state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,10 @@ func (suite *KeeperTestSuite) TestApplyMessageWithConfig() {
suite.Require().Equal(expectedGasUsed, res.GasUsed)
})
}

}

func (suite *KeeperTestSuite) createContractGethMsg(nonce uint64, signer ethtypes.Signer, cfg *params.ChainConfig, gasPrice *big.Int) (core.Message, error) {

ethMsg, err := suite.createContractMsgTx(nonce, signer, cfg, gasPrice)

if err != nil {
return nil, err
}
Expand All @@ -676,7 +673,6 @@ func (suite *KeeperTestSuite) createContractGethMsg(nonce uint64, signer ethtype
}

func (suite *KeeperTestSuite) createContractMsgTx(nonce uint64, signer ethtypes.Signer, cfg *params.ChainConfig, gasPrice *big.Int) (*types.MsgEthereumTx, error) {

contractCreateTx := &ethtypes.AccessListTx{
GasPrice: gasPrice,
Gas: params.TxGasContractCreation,
Expand Down
1 change: 0 additions & 1 deletion x/evm/keeper/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ func (suite *KeeperTestSuite) TestSetBalance() {
suite.Require().NoError(err)
suite.Require().Equal(amount, balance)
}

})
}
}
Expand Down
Loading