Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var (
headFastBlockGauge = metrics.NewRegisteredGauge("chain/head/receipt", nil)
headFinalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil)
headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil)
headBaseFeeGauge = metrics.NewRegisteredGauge("chain/head/basefee", nil)

chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil)
chainMgaspsMeter = metrics.NewRegisteredResettingTimer("chain/mgasps", nil)
Expand Down Expand Up @@ -1230,7 +1229,9 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) {

bc.currentBlock.Store(block.Header())
headBlockGauge.Update(int64(block.NumberU64()))
headBaseFeeGauge.TryUpdate(block.Header().BaseFee)

// OPStack addition
updateOptimismBlockMetrics(block.Header())
}

// stopWithoutSaving stops the blockchain service. If any imports are currently in progress
Expand Down Expand Up @@ -1398,7 +1399,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
bc.currentSnapBlock.Store(header)
headHeaderGauge.Update(header.Number.Int64())
headFastBlockGauge.Update(header.Number.Int64())
headBaseFeeGauge.TryUpdate(header.BaseFee)

// OPStack addition
updateOptimismBlockMetrics(header)
return nil
}
// writeAncient writes blockchain and corresponding receipt chain into ancient store.
Expand Down Expand Up @@ -2771,7 +2774,9 @@ func (bc *BlockChain) InsertHeadersBeforeCutoff(headers []*types.Header) (int, e
bc.currentSnapBlock.Store(last)
headHeaderGauge.Update(last.Number.Int64())
headFastBlockGauge.Update(last.Number.Int64())
headBaseFeeGauge.TryUpdate(last.BaseFee)

// OPStack addition
updateOptimismBlockMetrics(last)
return 0, nil
}

Expand Down
27 changes: 27 additions & 0 deletions core/blockchain_optimism.go
Comment thread
sebastianst marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package core

import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/metrics"
)

// OPStack additions
var (
headBaseFeeGauge = metrics.NewRegisteredGauge("chain/head/basefee", nil)
headGasUsedGauge = metrics.NewRegisteredGauge("chain/head/gas_used", nil)
headBlobGasUsedGauge = metrics.NewRegisteredGauge("chain/head/blob_gas_used", nil)

headGasUsedHist = metrics.NewRegisteredHistogram("chain/head/gas_used_hist", nil, metrics.NewExpDecaySample(1028, 0.015))
headBlobGasUsedHist = metrics.NewRegisteredHistogram("chain/head/blob_gas_used_hist", nil, metrics.NewExpDecaySample(1028, 0.015))
Comment thread
geoknee marked this conversation as resolved.
)

func updateOptimismBlockMetrics(header *types.Header) error {
headBaseFeeGauge.TryUpdate(header.BaseFee)
headGasUsedGauge.Update(int64(header.GasUsed))
headBlobGasUsedGauge.TryUpdateUint64(header.BlobGasUsed)
headGasUsedHist.Update(int64(header.GasUsed))
if header.BlobGasUsed != nil {
headBlobGasUsedHist.Update(int64(*header.BlobGasUsed))
}
return nil
}
16 changes: 12 additions & 4 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine c
}
hc.currentHeaderHash = hc.CurrentHeader().Hash()
headHeaderGauge.Update(hc.CurrentHeader().Number.Int64())
headBaseFeeGauge.TryUpdate(hc.CurrentHeader().BaseFee)

// OPStack addition
updateOptimismBlockMetrics(hc.CurrentHeader())
return hc, nil
}

Expand Down Expand Up @@ -183,7 +185,9 @@ func (hc *HeaderChain) Reorg(headers []*types.Header) error {
hc.currentHeaderHash = last.Hash()
hc.currentHeader.Store(types.CopyHeader(last))
headHeaderGauge.Update(last.Number.Int64())
headBaseFeeGauge.TryUpdate(last.BaseFee)

// OPStack addition
updateOptimismBlockMetrics(last)
return nil
}

Expand Down Expand Up @@ -486,7 +490,9 @@ func (hc *HeaderChain) SetCurrentHeader(head *types.Header) {
hc.currentHeader.Store(head)
hc.currentHeaderHash = head.Hash()
headHeaderGauge.Update(head.Number.Int64())
headBaseFeeGauge.TryUpdate(head.BaseFee)

// OPStack addition
updateOptimismBlockMetrics(head)
}

type (
Expand Down Expand Up @@ -573,7 +579,9 @@ func (hc *HeaderChain) setHead(headBlock uint64, headTime uint64, updateFn Updat
hc.currentHeader.Store(parent)
hc.currentHeaderHash = parentHash
headHeaderGauge.Update(parent.Number.Int64())
headBaseFeeGauge.TryUpdate(parent.BaseFee)

// OPStack addition
updateOptimismBlockMetrics(parent)

// If this is the first iteration, wipe any leftover data upwards too so
// we don't end up with dangling daps in the database
Expand Down
5 changes: 4 additions & 1 deletion fork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ def:
- title: Warn on missing hardfork data and emit additional metrics
globs:
- "core/blockchain.go"
- title: Additional metrics
- title: Define additional header-based metrics
globs:
- "core/blockchain_optimism.go"
- title: Add hooks for additional header-chain metrics
globs:
- "core/headerchain.go"
- title: Optional Engine API extensions
Expand Down
10 changes: 10 additions & 0 deletions metrics/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (g *Gauge) Update(v int64) {
(*atomic.Int64)(g).Store(v)
}

// OPStack addition
// TryUpdate updates the gauge if the value is non-nil, converting it to int64.
func (g *Gauge) TryUpdate(v *big.Int) {
if v == nil {
Expand All @@ -53,6 +54,15 @@ func (g *Gauge) TryUpdate(v *big.Int) {
(*atomic.Int64)(g).Store(v.Int64())
}

// OPStack additon
// TryUpdate updates the gauge if the value is non-nil, converting it to int64.
func (g *Gauge) TryUpdateUint64(v *uint64) {
if v == nil {
return
}
(*atomic.Int64)(g).Store(int64(*v))
}

// UpdateIfGt updates the gauge's value if v is larger then the current value.
func (g *Gauge) UpdateIfGt(v int64) {
value := (*atomic.Int64)(g)
Expand Down