From 3d4f2e5f35d850b5a2f431e70e13bfdb04984491 Mon Sep 17 00:00:00 2001 From: Daniel Burckhardt Date: Fri, 27 May 2022 16:58:34 +0200 Subject: [PATCH 1/2] impr(evm): add tx_type, gas and counter telemetry for ethereum txs --- go.mod | 2 +- x/evm/keeper/msg_server.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f51997c3cb..cb448151ff 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/tharsis/ethermint go 1.17 require ( + github.com/armon/go-metrics v0.3.10 github.com/btcsuite/btcd v0.22.1 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/cosmos-sdk v0.45.4 @@ -45,7 +46,6 @@ require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect - github.com/armon/go-metrics v0.3.10 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 50c49afc2d..dd8d012734 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -9,6 +9,8 @@ import ( tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" + "github.com/armon/go-metrics" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -28,11 +30,38 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t tx := msg.AsTransaction() txIndex := k.GetTxIndexTransient(ctx) + labels := []metrics.Label{telemetry.NewLabel("tx_type", fmt.Sprintf("%d", tx.Type()))} + if tx.To() == nil { + labels = []metrics.Label{ + telemetry.NewLabel("execution", "create"), + } + } else { + labels = []metrics.Label{ + telemetry.NewLabel("execution", "call"), + telemetry.NewLabel("to", tx.To().Hex()), // recipient address (contract or account) + } + } + response, err := k.ApplyTransaction(ctx, tx) if err != nil { return nil, sdkerrors.Wrap(err, "failed to apply transaction") } + defer func() { + if tx.Value().IsInt64() { + telemetry.SetGauge( + float32(tx.Value().Int64()), + "tx", "msg", "ethereum_tx", + ) + } + + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, "ethereum_tx"}, + 1, + labels, + ) + }() + attrs := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()), // add event for ethereum transaction hash format From 685361b7169f647174182fe5711f442de1c0234f Mon Sep 17 00:00:00 2001 From: Daniel Burckhardt Date: Fri, 27 May 2022 17:03:29 +0200 Subject: [PATCH 2/2] impr(evm): Add CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0960ff578..eb00bff48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [tharsis#1086](https://github.com/tharsis/ethermint/pull/1086) Add rollback command. * (specs) [tharsis#1095](https://github.com/tharsis/ethermint/pull/1095) Add more evm specs concepts. +* (evm) [tharsis#1101](https://github.com/tharsis/ethermint/pull/1101) Add tx_type, gas and counter telemetry for ethereum txs. ### Bug Fixes