Commit 853842d1 authored by refcell's avatar refcell Committed by GitHub

fix(op-dispute-mon): export forecast to keep exporting consistent (#10430)

parent 89a3a5f3
...@@ -42,21 +42,21 @@ type forecastBatch struct { ...@@ -42,21 +42,21 @@ type forecastBatch struct {
LatestInvalidProposal uint64 LatestInvalidProposal uint64
} }
type forecast struct { type Forecast struct {
logger log.Logger logger log.Logger
metrics ForecastMetrics metrics ForecastMetrics
validator OutputValidator validator OutputValidator
} }
func newForecast(logger log.Logger, metrics ForecastMetrics, validator OutputValidator) *forecast { func NewForecast(logger log.Logger, metrics ForecastMetrics, validator OutputValidator) *Forecast {
return &forecast{ return &Forecast{
logger: logger, logger: logger,
metrics: metrics, metrics: metrics,
validator: validator, validator: validator,
} }
} }
func (f *forecast) Forecast(ctx context.Context, games []*monTypes.EnrichedGameData, ignoredCount int) { func (f *Forecast) Forecast(ctx context.Context, games []*monTypes.EnrichedGameData, ignoredCount int) {
batch := forecastBatch{} batch := forecastBatch{}
for _, game := range games { for _, game := range games {
if err := f.forecastGame(ctx, game, &batch); err != nil { if err := f.forecastGame(ctx, game, &batch); err != nil {
...@@ -66,7 +66,7 @@ func (f *forecast) Forecast(ctx context.Context, games []*monTypes.EnrichedGameD ...@@ -66,7 +66,7 @@ func (f *forecast) Forecast(ctx context.Context, games []*monTypes.EnrichedGameD
f.recordBatch(batch, ignoredCount) f.recordBatch(batch, ignoredCount)
} }
func (f *forecast) recordBatch(batch forecastBatch, ignoredCount int) { func (f *Forecast) recordBatch(batch forecastBatch, ignoredCount int) {
f.metrics.RecordGameAgreement(metrics.AgreeDefenderWins, batch.AgreeDefenderWins) f.metrics.RecordGameAgreement(metrics.AgreeDefenderWins, batch.AgreeDefenderWins)
f.metrics.RecordGameAgreement(metrics.DisagreeDefenderWins, batch.DisagreeDefenderWins) f.metrics.RecordGameAgreement(metrics.DisagreeDefenderWins, batch.DisagreeDefenderWins)
f.metrics.RecordGameAgreement(metrics.AgreeChallengerWins, batch.AgreeChallengerWins) f.metrics.RecordGameAgreement(metrics.AgreeChallengerWins, batch.AgreeChallengerWins)
...@@ -82,7 +82,7 @@ func (f *forecast) recordBatch(batch forecastBatch, ignoredCount int) { ...@@ -82,7 +82,7 @@ func (f *forecast) recordBatch(batch forecastBatch, ignoredCount int) {
f.metrics.RecordIgnoredGames(ignoredCount) f.metrics.RecordIgnoredGames(ignoredCount)
} }
func (f *forecast) forecastGame(ctx context.Context, game *monTypes.EnrichedGameData, metrics *forecastBatch) error { func (f *Forecast) forecastGame(ctx context.Context, game *monTypes.EnrichedGameData, metrics *forecastBatch) error {
// Check the root agreement. // Check the root agreement.
agreement, expected, err := f.validator.CheckRootAgreement(ctx, game.L1HeadNum, game.L2BlockNumber, game.RootClaim) agreement, expected, err := f.validator.CheckRootAgreement(ctx, game.L1HeadNum, game.L2BlockNumber, game.RootClaim)
if err != nil { if err != nil {
......
...@@ -266,13 +266,13 @@ func TestForecast_Forecast_MultipleGames(t *testing.T) { ...@@ -266,13 +266,13 @@ func TestForecast_Forecast_MultipleGames(t *testing.T) {
require.EqualValues(t, 7, m.latestInvalidProposal) require.EqualValues(t, 7, m.latestInvalidProposal)
} }
func setupForecastTest(t *testing.T) (*forecast, *mockForecastMetrics, *stubOutputValidator, *testlog.CapturingHandler) { func setupForecastTest(t *testing.T) (*Forecast, *mockForecastMetrics, *stubOutputValidator, *testlog.CapturingHandler) {
logger, capturedLogs := testlog.CaptureLogger(t, log.LvlDebug) logger, capturedLogs := testlog.CaptureLogger(t, log.LvlDebug)
validator := &stubOutputValidator{} validator := &stubOutputValidator{}
m := &mockForecastMetrics{ m := &mockForecastMetrics{
gameAgreement: zeroGameAgreement(), gameAgreement: zeroGameAgreement(),
} }
return newForecast(logger, m, validator), m, validator, capturedLogs return NewForecast(logger, m, validator), m, validator, capturedLogs
} }
func zeroGameAgreement() map[metrics.GameAgreementStatus]int { func zeroGameAgreement() map[metrics.GameAgreementStatus]int {
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
type Forecast func(ctx context.Context, games []*types.EnrichedGameData, ignoredCount int) type ForecastResolution func(ctx context.Context, games []*types.EnrichedGameData, ignoredCount int)
type Bonds func(games []*types.EnrichedGameData) type Bonds func(games []*types.EnrichedGameData)
type Resolutions func(games []*types.EnrichedGameData) type Resolutions func(games []*types.EnrichedGameData)
type MonitorClaims func(games []*types.EnrichedGameData) type MonitorClaims func(games []*types.EnrichedGameData)
...@@ -33,7 +33,7 @@ type gameMonitor struct { ...@@ -33,7 +33,7 @@ type gameMonitor struct {
gameWindow time.Duration gameWindow time.Duration
monitorInterval time.Duration monitorInterval time.Duration
forecast Forecast forecast ForecastResolution
bonds Bonds bonds Bonds
resolutions Resolutions resolutions Resolutions
claims MonitorClaims claims MonitorClaims
...@@ -49,7 +49,7 @@ func newGameMonitor( ...@@ -49,7 +49,7 @@ func newGameMonitor(
cl clock.Clock, cl clock.Clock,
monitorInterval time.Duration, monitorInterval time.Duration,
gameWindow time.Duration, gameWindow time.Duration,
forecast Forecast, forecast ForecastResolution,
bonds Bonds, bonds Bonds,
resolutions Resolutions, resolutions Resolutions,
claims MonitorClaims, claims MonitorClaims,
......
...@@ -37,7 +37,7 @@ type Service struct { ...@@ -37,7 +37,7 @@ type Service struct {
cl clock.Clock cl clock.Clock
extractor *extract.Extractor extractor *extract.Extractor
forecast *forecast forecast *Forecast
bonds *bonds.Bonds bonds *bonds.Bonds
game *extract.GameCallerCreator game *extract.GameCallerCreator
resolutions *ResolutionMonitor resolutions *ResolutionMonitor
...@@ -142,7 +142,7 @@ func (s *Service) initExtractor(cfg *config.Config) { ...@@ -142,7 +142,7 @@ func (s *Service) initExtractor(cfg *config.Config) {
} }
func (s *Service) initForecast(cfg *config.Config) { func (s *Service) initForecast(cfg *config.Config) {
s.forecast = newForecast(s.logger, s.metrics, s.validator) s.forecast = NewForecast(s.logger, s.metrics, s.validator)
} }
func (s *Service) initBonds() { func (s *Service) initBonds() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment