Skip to content

Commit

Permalink
op-challenger: Add a metric to report the number of large preimage pr…
Browse files Browse the repository at this point in the history
…oposals (#11154)
  • Loading branch information
ajsutton authored Jul 16, 2024
1 parent 66ad3ab commit eda7fdc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions op-challenger/game/keccak/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ type OracleSource interface {
Oracles() []keccakTypes.LargePreimageOracle
}

type Metrics interface {
RecordLargePreimageCount(count int)
}

type LargePreimageScheduler struct {
log log.Logger
m Metrics
cl faultTypes.ClockReader
ch chan common.Hash
oracles OracleSource
Expand All @@ -33,11 +38,13 @@ type LargePreimageScheduler struct {

func NewLargePreimageScheduler(
logger log.Logger,
m Metrics,
cl faultTypes.ClockReader,
oracleSource OracleSource,
challenger Challenger) *LargePreimageScheduler {
return &LargePreimageScheduler{
log: logger,
m: m,
cl: cl,
ch: make(chan common.Hash, 1),
oracles: oracleSource,
Expand Down Expand Up @@ -94,6 +101,7 @@ func (s *LargePreimageScheduler) verifyOraclePreimages(ctx context.Context, orac
if err != nil {
return err
}
s.m.RecordLargePreimageCount(len(preimages))
period, err := oracle.ChallengePeriod(ctx)
if err != nil {
return fmt.Errorf("failed to load challenge period: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion op-challenger/game/keccak/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/testlog"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestScheduleNextCheck(t *testing.T) {
}
cl := clock.NewDeterministicClock(time.Unix(int64(currentTimestamp), 0))
challenger := &stubChallenger{}
scheduler := NewLargePreimageScheduler(logger, cl, OracleSourceArray{oracle}, challenger)
scheduler := NewLargePreimageScheduler(logger, metrics.NoopMetrics, cl, OracleSourceArray{oracle}, challenger)
scheduler.Start(ctx)
defer scheduler.Close()
err := scheduler.Schedule(common.Hash{0xaa}, 3)
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (s *Service) initLargePreimages() error {
fetcher := fetcher.NewPreimageFetcher(s.logger, s.l1Client)
verifier := keccak.NewPreimageVerifier(s.logger, fetcher)
challenger := keccak.NewPreimageChallenger(s.logger, s.metrics, verifier, s.txSender)
s.preimages = keccak.NewLargePreimageScheduler(s.logger, s.l1Clock, s.oracles, challenger)
s.preimages = keccak.NewLargePreimageScheduler(s.logger, s.metrics, s.l1Clock, s.oracles, challenger)
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions op-challenger/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Metricer interface {
RecordGameUpdateScheduled()
RecordGameUpdateCompleted()

RecordLargePreimageCount(count int)

IncActiveExecutors()
DecActiveExecutors()
IncIdleExecutors()
Expand Down Expand Up @@ -81,6 +83,7 @@ type Metrics struct {

preimageChallenged prometheus.Counter
preimageChallengeFailed prometheus.Counter
preimageCount prometheus.Gauge

highestActedL1Block prometheus.Gauge

Expand Down Expand Up @@ -193,6 +196,11 @@ func NewMetrics() *Metrics {
Name: "preimage_challenge_failed",
Help: "Number of preimage challenges that failed",
}),
preimageCount: factory.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "preimage_count",
Help: "Number of large preimage proposals being tracked by the challenger",
}),
trackedGames: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tracked_games",
Expand Down Expand Up @@ -261,6 +269,10 @@ func (m *Metrics) RecordPreimageChallengeFailed() {
m.preimageChallengeFailed.Add(1)
}

func (m *Metrics) RecordLargePreimageCount(count int) {
m.preimageCount.Set(float64(count))
}

func (m *Metrics) RecordBondClaimFailed() {
m.bondClaimFailures.Add(1)
}
Expand Down
1 change: 1 addition & 0 deletions op-challenger/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (*NoopMetricsImpl) RecordActedL1Block(_ uint64) {}

func (*NoopMetricsImpl) RecordPreimageChallenged() {}
func (*NoopMetricsImpl) RecordPreimageChallengeFailed() {}
func (*NoopMetricsImpl) RecordLargePreimageCount(_ int) {}

func (*NoopMetricsImpl) RecordBondClaimFailed() {}
func (*NoopMetricsImpl) RecordBondClaimed(uint64) {}
Expand Down

0 comments on commit eda7fdc

Please sign in to comment.