Skip to content

Commit 3eb72e8

Browse files
committed
fix(op-wheel): record block base fee on its own gauge
RecordBlockStats set BlockGas twice — once with gas used and once with the base fee — which left the BlockBaseFee gauge unset and clobbered the gas gauge. Record the base fee on BlockBaseFee instead. Also fix the pre-block status log, which emitted status.Gas for the "basefee" field instead of status.BaseFee. Adds a regression test asserting gas and base fee land on their own gauges. Closes #20958
1 parent 729d492 commit 3eb72e8

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

op-wheel/engine/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func Auto(
247247
continue
248248
}
249249
log.Info("status", "head", status.Head, "safe", status.Safe, "finalized", status.Finalized,
250-
"head_time", status.Head.Time, "txs", status.Txs, "gas", status.Gas, "basefee", status.Gas)
250+
"head_time", status.Head.Time, "txs", status.Txs, "gas", status.Gas, "basefee", status.BaseFee)
251251

252252
// On a mocked "beacon epoch transition", update finalization and justification checkpoints.
253253
// There are no gap slots, so we just go back 32 blocks.

op-wheel/engine/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *Metrics) RecordBlockStats(hash common.Hash, num uint64, time uint64, tx
8181
r.BlockTime.Set(float64(time))
8282
r.BlockTxs.Set(float64(txs))
8383
r.BlockGas.Set(float64(gas))
84-
r.BlockGas.Set(float64(baseFee))
84+
r.BlockBaseFee.Set(baseFee)
8585
}
8686

8787
var _ Metricer = (*Metrics)(nil)

op-wheel/engine/metrics_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package engine
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/prometheus/client_golang/prometheus"
8+
dto "github.com/prometheus/client_model/go"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func gaugeValue(t *testing.T, g prometheus.Gauge) float64 {
13+
t.Helper()
14+
var m dto.Metric
15+
require.NoError(t, g.Write(&m))
16+
return m.GetGauge().GetValue()
17+
}
18+
19+
// TestRecordBlockStats ensures gas and base fee are recorded on their own
20+
// gauges. Distinct values are used so a regression that records the base fee
21+
// onto the gas gauge (or leaves the base-fee gauge unset) is caught.
22+
func TestRecordBlockStats(t *testing.T) {
23+
m := NewMetrics("test", prometheus.NewRegistry())
24+
25+
const gas = uint64(21000)
26+
const baseFee = float64(1234)
27+
28+
m.RecordBlockStats(common.Hash{0x01}, 5, 100, 3, gas, baseFee)
29+
30+
require.Equal(t, float64(gas), gaugeValue(t, m.BlockGas), "BlockGas should record gas used")
31+
require.Equal(t, baseFee, gaugeValue(t, m.BlockBaseFee), "BlockBaseFee should record the block base fee")
32+
}

0 commit comments

Comments
 (0)