From eda7fdc6c19d6a2f8c1ad96229eb8611b32876d2 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 16 Jul 2024 16:09:41 +1000 Subject: [PATCH] op-challenger: Add a metric to report the number of large preimage proposals (#11154) --- op-challenger/game/keccak/scheduler.go | 8 ++++++++ op-challenger/game/keccak/scheduler_test.go | 3 ++- op-challenger/game/service.go | 2 +- op-challenger/metrics/metrics.go | 12 ++++++++++++ op-challenger/metrics/noop.go | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/op-challenger/game/keccak/scheduler.go b/op-challenger/game/keccak/scheduler.go index e9d8cb583be4..233c2d218d31 100644 --- a/op-challenger/game/keccak/scheduler.go +++ b/op-challenger/game/keccak/scheduler.go @@ -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 @@ -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, @@ -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) diff --git a/op-challenger/game/keccak/scheduler_test.go b/op-challenger/game/keccak/scheduler_test.go index 067fc5d93065..30070becb82b 100644 --- a/op-challenger/game/keccak/scheduler_test.go +++ b/op-challenger/game/keccak/scheduler_test.go @@ -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" @@ -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) diff --git a/op-challenger/game/service.go b/op-challenger/game/service.go index fea6bc2aaf63..3aa0679d38c0 100644 --- a/op-challenger/game/service.go +++ b/op-challenger/game/service.go @@ -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 } diff --git a/op-challenger/metrics/metrics.go b/op-challenger/metrics/metrics.go index c46edcd67fcc..b5c9d19e298f 100644 --- a/op-challenger/metrics/metrics.go +++ b/op-challenger/metrics/metrics.go @@ -53,6 +53,8 @@ type Metricer interface { RecordGameUpdateScheduled() RecordGameUpdateCompleted() + RecordLargePreimageCount(count int) + IncActiveExecutors() DecActiveExecutors() IncIdleExecutors() @@ -81,6 +83,7 @@ type Metrics struct { preimageChallenged prometheus.Counter preimageChallengeFailed prometheus.Counter + preimageCount prometheus.Gauge highestActedL1Block prometheus.Gauge @@ -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", @@ -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) } diff --git a/op-challenger/metrics/noop.go b/op-challenger/metrics/noop.go index fc0f6d077803..1a3faf00b213 100644 --- a/op-challenger/metrics/noop.go +++ b/op-challenger/metrics/noop.go @@ -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) {}