From 823d927ec925e8bdaaf73bd8779abac169826d0a Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Fri, 14 Jul 2023 10:35:07 -0400 Subject: [PATCH 1/2] add gas used metric --- arbos/block_processor.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arbos/block_processor.go b/arbos/block_processor.go index 9f208c4404..0f26e000a4 100644 --- a/arbos/block_processor.go +++ b/arbos/block_processor.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" ) @@ -39,6 +40,7 @@ var L2ToL1TransactionEventID common.Hash var L2ToL1TxEventID common.Hash var EmitReedeemScheduledEvent func(*vm.EVM, uint64, uint64, [32]byte, [32]byte, common.Address, *big.Int, *big.Int) error var EmitTicketCreatedEvent func(*vm.EVM, [32]byte) error +var gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/sequencer/gasused", nil) type L1Info struct { poster common.Address @@ -422,6 +424,10 @@ func ProduceBlockAdvanced( blockGasLeft = 0 } + // add gas used since startup to prometheus metric + gasUsed := arbmath.SaturatingUSub(receipt.GasUsed, receipt.GasUsedForL1) + gasUsedSinceStartupCounter.Inc(arbmath.SaturatingCast(gasUsed)) + complete = append(complete, tx) receipts = append(receipts, receipt) From aefc1b9d684b76e35fac1bd80df06b052073e845 Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Fri, 14 Jul 2023 11:41:12 -0400 Subject: [PATCH 2/2] code refactor --- arbos/block_processor.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/arbos/block_processor.go b/arbos/block_processor.go index 0f26e000a4..653718b7d3 100644 --- a/arbos/block_processor.go +++ b/arbos/block_processor.go @@ -345,11 +345,7 @@ func ProduceBlockAdvanced( log.Debug("error applying transaction", "tx", tx, "err", err) if !hooks.DiscardInvalidTxsEarly { // we'll still deduct a TxGas's worth from the block-local rate limiter even if the tx was invalid - if blockGasLeft > params.TxGas { - blockGasLeft -= params.TxGas - } else { - blockGasLeft = 0 - } + blockGasLeft = arbmath.SaturatingUSub(blockGasLeft, params.TxGas) if isUserTx { userTxsProcessed++ } @@ -418,13 +414,9 @@ func ProduceBlockAdvanced( } } - if blockGasLeft > computeUsed { - blockGasLeft -= computeUsed - } else { - blockGasLeft = 0 - } + blockGasLeft = arbmath.SaturatingUSub(blockGasLeft, computeUsed) - // add gas used since startup to prometheus metric + // Add gas used since startup to prometheus metric. gasUsed := arbmath.SaturatingUSub(receipt.GasUsed, receipt.GasUsedForL1) gasUsedSinceStartupCounter.Inc(arbmath.SaturatingCast(gasUsed))