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
98ab92e8
Commit
98ab92e8
authored
Aug 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify the monitor component to only progress games on new L1 block.
parent
0677bc6c
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 @
98ab92e8
...
@@ -87,11 +87,7 @@ func (m *gameMonitor) minGameTimestamp() uint64 {
...
@@ -87,11 +87,7 @@ func (m *gameMonitor) minGameTimestamp() uint64 {
return
0
return
0
}
}
func
(
m
*
gameMonitor
)
progressGames
(
ctx
context
.
Context
)
error
{
func
(
m
*
gameMonitor
)
progressGames
(
ctx
context
.
Context
,
blockNum
uint64
)
error
{
blockNum
,
err
:=
m
.
fetchBlockNumber
(
ctx
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load current block number: %w"
,
err
)
}
games
,
err
:=
m
.
source
.
FetchAllGamesAtBlock
(
ctx
,
m
.
minGameTimestamp
(),
new
(
big
.
Int
)
.
SetUint64
(
blockNum
))
games
,
err
:=
m
.
source
.
FetchAllGamesAtBlock
(
ctx
,
m
.
minGameTimestamp
(),
new
(
big
.
Int
)
.
SetUint64
(
blockNum
))
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load games: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to load games: %w"
,
err
)
...
@@ -147,13 +143,26 @@ func (m *gameMonitor) fetchOrCreateGamePlayer(gameData FaultDisputeGame) (gamePl
...
@@ -147,13 +143,26 @@ func (m *gameMonitor) fetchOrCreateGamePlayer(gameData FaultDisputeGame) (gamePl
func
(
m
*
gameMonitor
)
MonitorGames
(
ctx
context
.
Context
)
error
{
func
(
m
*
gameMonitor
)
MonitorGames
(
ctx
context
.
Context
)
error
{
m
.
logger
.
Info
(
"Monitoring fault dispute games"
)
m
.
logger
.
Info
(
"Monitoring fault dispute games"
)
blockNum
:=
uint64
(
0
)
for
{
for
{
err
:=
m
.
progressGames
(
ctx
)
select
{
if
err
!=
nil
{
case
<-
ctx
.
Done
()
:
m
.
logger
.
Error
(
"Failed to progress games"
,
"err"
,
err
)
return
ctx
.
Err
()
}
default
:
if
err
:=
m
.
clock
.
SleepCtx
(
ctx
,
300
*
time
.
Millisecond
);
err
!=
nil
{
nextBlockNum
,
err
:=
m
.
fetchBlockNumber
(
ctx
)
return
err
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 @
98ab92e8
...
@@ -65,8 +65,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
...
@@ -65,8 +65,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
},
},
}
}
err
:=
monitor
.
progressGames
(
context
.
Background
())
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
(),
uint64
(
1
)))
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
...
@@ -75,7 +74,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
...
@@ -75,7 +74,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
require
.
Equal
(
t
,
1
,
games
.
created
[
addr2
]
.
progressCount
)
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
// 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
[
addr1
]
.
progressCount
)
require
.
Equal
(
t
,
2
,
games
.
created
[
addr2
]
.
progressCount
)
require
.
Equal
(
t
,
2
,
games
.
created
[
addr2
]
.
progressCount
)
}
}
...
@@ -96,8 +95,7 @@ func TestMonitorOnlyCreateSpecifiedGame(t *testing.T) {
...
@@ -96,8 +95,7 @@ func TestMonitorOnlyCreateSpecifiedGame(t *testing.T) {
},
},
}
}
err
:=
monitor
.
progressGames
(
context
.
Background
())
require
.
NoError
(
t
,
monitor
.
progressGames
(
context
.
Background
(),
uint64
(
1
)))
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
games
.
created
,
1
,
"should only create allowed game"
)
require
.
Len
(
t
,
games
.
created
,
1
,
"should only create allowed game"
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
...
@@ -122,14 +120,14 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
...
@@ -122,14 +120,14 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
}
}
source
.
games
=
allGames
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
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
// First game is now old enough it's not returned in the list of active games
// First game is now old enough it's not returned in the list of active games
source
.
games
=
source
.
games
[
1
:
]
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
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
require
.
Contains
(
t
,
games
.
created
,
addr2
)
...
@@ -139,7 +137,7 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
...
@@ -139,7 +137,7 @@ func TestDeletePlayersWhenNoLongerInListOfGames(t *testing.T) {
// First game now reappears (inexplicably but usefully for our testing)
// First game now reappears (inexplicably but usefully for our testing)
source
.
games
=
allGames
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
// A new player is created for it because the original was deleted
require
.
Len
(
t
,
games
.
created
,
2
)
require
.
Len
(
t
,
games
.
created
,
2
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
require
.
Contains
(
t
,
games
.
created
,
addr1
)
...
@@ -165,7 +163,7 @@ func TestCleanupResourcesOfCompletedGames(t *testing.T) {
...
@@ -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
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
require
.
Len
(
t
,
games
.
created
,
2
,
"should create game agents"
)
...
@@ -187,8 +185,10 @@ func setupMonitorTest(t *testing.T, allowedGames []common.Address) (*gameMonitor
...
@@ -187,8 +185,10 @@ func setupMonitorTest(t *testing.T, allowedGames []common.Address) (*gameMonitor
t
:
t
,
t
:
t
,
created
:
make
(
map
[
common
.
Address
]
*
stubGame
),
created
:
make
(
map
[
common
.
Address
]
*
stubGame
),
}
}
i
:=
uint64
(
1
)
fetchBlockNum
:=
func
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
fetchBlockNum
:=
func
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
return
1234
,
nil
i
++
return
i
,
nil
}
}
disk
:=
&
stubDiskManager
{
disk
:=
&
stubDiskManager
{
gameDirExists
:
make
(
map
[
common
.
Address
]
bool
),
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