Skip to content

Commit

Permalink
Merge pull request #1762 from OffchainLabs/add-gasused-metric
Browse files Browse the repository at this point in the history
Add gas used since startup to prometheus metric
  • Loading branch information
ganeshvanahalli committed Jul 14, 2023
2 parents 6d613c4 + 6a3cdbd commit 33692fd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -343,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++
}
Expand Down Expand Up @@ -416,11 +414,11 @@ func ProduceBlockAdvanced(
}
}

if blockGasLeft > computeUsed {
blockGasLeft -= computeUsed
} else {
blockGasLeft = 0
}
blockGasLeft = arbmath.SaturatingUSub(blockGasLeft, computeUsed)

// 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)
Expand Down

0 comments on commit 33692fd

Please sign in to comment.