From c112d05ffb82a2fcd120f45afc719db9c0d0284b Mon Sep 17 00:00:00 2001 From: Mael Regnery Date: Mon, 29 Sep 2025 10:25:26 +0200 Subject: [PATCH] rpc: add a metric for the gas used on eth_call --- internal/ethapi/api.go | 7 +++++++ internal/ethapi/metrics.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 internal/ethapi/metrics.go diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2432bb70b85..3bc5f471b82 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -775,6 +775,13 @@ func (api *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockN if err != nil { return nil, err } + + if result.UsedGas > gomath.MaxInt64 { + rpcEthCallGasUsedHist.Update(gomath.MaxInt64) + } else { + rpcEthCallGasUsedHist.Update(int64(result.UsedGas)) + } + if errors.Is(result.Err, vm.ErrExecutionReverted) { return nil, newRevertError(result.Revert()) } diff --git a/internal/ethapi/metrics.go b/internal/ethapi/metrics.go new file mode 100644 index 00000000000..58d5de2f36e --- /dev/null +++ b/internal/ethapi/metrics.go @@ -0,0 +1,21 @@ +// Copyright 2025 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package ethapi + +import "github.com/ethereum/go-ethereum/metrics" + +var rpcEthCallGasUsedHist = metrics.NewRegisteredHistogram("rpc/gas_used/eth_call", nil, metrics.NewExpDecaySample(1028, 0.015))