From 97c2bfa1e40518541345cfed4e089eb4e6c2c886 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Tue, 26 Mar 2024 10:04:28 -0500 Subject: [PATCH 1/2] 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 } From 8abc85558bc6952a275ce6f6f4308bc3dad1d0c1 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Tue, 26 Mar 2024 11:20:10 -0500 Subject: [PATCH 2/2] address PR comments --- execution/gethexec/executionengine.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 4ff10c70b7..518f95f1fa 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -27,10 +27,10 @@ import ( ) 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()) + baseFeeGauge = metrics.NewRegisteredGauge("arb/block/basefee", nil) + blockGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/gasused", nil, metrics.NewBoundedHistogramSample()) + txCountHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/count", nil, metrics.NewBoundedHistogramSample()) + txGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/gasused", nil, metrics.NewBoundedHistogramSample()) ) type ExecutionEngine struct { @@ -497,14 +497,14 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB return errors.New("geth rejected block as non-canonical") } baseFeeGauge.Update(block.BaseFee().Int64()) - txCountGauge.Update(int64(len(block.Transactions()) - 1)) + txCountHistogram.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)) + txGasUsedHistogram.Update(int64(val)) blockGasused += val } - blockGasUsedGauge.Update(int64(blockGasused)) + blockGasUsedHistogram.Update(int64(blockGasused)) return nil }