Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
4925d5b5
Commit
4925d5b5
authored
Dec 07, 2023
by
refcell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(op-challenger): wire up coordinator prestate validation call
parent
73ef726b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
3 deletions
+25
-3
coordinator.go
op-challenger/game/scheduler/coordinator.go
+5
-3
coordinator_test.go
op-challenger/game/scheduler/coordinator_test.go
+14
-0
stub_player.go
op-challenger/game/scheduler/test/stub_player.go
+5
-0
types.go
op-challenger/game/scheduler/types.go
+1
-0
No files found.
op-challenger/game/scheduler/coordinator.go
View file @
4925d5b5
...
@@ -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
()
}
}
...
...
op-challenger/game/scheduler/coordinator_test.go
View file @
4925d5b5
...
@@ -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
}
}
...
...
op-challenger/game/scheduler/test/stub_player.go
View file @
4925d5b5
...
@@ -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
{
...
...
op-challenger/game/scheduler/types.go
View file @
4925d5b5
...
@@ -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
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment