forked from cerc-io/laconicd-deprecated
evm: SDK metrics (#24)
* evm: SDK metrics * update BeginBlock * changelog
This commit is contained in:
+12
-1
@@ -2,16 +2,24 @@ package keeper
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/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
|
||||
// and resets the Bloom filter and the transaction count to 0.
|
||||
func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
||||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
|
||||
|
||||
if req.Header.Height < 1 {
|
||||
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
|
||||
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
||||
|
||||
// TODO: why do we have so many hash -> height mappings
|
||||
k.SetBlockHash(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
|
||||
// an empty slice.
|
||||
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
|
||||
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
@@ -18,6 +21,8 @@ import (
|
||||
var _ types.MsgServer = &Keeper{}
|
||||
|
||||
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)
|
||||
|
||||
ethMsg, err := msg.AsMessage()
|
||||
@@ -30,6 +35,19 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
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()
|
||||
|
||||
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
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
|
||||
@@ -8,4 +8,7 @@ const (
|
||||
AttributeKeyRecipient = "recipient"
|
||||
AttributeKeyTxHash = "txHash"
|
||||
AttributeValueCategory = ModuleName
|
||||
|
||||
MetricKeyTransitionDB = "transition_db"
|
||||
MetricKeyStaticCall = "static_call"
|
||||
)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ var (
|
||||
// message type and route constants
|
||||
const (
|
||||
// TypeMsgEthereumTx defines the type string of an Ethereum transaction
|
||||
TypeMsgEthereumTx = "ethereum"
|
||||
TypeMsgEthereumTx = "ethereum_tx"
|
||||
)
|
||||
|
||||
// NewMsgEthereumTx returns a reference to a new Ethereum transaction message.
|
||||
|
||||
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/xlab/suplog"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
@@ -114,6 +116,8 @@ func (st *StateTransition) newEVM(
|
||||
// returning the evm execution result.
|
||||
// NOTE: State transition checks are run during AnteHandler execution.
|
||||
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
|
||||
|
||||
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
|
||||
// instead of performing the modifications.
|
||||
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
|
||||
gasLimit := st.Message.Gas() - ctx.GasMeter().GasConsumed()
|
||||
csdb := st.Csdb.WithContext(ctx)
|
||||
|
||||
Reference in New Issue
Block a user