Skip to content

Commit c112d05

Browse files
committed
rpc: add a metric for the gas used on eth_call
1 parent 943a30d commit c112d05

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

internal/ethapi/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,13 @@ func (api *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockN
775775
if err != nil {
776776
return nil, err
777777
}
778+
779+
if result.UsedGas > gomath.MaxInt64 {
780+
rpcEthCallGasUsedHist.Update(gomath.MaxInt64)
781+
} else {
782+
rpcEthCallGasUsedHist.Update(int64(result.UsedGas))
783+
}
784+
778785
if errors.Is(result.Err, vm.ErrExecutionReverted) {
779786
return nil, newRevertError(result.Revert())
780787
}

internal/ethapi/metrics.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package ethapi
18+
19+
import "github.com/ethereum/go-ethereum/metrics"
20+
21+
var rpcEthCallGasUsedHist = metrics.NewRegisteredHistogram("rpc/gas_used/eth_call", nil, metrics.NewExpDecaySample(1028, 0.015))

0 commit comments

Comments
 (0)