evm: SDK metrics (#24)

* evm: SDK metrics

* update BeginBlock

* changelog
This commit is contained in:
Federico Kunze 2021-05-14 17:44:58 -04:00 committed by GitHub
parent ba5bf33f19
commit b3066f2631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 63 additions and 4 deletions

View File

@ -38,10 +38,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
## Unreleased ## Unreleased
### API Breaking ### API Breaking
* (eth) [\#845](https://github.com/cosmos/ethermint/pull/845) The `eth` namespace must be included in the list of API's as default to run the rpc server without error. * (eth) [\#845](https://github.com/cosmos/ethermint/pull/845) The `eth` namespace must be included in the list of API's as default to run the rpc server without error.
### Improvements ### Improvements
* (evm) [tharsis#24](https://github.com/tharsis/ethermint/pull/24)Implement metrics for `MsgEthereumTx`, state transtitions, `BeginBlock` and `EndBlock`.
* (deps) [\#602](https://github.com/cosmos/ethermint/pull/856) Bump tendermint version to [v0.39.3](https://github.com/tendermint/tendermint/releases/tag/v0.39.3) * (deps) [\#602](https://github.com/cosmos/ethermint/pull/856) Bump tendermint version to [v0.39.3](https://github.com/tendermint/tendermint/releases/tag/v0.39.3)
## [v0.4.1] - 2021-03-01 ## [v0.4.1] - 2021-03-01

2
go.mod
View File

@ -3,6 +3,7 @@ module github.com/cosmos/ethermint
go 1.15 go 1.15
require ( require (
github.com/armon/go-metrics v0.3.8
github.com/aws/aws-sdk-go v1.38.21 // indirect github.com/aws/aws-sdk-go v1.38.21 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/btcsuite/btcd v0.21.0-beta github.com/btcsuite/btcd v0.21.0-beta
@ -22,6 +23,7 @@ require (
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/improbable-eng/grpc-web v0.14.0 github.com/improbable-eng/grpc-web v0.14.0
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect

6
go.sum
View File

@ -82,8 +82,9 @@ github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.6 h1:x/tmtOF9cDBoXH7XoAGOz2qqm1DknFD1590XmD/DUJ8=
github.com/armon/go-metrics v0.3.6/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-metrics v0.3.6/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-metrics v0.3.8 h1:oOxq3KPj0WhCuy50EhzwiyMyG2ovRQZpZLXQuOh2a/M=
github.com/armon/go-metrics v0.3.8/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
@ -419,8 +420,9 @@ github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=

View File

@ -2,16 +2,24 @@ package keeper
import ( import (
"math/big" "math/big"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ethermint/x/evm/types"
) )
// BeginBlock sets the block hash -> block height map for the previous block height // BeginBlock sets the block hash -> block height map for the previous block height
// and resets the Bloom filter and the transaction count to 0. // and resets the Bloom filter and the transaction count to 0.
func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
if req.Header.Height < 1 { if req.Header.Height < 1 {
return return
} }
@ -19,6 +27,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
// Gas costs are handled within msg handler so costs should be ignored // Gas costs are handled within msg handler so costs should be ignored
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
// TODO: why do we have so many hash -> height mappings
k.SetBlockHash(ctx, req.Hash, req.Header.Height) k.SetBlockHash(ctx, req.Hash, req.Header.Height)
k.SetBlockHeightToHash(ctx, req.Hash, req.Header.Height) k.SetBlockHeightToHash(ctx, req.Hash, req.Header.Height)
@ -35,6 +44,8 @@ func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
// the store. The EVM end block logic doesn't update the validator set, thus it returns // the store. The EVM end block logic doesn't update the validator set, thus it returns
// an empty slice. // an empty slice.
func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
// Gas costs are handled within msg handler so costs should be ignored // Gas costs are handled within msg handler so costs should be ignored
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())

View File

@ -3,12 +3,15 @@ package keeper
import ( import (
"context" "context"
"errors" "errors"
"time"
"github.com/armon/go-metrics"
ethcmn "github.com/ethereum/go-ethereum/common" ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -18,6 +21,8 @@ import (
var _ types.MsgServer = &Keeper{} var _ types.MsgServer = &Keeper{}
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) { func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.TypeMsgEthereumTx)
ctx := sdk.UnwrapSDKContext(goCtx) ctx := sdk.UnwrapSDKContext(goCtx)
ethMsg, err := msg.AsMessage() ethMsg, err := msg.AsMessage()
@ -30,6 +35,19 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
return nil, types.ErrChainConfigNotFound return nil, types.ErrChainConfigNotFound
} }
var labels []metrics.Label
if msg.To() == nil {
labels = []metrics.Label{
telemetry.NewLabel("execution", "create"),
}
} else {
labels = []metrics.Label{
telemetry.NewLabel("execution", "call"),
// add label to the called recipient address (contract or account)
telemetry.NewLabel("to", msg.Data.To),
}
}
sender := ethMsg.From() sender := ethMsg.From()
txHash := tmtypes.Tx(ctx.TxBytes()).Hash() txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
@ -118,6 +136,21 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
} }
} }
defer func() {
if st.Message.Value().IsInt64() {
telemetry.SetGauge(
float32(st.Message.Value().Int64()),
"tx", "msg", "ethereum_tx",
)
}
telemetry.IncrCounterWithLabels(
[]string{types.ModuleName, "ethereum_tx"},
1,
labels,
)
}()
// emit events // emit events
ctx.EventManager().EmitEvents(sdk.Events{ ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent( sdk.NewEvent(

View File

@ -8,4 +8,7 @@ const (
AttributeKeyRecipient = "recipient" AttributeKeyRecipient = "recipient"
AttributeKeyTxHash = "txHash" AttributeKeyTxHash = "txHash"
AttributeValueCategory = ModuleName AttributeValueCategory = ModuleName
MetricKeyTransitionDB = "transition_db"
MetricKeyStaticCall = "static_call"
) )

View File

@ -25,7 +25,7 @@ var (
// message type and route constants // message type and route constants
const ( const (
// TypeMsgEthereumTx defines the type string of an Ethereum transaction // TypeMsgEthereumTx defines the type string of an Ethereum transaction
TypeMsgEthereumTx = "ethereum" TypeMsgEthereumTx = "ethereum_tx"
) )
// NewMsgEthereumTx returns a reference to a new Ethereum transaction message. // NewMsgEthereumTx returns a reference to a new Ethereum transaction message.

View File

@ -3,6 +3,7 @@ package types
import ( import (
"math/big" "math/big"
"os" "os"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/xlab/suplog" log "github.com/xlab/suplog"
@ -13,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
) )
@ -114,6 +116,8 @@ func (st *StateTransition) newEVM(
// returning the evm execution result. // returning the evm execution result.
// NOTE: State transition checks are run during AnteHandler execution. // NOTE: State transition checks are run during AnteHandler execution.
func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (resp *ExecutionResult, err error) { func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (resp *ExecutionResult, err error) {
defer telemetry.ModuleMeasureSince(ModuleName, time.Now(), MetricKeyTransitionDB)
contractCreation := st.Message.To() == nil contractCreation := st.Message.To() == nil
cost, err := core.IntrinsicGas(st.Message.Data(), st.Message.AccessList(), true, false, true) cost, err := core.IntrinsicGas(st.Message.Data(), st.Message.AccessList(), true, false, true)
@ -294,6 +298,8 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
// Opcodes that attempt to perform such modifications will result in exceptions // Opcodes that attempt to perform such modifications will result in exceptions
// instead of performing the modifications. // instead of performing the modifications.
func (st *StateTransition) StaticCall(ctx sdk.Context, config ChainConfig) ([]byte, error) { func (st *StateTransition) StaticCall(ctx sdk.Context, config ChainConfig) ([]byte, error) {
defer telemetry.ModuleMeasureSince(ModuleName, time.Now(), MetricKeyStaticCall)
// This gas limit the the transaction gas limit with intrinsic gas subtracted // This gas limit the the transaction gas limit with intrinsic gas subtracted
gasLimit := st.Message.Gas() - ctx.GasMeter().GasConsumed() gasLimit := st.Message.Gas() - ctx.GasMeter().GasConsumed()
csdb := st.Csdb.WithContext(ctx) csdb := st.Csdb.WithContext(ctx)