Commit 2bb23ffc authored by refcell's avatar refcell Committed by GitHub

fix(op-dispute-mon): Remove Delays Calculator (#10372)

* fix(op-dispute-mon): remove the delays calculator

* fix(op-challenger): resolution import
parent 154f976d
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types" gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/resolution" "github.com/ethereum-optimism/optimism/op-dispute-mon/mon"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform" "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform"
disputeTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types" disputeTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -90,7 +90,7 @@ func enrichClaims(claims []types.Claim) []disputeTypes.EnrichedClaim { ...@@ -90,7 +90,7 @@ func enrichClaims(claims []types.Claim) []disputeTypes.EnrichedClaim {
func gameResult(game types.Game) (gameTypes.GameStatus, *disputeTypes.BidirectionalTree, types.Game) { func gameResult(game types.Game) (gameTypes.GameStatus, *disputeTypes.BidirectionalTree, types.Game) {
tree := transform.CreateBidirectionalTree(enrichClaims(game.Claims())) tree := transform.CreateBidirectionalTree(enrichClaims(game.Claims()))
result := resolution.Resolve(tree) result := mon.Resolve(tree)
resolvedClaims := make([]types.Claim, 0, len(tree.Claims)) resolvedClaims := make([]types.Claim, 0, len(tree.Claims))
for _, claim := range tree.Claims { for _, claim := range tree.Claims {
resolvedClaims = append(resolvedClaims, *claim.Claim) resolvedClaims = append(resolvedClaims, *claim.Claim)
......
...@@ -88,8 +88,6 @@ type Metricer interface { ...@@ -88,8 +88,6 @@ type Metricer interface {
RecordWithdrawalRequests(delayedWeth common.Address, matches bool, count int) RecordWithdrawalRequests(delayedWeth common.Address, matches bool, count int)
RecordClaimResolutionDelayMax(delay float64)
RecordOutputFetchTime(timestamp float64) RecordOutputFetchTime(timestamp float64)
RecordGameAgreement(status GameAgreementStatus, count int) RecordGameAgreement(status GameAgreementStatus, count int)
...@@ -129,8 +127,6 @@ type Metrics struct { ...@@ -129,8 +127,6 @@ type Metrics struct {
lastOutputFetch prometheus.Gauge lastOutputFetch prometheus.Gauge
claimResolutionDelayMax prometheus.Gauge
gamesAgreement prometheus.GaugeVec gamesAgreement prometheus.GaugeVec
ignoredGames prometheus.Gauge ignoredGames prometheus.Gauge
...@@ -173,11 +169,6 @@ func NewMetrics() *Metrics { ...@@ -173,11 +169,6 @@ func NewMetrics() *Metrics {
Name: "last_output_fetch", Name: "last_output_fetch",
Help: "Timestamp of the last output fetch", Help: "Timestamp of the last output fetch",
}), }),
claimResolutionDelayMax: factory.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "claim_resolution_delay_max",
Help: "Maximum claim resolution delay in seconds",
}),
honestActorClaims: *factory.NewGaugeVec(prometheus.GaugeOpts{ honestActorClaims: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace, Namespace: Namespace,
Name: "honest_actor_claims", Name: "honest_actor_claims",
...@@ -367,10 +358,6 @@ func (m *Metrics) RecordWithdrawalRequests(delayedWeth common.Address, matches b ...@@ -367,10 +358,6 @@ func (m *Metrics) RecordWithdrawalRequests(delayedWeth common.Address, matches b
m.withdrawalRequests.WithLabelValues(delayedWeth.Hex(), credits).Set(float64(count)) m.withdrawalRequests.WithLabelValues(delayedWeth.Hex(), credits).Set(float64(count))
} }
func (m *Metrics) RecordClaimResolutionDelayMax(delay float64) {
m.claimResolutionDelayMax.Set(delay)
}
func (m *Metrics) Document() []opmetrics.DocumentedMetric { func (m *Metrics) Document() []opmetrics.DocumentedMetric {
return m.factory.Document() return m.factory.Document()
} }
......
...@@ -29,8 +29,6 @@ func (*NoopMetricsImpl) RecordClaims(_ ClaimStatus, _ int) {} ...@@ -29,8 +29,6 @@ func (*NoopMetricsImpl) RecordClaims(_ ClaimStatus, _ int) {}
func (*NoopMetricsImpl) RecordWithdrawalRequests(_ common.Address, _ bool, _ int) {} func (*NoopMetricsImpl) RecordWithdrawalRequests(_ common.Address, _ bool, _ int) {}
func (*NoopMetricsImpl) RecordClaimResolutionDelayMax(_ float64) {}
func (*NoopMetricsImpl) RecordOutputFetchTime(_ float64) {} func (*NoopMetricsImpl) RecordOutputFetchTime(_ float64) {}
func (*NoopMetricsImpl) RecordGameAgreement(_ GameAgreementStatus, _ int) {} func (*NoopMetricsImpl) RecordGameAgreement(_ GameAgreementStatus, _ int) {}
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/metrics" "github.com/ethereum-optimism/optimism/op-dispute-mon/metrics"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/resolution"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform" "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types" monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -24,7 +23,6 @@ type OutputValidator interface { ...@@ -24,7 +23,6 @@ type OutputValidator interface {
} }
type ForecastMetrics interface { type ForecastMetrics interface {
RecordClaimResolutionDelayMax(delay float64)
RecordGameAgreement(status metrics.GameAgreementStatus, count int) RecordGameAgreement(status metrics.GameAgreementStatus, count int)
RecordIgnoredGames(count int) RecordIgnoredGames(count int)
} }
...@@ -107,7 +105,7 @@ func (f *forecast) forecastGame(ctx context.Context, game *monTypes.EnrichedGame ...@@ -107,7 +105,7 @@ func (f *forecast) forecastGame(ctx context.Context, game *monTypes.EnrichedGame
tree := transform.CreateBidirectionalTree(game.Claims) tree := transform.CreateBidirectionalTree(game.Claims)
// Compute the resolution status of the game. // Compute the resolution status of the game.
forecastStatus := resolution.Resolve(tree) forecastStatus := Resolve(tree)
if agreement { if agreement {
// If we agree with the output root proposal, the Defender should win, defending that claim. // If we agree with the output root proposal, the Defender should win, defending that claim.
......
...@@ -286,7 +286,6 @@ func zeroGameAgreement() map[metrics.GameAgreementStatus]int { ...@@ -286,7 +286,6 @@ func zeroGameAgreement() map[metrics.GameAgreementStatus]int {
type mockForecastMetrics struct { type mockForecastMetrics struct {
gameAgreement map[metrics.GameAgreementStatus]int gameAgreement map[metrics.GameAgreementStatus]int
ignoredGames int ignoredGames int
claimResolutionDelayMax float64
} }
func (m *mockForecastMetrics) RecordGameAgreement(status metrics.GameAgreementStatus, count int) { func (m *mockForecastMetrics) RecordGameAgreement(status metrics.GameAgreementStatus, count int) {
...@@ -297,10 +296,6 @@ func (m *mockForecastMetrics) RecordIgnoredGames(count int) { ...@@ -297,10 +296,6 @@ func (m *mockForecastMetrics) RecordIgnoredGames(count int) {
m.ignoredGames = count m.ignoredGames = count
} }
func (m *mockForecastMetrics) RecordClaimResolutionDelayMax(delay float64) {
m.claimResolutionDelayMax = delay
}
func createDeepClaimList() []monTypes.EnrichedClaim { func createDeepClaimList() []monTypes.EnrichedClaim {
return []monTypes.EnrichedClaim{ return []monTypes.EnrichedClaim{
{ {
......
...@@ -21,7 +21,6 @@ type MonitorWithdrawals func(games []*types.EnrichedGameData) ...@@ -21,7 +21,6 @@ type MonitorWithdrawals func(games []*types.EnrichedGameData)
type BlockHashFetcher func(ctx context.Context, number *big.Int) (common.Hash, error) type BlockHashFetcher func(ctx context.Context, number *big.Int) (common.Hash, error)
type BlockNumberFetcher func(ctx context.Context) (uint64, error) type BlockNumberFetcher func(ctx context.Context) (uint64, error)
type Extract func(ctx context.Context, blockHash common.Hash, minTimestamp uint64) ([]*types.EnrichedGameData, int, error) type Extract func(ctx context.Context, blockHash common.Hash, minTimestamp uint64) ([]*types.EnrichedGameData, int, error)
type RecordClaimResolutionDelayMax func([]*types.EnrichedGameData)
type gameMonitor struct { type gameMonitor struct {
logger log.Logger logger log.Logger
...@@ -34,7 +33,6 @@ type gameMonitor struct { ...@@ -34,7 +33,6 @@ type gameMonitor struct {
gameWindow time.Duration gameWindow time.Duration
monitorInterval time.Duration monitorInterval time.Duration
delays RecordClaimResolutionDelayMax
forecast Forecast forecast Forecast
bonds Bonds bonds Bonds
resolutions Resolutions resolutions Resolutions
...@@ -51,7 +49,6 @@ func newGameMonitor( ...@@ -51,7 +49,6 @@ func newGameMonitor(
cl clock.Clock, cl clock.Clock,
monitorInterval time.Duration, monitorInterval time.Duration,
gameWindow time.Duration, gameWindow time.Duration,
delays RecordClaimResolutionDelayMax,
forecast Forecast, forecast Forecast,
bonds Bonds, bonds Bonds,
resolutions Resolutions, resolutions Resolutions,
...@@ -68,7 +65,6 @@ func newGameMonitor( ...@@ -68,7 +65,6 @@ func newGameMonitor(
done: make(chan struct{}), done: make(chan struct{}),
monitorInterval: monitorInterval, monitorInterval: monitorInterval,
gameWindow: gameWindow, gameWindow: gameWindow,
delays: delays,
forecast: forecast, forecast: forecast,
bonds: bonds, bonds: bonds,
resolutions: resolutions, resolutions: resolutions,
...@@ -96,7 +92,6 @@ func (m *gameMonitor) monitorGames() error { ...@@ -96,7 +92,6 @@ func (m *gameMonitor) monitorGames() error {
return fmt.Errorf("failed to load games: %w", err) return fmt.Errorf("failed to load games: %w", err)
} }
m.resolutions(enrichedGames) m.resolutions(enrichedGames)
m.delays(enrichedGames)
m.forecast(m.ctx, enrichedGames, ignored) m.forecast(m.ctx, enrichedGames, ignored)
m.bonds(enrichedGames) m.bonds(enrichedGames)
m.claims(enrichedGames) m.claims(enrichedGames)
......
...@@ -24,7 +24,7 @@ func TestMonitor_MonitorGames(t *testing.T) { ...@@ -24,7 +24,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("FailedFetchBlocknumber", func(t *testing.T) { t.Run("FailedFetchBlocknumber", func(t *testing.T) {
monitor, _, _, _, _, _, _, _ := setupMonitorTest(t) monitor, _, _, _, _, _, _ := setupMonitorTest(t)
boom := errors.New("boom") boom := errors.New("boom")
monitor.fetchBlockNumber = func(ctx context.Context) (uint64, error) { monitor.fetchBlockNumber = func(ctx context.Context) (uint64, error) {
return 0, boom return 0, boom
...@@ -34,7 +34,7 @@ func TestMonitor_MonitorGames(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
}) })
t.Run("FailedFetchBlockHash", func(t *testing.T) { t.Run("FailedFetchBlockHash", func(t *testing.T) {
monitor, _, _, _, _, _, _, _ := setupMonitorTest(t) monitor, _, _, _, _, _, _ := setupMonitorTest(t)
boom := errors.New("boom") boom := errors.New("boom")
monitor.fetchBlockHash = func(ctx context.Context, number *big.Int) (common.Hash, error) { monitor.fetchBlockHash = func(ctx context.Context, number *big.Int) (common.Hash, error) {
return common.Hash{}, boom return common.Hash{}, boom
...@@ -44,12 +44,11 @@ func TestMonitor_MonitorGames(t *testing.T) { ...@@ -44,12 +44,11 @@ func TestMonitor_MonitorGames(t *testing.T) {
}) })
t.Run("MonitorsWithNoGames", func(t *testing.T) { t.Run("MonitorsWithNoGames", func(t *testing.T) {
monitor, factory, forecast, delays, bonds, withdrawals, resolutions, claims := setupMonitorTest(t) monitor, factory, forecast, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{} factory.games = []*monTypes.EnrichedGameData{}
err := monitor.monitorGames() err := monitor.monitorGames()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, forecast.calls) require.Equal(t, 1, forecast.calls)
require.Equal(t, 1, delays.calls)
require.Equal(t, 1, bonds.calls) require.Equal(t, 1, bonds.calls)
require.Equal(t, 1, resolutions.calls) require.Equal(t, 1, resolutions.calls)
require.Equal(t, 1, claims.calls) require.Equal(t, 1, claims.calls)
...@@ -57,12 +56,11 @@ func TestMonitor_MonitorGames(t *testing.T) { ...@@ -57,12 +56,11 @@ func TestMonitor_MonitorGames(t *testing.T) {
}) })
t.Run("MonitorsMultipleGames", func(t *testing.T) { t.Run("MonitorsMultipleGames", func(t *testing.T) {
monitor, factory, forecast, delays, bonds, withdrawals, resolutions, claims := setupMonitorTest(t) monitor, factory, forecast, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{{}, {}, {}} factory.games = []*monTypes.EnrichedGameData{{}, {}, {}}
err := monitor.monitorGames() err := monitor.monitorGames()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, forecast.calls) require.Equal(t, 1, forecast.calls)
require.Equal(t, 1, delays.calls)
require.Equal(t, 1, bonds.calls) require.Equal(t, 1, bonds.calls)
require.Equal(t, 1, resolutions.calls) require.Equal(t, 1, resolutions.calls)
require.Equal(t, 1, claims.calls) require.Equal(t, 1, claims.calls)
...@@ -74,7 +72,7 @@ func TestMonitor_StartMonitoring(t *testing.T) { ...@@ -74,7 +72,7 @@ func TestMonitor_StartMonitoring(t *testing.T) {
t.Run("MonitorsGames", func(t *testing.T) { t.Run("MonitorsGames", func(t *testing.T) {
addr1 := common.Address{0xaa} addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb} addr2 := common.Address{0xbb}
monitor, factory, forecaster, _, _, _, _, _ := setupMonitorTest(t) monitor, factory, forecaster, _, _, _, _ := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{newEnrichedGameData(addr1, 9999), newEnrichedGameData(addr2, 9999)} factory.games = []*monTypes.EnrichedGameData{newEnrichedGameData(addr1, 9999), newEnrichedGameData(addr2, 9999)}
factory.maxSuccess = len(factory.games) // Only allow two successful fetches factory.maxSuccess = len(factory.games) // Only allow two successful fetches
...@@ -87,7 +85,7 @@ func TestMonitor_StartMonitoring(t *testing.T) { ...@@ -87,7 +85,7 @@ func TestMonitor_StartMonitoring(t *testing.T) {
}) })
t.Run("FailsToFetchGames", func(t *testing.T) { t.Run("FailsToFetchGames", func(t *testing.T) {
monitor, factory, forecaster, _, _, _, _, _ := setupMonitorTest(t) monitor, factory, forecaster, _, _, _, _ := setupMonitorTest(t)
factory.fetchErr = errors.New("boom") factory.fetchErr = errors.New("boom")
monitor.StartMonitoring() monitor.StartMonitoring()
...@@ -109,7 +107,7 @@ func newEnrichedGameData(proxy common.Address, timestamp uint64) *monTypes.Enric ...@@ -109,7 +107,7 @@ func newEnrichedGameData(proxy common.Address, timestamp uint64) *monTypes.Enric
} }
} }
func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast, *mockDelayCalculator, *mockBonds, *mockWithdrawalMonitor, *mockResolutionMonitor, *mockClaimMonitor) { func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast, *mockBonds, *mockWithdrawalMonitor, *mockResolutionMonitor, *mockClaimMonitor) {
logger := testlog.Logger(t, log.LvlDebug) logger := testlog.Logger(t, log.LvlDebug)
fetchBlockNum := func(ctx context.Context) (uint64, error) { fetchBlockNum := func(ctx context.Context) (uint64, error) {
return 1, nil return 1, nil
...@@ -126,14 +124,12 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast ...@@ -126,14 +124,12 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast
resolutions := &mockResolutionMonitor{} resolutions := &mockResolutionMonitor{}
claims := &mockClaimMonitor{} claims := &mockClaimMonitor{}
withdrawals := &mockWithdrawalMonitor{} withdrawals := &mockWithdrawalMonitor{}
delays := &mockDelayCalculator{}
monitor := newGameMonitor( monitor := newGameMonitor(
context.Background(), context.Background(),
logger, logger,
cl, cl,
monitorInterval, monitorInterval,
10*time.Second, 10*time.Second,
delays.RecordClaimResolutionDelayMax,
forecast.Forecast, forecast.Forecast,
bonds.CheckBonds, bonds.CheckBonds,
resolutions.CheckResolutions, resolutions.CheckResolutions,
...@@ -143,7 +139,7 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast ...@@ -143,7 +139,7 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast
fetchBlockNum, fetchBlockNum,
fetchBlockHash, fetchBlockHash,
) )
return monitor, extractor, forecast, delays, bonds, withdrawals, resolutions, claims return monitor, extractor, forecast, bonds, withdrawals, resolutions, claims
} }
type mockResolutionMonitor struct { type mockResolutionMonitor struct {
...@@ -170,14 +166,6 @@ func (m *mockWithdrawalMonitor) CheckWithdrawals(games []*monTypes.EnrichedGameD ...@@ -170,14 +166,6 @@ func (m *mockWithdrawalMonitor) CheckWithdrawals(games []*monTypes.EnrichedGameD
m.calls++ m.calls++
} }
type mockDelayCalculator struct {
calls int
}
func (m *mockDelayCalculator) RecordClaimResolutionDelayMax(games []*monTypes.EnrichedGameData) {
m.calls++
}
type mockForecast struct { type mockForecast struct {
calls int calls int
} }
......
package resolution
import (
"time"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/clock"
)
type DelayMetrics interface {
RecordClaimResolutionDelayMax(delay float64)
}
type DelayCalculator struct {
metrics DelayMetrics
clock clock.Clock
}
func NewDelayCalculator(metrics DelayMetrics, clock clock.Clock) *DelayCalculator {
return &DelayCalculator{
metrics: metrics,
clock: clock,
}
}
func (d *DelayCalculator) RecordClaimResolutionDelayMax(games []*types.EnrichedGameData) {
var maxDelay uint64 = 0
for _, game := range games {
maxDelay = max(d.getMaxResolutionDelay(game), maxDelay)
}
d.metrics.RecordClaimResolutionDelayMax(float64(maxDelay))
}
func (d *DelayCalculator) getMaxResolutionDelay(game *types.EnrichedGameData) uint64 {
var maxDelay uint64 = 0
for _, claim := range game.Claims {
maxDelay = max(d.getOverflowTime(game.MaxClockDuration, &claim), maxDelay)
}
return maxDelay
}
func (d *DelayCalculator) getOverflowTime(maxClockDuration uint64, claim *types.EnrichedClaim) uint64 {
if claim.Resolved {
return 0
}
maxChessTime := time.Duration(maxClockDuration) * time.Second
accumulatedTime := claim.ChessTime(d.clock.Now())
if accumulatedTime < maxChessTime {
return 0
}
return uint64((accumulatedTime - maxChessTime).Seconds())
}
package resolution
import (
"math/big"
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/stretchr/testify/require"
)
var (
maxClockDuration = uint64(480)
frozen = time.Unix(int64(time.Hour.Seconds()), 0)
)
func TestDelayCalculator_getOverflowTime(t *testing.T) {
t.Run("NoClock", func(t *testing.T) {
d, metrics, _ := setupDelayCalculatorTest(t)
claim := &monTypes.EnrichedClaim{
Resolved: true,
}
delay := d.getOverflowTime(maxClockDuration, claim)
require.Equal(t, uint64(0), delay)
require.Equal(t, 0, metrics.calls)
})
t.Run("RemainingTime", func(t *testing.T) {
d, metrics, cl := setupDelayCalculatorTest(t)
duration := 3 * time.Minute
timestamp := cl.Now().Add(-time.Minute)
claim := &monTypes.EnrichedClaim{
Claim: types.Claim{
ClaimData: types.ClaimData{
Bond: big.NewInt(5),
},
Clock: types.NewClock(duration, timestamp),
},
}
delay := d.getOverflowTime(maxClockDuration, claim)
require.Equal(t, uint64(0), delay)
require.Equal(t, 0, metrics.calls)
})
t.Run("OverflowTime", func(t *testing.T) {
d, metrics, cl := setupDelayCalculatorTest(t)
duration := time.Duration(maxClockDuration) * time.Second
timestamp := cl.Now().Add(4 * -time.Minute)
claim := &monTypes.EnrichedClaim{
Claim: types.Claim{
ClaimData: types.ClaimData{
Bond: big.NewInt(5),
},
Clock: types.NewClock(duration, timestamp),
},
}
delay := d.getOverflowTime(maxClockDuration, claim)
require.Equal(t, uint64(240), delay)
require.Equal(t, 0, metrics.calls)
})
}
func TestDelayCalculator_getMaxResolutionDelay(t *testing.T) {
tests := []struct {
name string
claims []monTypes.EnrichedClaim
want uint64
}{
{"NoClaims", []monTypes.EnrichedClaim{}, 0},
{"SingleClaim", createClaimList()[:1], 180},
{"MultipleClaims", createClaimList()[:2], 300},
{"ClaimsWithMaxUint128", createClaimList(), 300},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
d, metrics, _ := setupDelayCalculatorTest(t)
game := &monTypes.EnrichedGameData{
Claims: test.claims,
MaxClockDuration: maxClockDuration,
}
got := d.getMaxResolutionDelay(game)
require.Equal(t, 0, metrics.calls)
require.Equal(t, test.want, got)
})
}
}
func TestDelayCalculator_RecordClaimResolutionDelayMax(t *testing.T) {
tests := []struct {
name string
games []*monTypes.EnrichedGameData
want float64
}{
{"NoGames", createGameWithClaimsList()[:0], 0},
{"SingleGame", createGameWithClaimsList()[:1], 180},
{"MultipleGames", createGameWithClaimsList()[:2], 300},
{"ClaimsWithMaxUint128", createGameWithClaimsList(), 300},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
d, metrics, _ := setupDelayCalculatorTest(t)
d.RecordClaimResolutionDelayMax(test.games)
require.Equal(t, 1, metrics.calls)
require.Equal(t, test.want, metrics.maxDelay)
})
}
}
func setupDelayCalculatorTest(t *testing.T) (*DelayCalculator, *mockDelayMetrics, *clock.DeterministicClock) {
metrics := &mockDelayMetrics{}
cl := clock.NewDeterministicClock(frozen)
return NewDelayCalculator(metrics, cl), metrics, cl
}
func createGameWithClaimsList() []*monTypes.EnrichedGameData {
return []*monTypes.EnrichedGameData{
{
Claims: createClaimList()[:1],
MaxClockDuration: maxClockDuration,
},
{
Claims: createClaimList()[:2],
MaxClockDuration: maxClockDuration,
},
{
Claims: createClaimList(),
MaxClockDuration: maxClockDuration,
},
}
}
func createClaimList() []monTypes.EnrichedClaim {
newClock := func(multiplier int) types.Clock {
duration := maxClockDuration
timestamp := frozen.Add(-time.Minute * time.Duration(multiplier))
return types.NewClock(time.Duration(duration)*time.Second, timestamp)
}
return []monTypes.EnrichedClaim{
{
Claim: types.Claim{
ClaimData: types.ClaimData{
Bond: big.NewInt(5),
},
Clock: newClock(3),
},
},
{
Claim: types.Claim{
ClaimData: types.ClaimData{
Bond: big.NewInt(10),
},
Clock: newClock(5),
},
},
{
Claim: types.Claim{
ClaimData: types.ClaimData{
Bond: big.NewInt(100),
},
Clock: newClock(2),
},
},
{
Claim: types.Claim{
Clock: newClock(10),
},
Resolved: true,
},
}
}
type mockDelayMetrics struct {
calls int
maxDelay float64
}
func (m *mockDelayMetrics) RecordClaimResolutionDelayMax(delay float64) {
m.calls++
if delay > m.maxDelay {
m.maxDelay = delay
}
}
package resolution package mon
import ( import (
"math/big" "math/big"
......
package resolution package mon
import ( import (
"math/big" "math/big"
......
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"github.com/ethereum-optimism/optimism/op-dispute-mon/config" "github.com/ethereum-optimism/optimism/op-dispute-mon/config"
"github.com/ethereum-optimism/optimism/op-dispute-mon/metrics" "github.com/ethereum-optimism/optimism/op-dispute-mon/metrics"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract" "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/resolution"
"github.com/ethereum-optimism/optimism/op-dispute-mon/version" "github.com/ethereum-optimism/optimism/op-dispute-mon/version"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
...@@ -37,7 +36,6 @@ type Service struct { ...@@ -37,7 +36,6 @@ type Service struct {
cl clock.Clock cl clock.Clock
delays *resolution.DelayCalculator
extractor *extract.Extractor extractor *extract.Extractor
forecast *forecast forecast *forecast
bonds *bonds.Bonds bonds *bonds.Bonds
...@@ -95,7 +93,6 @@ func (s *Service) initFromConfig(ctx context.Context, cfg *config.Config) error ...@@ -95,7 +93,6 @@ func (s *Service) initFromConfig(ctx context.Context, cfg *config.Config) error
s.initOutputValidator() // Must be called before initForecast s.initOutputValidator() // Must be called before initForecast
s.initGameCallerCreator() // Must be called before initForecast s.initGameCallerCreator() // Must be called before initForecast
s.initDelayCalculator()
s.initExtractor(cfg) s.initExtractor(cfg)
s.initForecast(cfg) s.initForecast(cfg)
...@@ -129,10 +126,6 @@ func (s *Service) initGameCallerCreator() { ...@@ -129,10 +126,6 @@ func (s *Service) initGameCallerCreator() {
s.game = extract.NewGameCallerCreator(s.metrics, batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize)) s.game = extract.NewGameCallerCreator(s.metrics, batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize))
} }
func (s *Service) initDelayCalculator() {
s.delays = resolution.NewDelayCalculator(s.metrics, s.cl)
}
func (s *Service) initExtractor(cfg *config.Config) { func (s *Service) initExtractor(cfg *config.Config) {
s.extractor = extract.NewExtractor( s.extractor = extract.NewExtractor(
s.logger, s.logger,
...@@ -230,7 +223,6 @@ func (s *Service) initMonitor(ctx context.Context, cfg *config.Config) { ...@@ -230,7 +223,6 @@ func (s *Service) initMonitor(ctx context.Context, cfg *config.Config) {
s.cl, s.cl,
cfg.MonitorInterval, cfg.MonitorInterval,
cfg.GameWindow, cfg.GameWindow,
s.delays.RecordClaimResolutionDelayMax,
s.forecast.Forecast, s.forecast.Forecast,
s.bonds.CheckBonds, s.bonds.CheckBonds,
s.resolutions.CheckResolutions, s.resolutions.CheckResolutions,
......
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