Skip to content

Commit

Permalink
Merge pull request #335 from OffchainLabs/metrics
Browse files Browse the repository at this point in the history
[NIT-1168] Metrics for total gas used for eth_call and total gas used for eth_estimateGas
  • Loading branch information
joshuacolvin0 authored Jul 12, 2024
2 parents e52de0a + c186780 commit 64d5c61
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/ethereum/go-ethereum/eth/gasestimator"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
Expand All @@ -52,6 +53,10 @@ import (
)

var errBlobTxNotSupported = errors.New("signing blob transactions not supported")
var (
gasUsedEthEstimateGasGauge = metrics.NewRegisteredCounter("rpc/gas_used/eth_estimategas", nil)
gasUsedEthCallGauge = metrics.NewRegisteredCounter("rpc/gas_used/eth_call", nil)
)

func fallbackClientFor(b Backend, err error) types.FallbackClient {
if !errors.Is(err, types.ErrUseFallback) {
Expand Down Expand Up @@ -1242,6 +1247,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
if len(result.Revert()) > 0 {
return nil, newRevertError(result.Revert())
}
gasUsedEthCallGauge.Inc(int64(result.UsedGas))
return result.Return(), result.Err
}

Expand Down Expand Up @@ -1312,6 +1318,9 @@ func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, b
err := client.CallContext(ctx, &res, "eth_estimateGas", args, blockNrOrHash, overrides)
return res, err
}
if err != nil {
gasUsedEthEstimateGasGauge.Inc(int64(res))
}
return res, err
}

Expand Down

0 comments on commit 64d5c61

Please sign in to comment.