Commit 4925d5b5 authored by refcell's avatar refcell

feat(op-challenger): wire up coordinator prestate validation call

parent 73ef726b
...@@ -63,7 +63,7 @@ func (c *coordinator) schedule(ctx context.Context, games []types.GameMetadata) ...@@ -63,7 +63,7 @@ func (c *coordinator) schedule(ctx context.Context, games []types.GameMetadata)
// Otherwise, results may start being processed before all games are recorded, resulting in existing // Otherwise, results may start being processed before all games are recorded, resulting in existing
// data directories potentially being deleted for games that are required. // data directories potentially being deleted for games that are required.
for _, game := range games { for _, game := range games {
if j, err := c.createJob(game); err != nil { if j, err := c.createJob(ctx, game); err != nil {
errs = append(errs, fmt.Errorf("failed to create job for game %v: %w", game.Proxy, err)) errs = append(errs, fmt.Errorf("failed to create job for game %v: %w", game.Proxy, err))
} else if j != nil { } else if j != nil {
jobs = append(jobs, *j) jobs = append(jobs, *j)
...@@ -96,7 +96,7 @@ func (c *coordinator) schedule(ctx context.Context, games []types.GameMetadata) ...@@ -96,7 +96,7 @@ func (c *coordinator) schedule(ctx context.Context, games []types.GameMetadata)
// createJob updates the state for the specified game and returns the job to enqueue for it, if any // createJob updates the state for the specified game and returns the job to enqueue for it, if any
// Returns (nil, nil) when there is no error and no job to enqueue // Returns (nil, nil) when there is no error and no job to enqueue
func (c *coordinator) createJob(game types.GameMetadata) (*job, error) { func (c *coordinator) createJob(ctx context.Context, game types.GameMetadata) (*job, error) {
state, ok := c.states[game.Proxy] state, ok := c.states[game.Proxy]
if !ok { if !ok {
state = &gameState{} state = &gameState{}
...@@ -112,7 +112,9 @@ func (c *coordinator) createJob(game types.GameMetadata) (*job, error) { ...@@ -112,7 +112,9 @@ func (c *coordinator) createJob(game types.GameMetadata) (*job, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create game player: %w", err) return nil, fmt.Errorf("failed to create game player: %w", err)
} }
// TODO(client-pod#325): Update coordinator to call the game player's ValidatePrestate method if err := player.ValidatePrestate(ctx); err != nil {
return nil, fmt.Errorf("failed to validate prestate: %w", err)
}
state.player = player state.player = player
state.status = player.Status() state.status = player.Status()
} }
......
...@@ -63,6 +63,16 @@ func TestExitWhenContextDoneWhileSchedulingJob(t *testing.T) { ...@@ -63,6 +63,16 @@ func TestExitWhenContextDoneWhileSchedulingJob(t *testing.T) {
require.Empty(t, workQueue, "should not have been able to schedule game") require.Empty(t, workQueue, "should not have been able to schedule game")
} }
func TestSchedule_PrestateValidationErrors(t *testing.T) {
c, _, _, games, _ := setupCoordinatorTest(t, 10)
games.PrestateErr = fmt.Errorf("prestate error")
gameAddr1 := common.Address{0xaa}
ctx := context.Background()
err := c.schedule(ctx, asGames(gameAddr1))
require.Error(t, err)
}
func TestScheduleGameAgainAfterCompletion(t *testing.T) { func TestScheduleGameAgainAfterCompletion(t *testing.T) {
c, workQueue, _, _, _ := setupCoordinatorTest(t, 10) c, workQueue, _, _, _ := setupCoordinatorTest(t, 10)
gameAddr1 := common.Address{0xaa} gameAddr1 := common.Address{0xaa}
...@@ -246,6 +256,7 @@ type createdGames struct { ...@@ -246,6 +256,7 @@ type createdGames struct {
createCompleted common.Address createCompleted common.Address
creationFails common.Address creationFails common.Address
created map[common.Address]*test.StubGamePlayer created map[common.Address]*test.StubGamePlayer
PrestateErr error
} }
func (c *createdGames) CreateGame(fdg types.GameMetadata, dir string) (GamePlayer, error) { func (c *createdGames) CreateGame(fdg types.GameMetadata, dir string) (GamePlayer, error) {
...@@ -265,6 +276,9 @@ func (c *createdGames) CreateGame(fdg types.GameMetadata, dir string) (GamePlaye ...@@ -265,6 +276,9 @@ func (c *createdGames) CreateGame(fdg types.GameMetadata, dir string) (GamePlaye
StatusValue: status, StatusValue: status,
Dir: dir, Dir: dir,
} }
if c.PrestateErr != nil {
game.PrestateErr = c.PrestateErr
}
c.created[addr] = game c.created[addr] = game
return game, nil return game, nil
} }
......
...@@ -12,6 +12,11 @@ type StubGamePlayer struct { ...@@ -12,6 +12,11 @@ type StubGamePlayer struct {
ProgressCount int ProgressCount int
StatusValue types.GameStatus StatusValue types.GameStatus
Dir string Dir string
PrestateErr error
}
func (g *StubGamePlayer) ValidatePrestate(_ context.Context) error {
return g.PrestateErr
} }
func (g *StubGamePlayer) ProgressGame(_ context.Context) types.GameStatus { func (g *StubGamePlayer) ProgressGame(_ context.Context) types.GameStatus {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
) )
type GamePlayer interface { type GamePlayer interface {
ValidatePrestate(ctx context.Context) error
ProgressGame(ctx context.Context) types.GameStatus ProgressGame(ctx context.Context) types.GameStatus
Status() types.GameStatus Status() types.GameStatus
} }
......
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