From 97c2bfa1e40518541345cfed4e089eb4e6c2c886 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Tue, 26 Mar 2024 10:04:28 -0500 Subject: [PATCH] Add metrics for L2 gas pricing [NIT-2361] --- execution/gethexec/executionengine.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index a662de3621..4ff10c70b7 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos" "github.com/offchainlabs/nitro/arbos/arbosState" @@ -20,10 +21,18 @@ import ( "github.com/offchainlabs/nitro/arbos/l1pricing" "github.com/offchainlabs/nitro/arbutil" "github.com/offchainlabs/nitro/execution" + "github.com/offchainlabs/nitro/util/arbmath" "github.com/offchainlabs/nitro/util/sharedmetrics" "github.com/offchainlabs/nitro/util/stopwaiter" ) +var ( + baseFeeGauge = metrics.NewRegisteredGauge("arb/block/basefee", nil) + blockGasUsedGauge = metrics.NewRegisteredHistogram("arb/block/gasused", nil, metrics.NewBoundedHistogramSample()) + txCountGauge = metrics.NewRegisteredHistogram("arb/block/transactions/count", nil, metrics.NewBoundedHistogramSample()) + txGasUsedGauge = metrics.NewRegisteredHistogram("arb/transaction/gasused", nil, metrics.NewBoundedHistogramSample()) +) + type ExecutionEngine struct { stopwaiter.StopWaiter @@ -487,6 +496,15 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB if status == core.SideStatTy { return errors.New("geth rejected block as non-canonical") } + baseFeeGauge.Update(block.BaseFee().Int64()) + txCountGauge.Update(int64(len(block.Transactions()) - 1)) + var blockGasused uint64 + for i := 1; i < len(receipts); i++ { + val := arbmath.SaturatingUSub(receipts[i].GasUsed, receipts[i].GasUsedForL1) + txGasUsedGauge.Update(int64(val)) + blockGasused += val + } + blockGasUsedGauge.Update(int64(blockGasused)) return nil }