Commit 92d2e22d authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #7261 from ethereum-optimism/refcell/complete-games-queue

fix(op-challenger): Don't schedule updates for resolved games
parents c5732fc5 df2415a4
...@@ -114,6 +114,10 @@ func NewGamePlayer( ...@@ -114,6 +114,10 @@ func NewGamePlayer(
}, nil }, nil
} }
func (g *GamePlayer) Status() gameTypes.GameStatus {
return g.status
}
func (g *GamePlayer) ProgressGame(ctx context.Context) gameTypes.GameStatus { func (g *GamePlayer) ProgressGame(ctx context.Context) gameTypes.GameStatus {
if g.status != gameTypes.GameStatusInProgress { if g.status != gameTypes.GameStatusInProgress {
// Game is already complete so don't try to perform further actions. // Game is already complete so don't try to perform further actions.
......
...@@ -109,9 +109,14 @@ func (c *coordinator) createJob(game common.Address) (*job, error) { ...@@ -109,9 +109,14 @@ func (c *coordinator) createJob(game common.Address) (*job, error) {
return nil, fmt.Errorf("failed to create game player: %w", err) return nil, fmt.Errorf("failed to create game player: %w", err)
} }
state.player = player state.player = player
state.status = player.Status()
} }
state.inflight = true state.inflight = true
return &job{addr: game, player: state.player}, nil if state.status != types.GameStatusInProgress {
c.logger.Debug("Not rescheduling resolved game", "game", game, "status", state.status)
return nil, nil
}
return &job{addr: game, player: state.player, status: state.status}, nil
} }
func (c *coordinator) enqueueJob(ctx context.Context, j job) error { func (c *coordinator) enqueueJob(ctx context.Context, j job) error {
......
...@@ -150,7 +150,10 @@ func TestDeleteDataForResolvedGames(t *testing.T) { ...@@ -150,7 +150,10 @@ func TestDeleteDataForResolvedGames(t *testing.T) {
gameAddrs := []common.Address{gameAddr1, gameAddr2, gameAddr3} gameAddrs := []common.Address{gameAddr1, gameAddr2, gameAddr3}
require.NoError(t, c.schedule(ctx, gameAddrs)) require.NoError(t, c.schedule(ctx, gameAddrs))
require.Len(t, workQueue, len(gameAddrs), "should schedule all games") // The work queue should only contain jobs for games 1 and 2
// A resolved game should not be scheduled for an update.
// This makes the inflight game metric more robust.
require.Len(t, workQueue, 2, "should schedule all games")
// Game 1 progresses and is still in progress // Game 1 progresses and is still in progress
// Game 2 progresses and is now resolved // Game 2 progresses and is now resolved
...@@ -249,6 +252,10 @@ func (g *stubGame) ProgressGame(_ context.Context) types.GameStatus { ...@@ -249,6 +252,10 @@ func (g *stubGame) ProgressGame(_ context.Context) types.GameStatus {
return g.status return g.status
} }
func (g *stubGame) Status() types.GameStatus {
return g.status
}
type createdGames struct { type createdGames struct {
t *testing.T t *testing.T
createCompleted common.Address createCompleted common.Address
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
type GamePlayer interface { type GamePlayer interface {
ProgressGame(ctx context.Context) types.GameStatus ProgressGame(ctx context.Context) types.GameStatus
Status() types.GameStatus
} }
type DiskManager interface { type DiskManager interface {
......
...@@ -47,6 +47,10 @@ func (s *stubPlayer) ProgressGame(ctx context.Context) types.GameStatus { ...@@ -47,6 +47,10 @@ func (s *stubPlayer) ProgressGame(ctx context.Context) types.GameStatus {
return s.status return s.status
} }
func (s *stubPlayer) Status() types.GameStatus {
return s.status
}
func readWithTimeout[T any](t *testing.T, ch <-chan T) T { func readWithTimeout[T any](t *testing.T, ch <-chan T) T {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
......
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