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
0e1330b2
Unverified
Commit
0e1330b2
authored
Aug 23, 2023
by
OptimismBot
Committed by
GitHub
Aug 23, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6974 from ethereum-optimism/refcell/progress-games-on-block
feat(op-challenger): Progress Games on New L1 Block
parents
94d05480
f7fd62de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
21 deletions
+30
-21
monitor.go
op-challenger/fault/monitor.go
+20
-11
monitor_test.go
op-challenger/fault/monitor_test.go
+10
-10
No files found.
op-challenger/fault/monitor.go
View file @
0e1330b2
...
...
@@ -87,11 +87,7 @@ func (m *gameMonitor) minGameTimestamp() uint64 {
return
0
}
func
(
m
*
gameMonitor
)
progressGames
(
ctx
context
.
Context
)
error
{
blockNum
,
err
:=
m
.
fetchBlockNumber
(
ctx
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load current block number: %w"
,
err
)
}
func
(
m
*
gameMonitor
)
progressGames
(
ctx
context
.
Context
,
blockNum
uint64
)
error
{
games
,
err
:=
m
.
source
.
FetchAllGamesAtBlock
(
ctx
,
m
.
minGameTimestamp
(),
new
(
big
.
Int
)
.
SetUint64
(
blockNum
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load games: %w"
,
err
)
...
...
@@ -147,13 +143,26 @@ func (m *gameMonitor) fetchOrCreateGamePlayer(gameData FaultDisputeGame) (gamePl
func
(
m
*
gameMonitor
)
MonitorGames
(
ctx
context
.
Context
)
error
{
m
.
logger
.
Info
(
"Monitoring fault dispute games"
)
blockNum
:=
uint64
(
0
)
for
{
err
:=
m
.
progressGames
(
ctx
)
if
err
!=
nil
{
m
.
logger
.
Error
(
"Failed to progress games"
,
"err"
,
err
)
}
if
err
:=
m
.
clock
.
SleepCtx
(
ctx
,
300
*
time
.
Millisecond
);
err
!=
nil
{
return
err
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
default
:
nextBlockNum
,
err
:=
m
.
fetchBlockNumber
(
ctx
)
if
err
!=
nil
{
m
.
logger
.
Error
(
"Failed to load current block number"
,
"err"
,
err
)
continue
}
if
nextBlockNum
>
blockNum
{
blockNum
=
nextBlockNum
if
err
:=
m
.
progressGames
(
ctx
,
nextBlockNum
);
err
!=
nil
{
m
.
logger
.
Error
(
"Failed to progress games"
,
"err"
,
err
)
}
}
if
err
:=
m
.
clock
.
SleepCtx
(
ctx
,
time
.
Second
);
err
!=
nil
{
return
err
}
}
}
}
op-challenger/fault/monitor_test.go
View file @
0e1330b2
...
...
@@ -65,8 +65,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
},
}
err
:=
monitor
.
progressGames
(
context
.
Background
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
(),
uint64
(
1
)))
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
...
...
@@ -75,7 +74,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
require
.
Equal
(
t
,
1
,
games
.
created
[
addr2
]
.
progressCount
)
// The stub will fail the test if a game is created with the same address multiple times
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()),
"should only create games once"
)
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()
,
uint64
(
2
)
),
"should only create games once"
)
require
.
Equal
(
t
,
2
,
games
.
created
[
addr1
]
.
progressCount
)
require
.
Equal
(
t
,
2
,
games
.
created
[
addr2
]
.
progressCount
)
}
...
...
@@ -96,8 +95,7 @@ func TestMonitorOnlyCreateSpecifiedGame(t *testing.T) {
},
}
err
:=
monitor
.
progressGames
(
context
.
Background
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
(),
uint64
(
1
)))
require
.
Len
(
t
,
games
.
created
,
1
,
"should only create allowed game"
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
...
...
@@ -122,14 +120,14 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
}
source
.
games
=
allGames
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()))
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()
,
uint64
(
1
)
))
require
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
// First game is now old enough it's not returned in the list of active games
source
.
games
=
source
.
games
[
1
:
]
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()))
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()
,
uint64
(
2
)
))
require
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
...
...
@@ -139,7 +137,7 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
// First game now reappears (inexplicably but usefully for our testing)
source
.
games
=
allGames
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()))
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
()
,
uint64
(
3
)
))
// A new player is created for it because the original was deleted
require
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
...
...
@@ -165,7 +163,7 @@ func TestCleanupResourcesOfCompletedGames(t *testing.T) {
},
}
err
:=
monitor
.
progressGames
(
context
.
Background
())
err
:=
monitor
.
progressGames
(
context
.
Background
()
,
uint64
(
1
)
)
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
...
...
@@ -187,8 +185,10 @@ func setupMonitorTest(t *testing.T, allowedGames []common.Address) (*gameMonitor
t
:
t
,
created
:
make
(
map
[
common
.
Address
]
*
stubGame
),
}
i
:=
uint64
(
1
)
fetchBlockNum
:=
func
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
return
1234
,
nil
i
++
return
i
,
nil
}
disk
:=
&
stubDiskManager
{
gameDirExists
:
make
(
map
[
common
.
Address
]
bool
),
...
...
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