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
5a829ce7
Unverified
Commit
5a829ce7
authored
Apr 30, 2024
by
Adrian Sutton
Committed by
GitHub
Apr 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Apply game window to list-games (#10336)
Avoids it getting increasingly slower over time.
parent
98afa5b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
11 deletions
+28
-11
list_games.go
op-challenger/cmd/list_games.go
+12
-5
gamefactory.go
op-challenger/game/fault/contracts/gamefactory.go
+8
-6
gamefactory_test.go
op-challenger/game/fault/contracts/gamefactory_test.go
+7
-0
types.go
op-challenger/game/types/types.go
+1
-0
No files found.
op-challenger/cmd/list_games.go
View file @
5a829ce7
...
...
@@ -3,6 +3,7 @@ package main
import
(
"context"
"fmt"
"slices"
"sync"
"time"
...
...
@@ -11,6 +12,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
opservice
"github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/dial"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
...
...
@@ -33,6 +35,8 @@ func ListGames(ctx *cli.Context) error {
return
err
}
gameWindow
:=
ctx
.
Duration
(
flags
.
GameWindowFlag
.
Name
)
l1Client
,
err
:=
dial
.
DialEthClientWithTimeout
(
ctx
.
Context
,
dial
.
DefaultDialTimeout
,
logger
,
rpcUrl
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to dial L1: %w"
,
err
)
...
...
@@ -45,7 +49,7 @@ func ListGames(ctx *cli.Context) error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to retrieve current head block: %w"
,
err
)
}
return
listGames
(
ctx
.
Context
,
caller
,
contract
,
head
.
Hash
())
return
listGames
(
ctx
.
Context
,
caller
,
contract
,
head
.
Hash
()
,
gameWindow
)
}
type
gameInfo
struct
{
...
...
@@ -57,11 +61,13 @@ type gameInfo struct {
err
error
}
func
listGames
(
ctx
context
.
Context
,
caller
*
batching
.
MultiCaller
,
factory
*
contracts
.
DisputeGameFactoryContract
,
block
common
.
Hash
)
error
{
games
,
err
:=
factory
.
GetAllGames
(
ctx
,
block
)
func
listGames
(
ctx
context
.
Context
,
caller
*
batching
.
MultiCaller
,
factory
*
contracts
.
DisputeGameFactoryContract
,
block
common
.
Hash
,
gameWindow
time
.
Duration
)
error
{
earliestTimestamp
:=
clock
.
MinCheckedTimestamp
(
clock
.
SystemClock
,
gameWindow
)
games
,
err
:=
factory
.
GetGamesAtOrAfter
(
ctx
,
block
,
earliestTimestamp
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to retrieve games: %w"
,
err
)
}
slices
.
Reverse
(
games
)
infos
:=
make
([]
*
gameInfo
,
len
(
games
))
var
wg
sync
.
WaitGroup
...
...
@@ -95,13 +101,13 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
wg
.
Wait
()
lineFormat
:=
"%3v %-42v %4v %-21v %14v %-66v %6v %-14v
\n
"
fmt
.
Printf
(
lineFormat
,
"Idx"
,
"Game"
,
"Type"
,
"Created (Local)"
,
"L2 Block"
,
"Output Root"
,
"Claims"
,
"Status"
)
for
idx
,
game
:=
range
infos
{
for
_
,
game
:=
range
infos
{
if
game
.
err
!=
nil
{
return
game
.
err
}
created
:=
time
.
Unix
(
int64
(
game
.
Timestamp
),
0
)
.
Format
(
time
.
DateTime
)
fmt
.
Printf
(
lineFormat
,
id
x
,
game
.
Proxy
,
game
.
GameType
,
created
,
game
.
l2BlockNum
,
game
.
rootClaim
,
game
.
claimCount
,
game
.
status
)
game
.
Inde
x
,
game
.
Proxy
,
game
.
GameType
,
created
,
game
.
l2BlockNum
,
game
.
rootClaim
,
game
.
claimCount
,
game
.
status
)
}
return
nil
}
...
...
@@ -110,6 +116,7 @@ func listGamesFlags() []cli.Flag {
cliFlags
:=
[]
cli
.
Flag
{
flags
.
L1EthRpcFlag
,
flags
.
FactoryAddressFlag
,
flags
.
GameWindowFlag
,
}
cliFlags
=
append
(
cliFlags
,
oplog
.
CLIFlags
(
"OP_CHALLENGER"
)
...
)
return
cliFlags
...
...
op-challenger/game/fault/contracts/gamefactory.go
View file @
5a829ce7
...
...
@@ -73,7 +73,7 @@ func (f *DisputeGameFactoryContract) GetGame(ctx context.Context, idx uint64, bl
if
err
!=
nil
{
return
types
.
GameMetadata
{},
fmt
.
Errorf
(
"failed to load game %v: %w"
,
idx
,
err
)
}
return
f
.
decodeGame
(
result
),
nil
return
f
.
decodeGame
(
idx
,
result
),
nil
}
func
(
f
*
DisputeGameFactoryContract
)
GetGameImpl
(
ctx
context
.
Context
,
gameType
uint32
)
(
common
.
Address
,
error
)
{
...
...
@@ -118,8 +118,9 @@ func (f *DisputeGameFactoryContract) GetGamesAtOrAfter(ctx context.Context, bloc
return
nil
,
fmt
.
Errorf
(
"failed to fetch games: %w"
,
err
)
}
for
_
,
result
:=
range
results
{
game
:=
f
.
decodeGame
(
result
)
for
i
,
result
:=
range
results
{
idx
:=
rangeEnd
-
uint64
(
i
)
-
1
game
:=
f
.
decodeGame
(
idx
,
result
)
if
game
.
Timestamp
<
earliestTimestamp
{
return
games
,
nil
}
...
...
@@ -147,8 +148,8 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash
}
var
games
[]
types
.
GameMetadata
for
_
,
result
:=
range
results
{
games
=
append
(
games
,
f
.
decodeGame
(
result
))
for
i
,
result
:=
range
results
{
games
=
append
(
games
,
f
.
decodeGame
(
uint64
(
i
),
result
))
}
return
games
,
nil
}
...
...
@@ -189,11 +190,12 @@ func (f *DisputeGameFactoryContract) DecodeDisputeGameCreatedLog(rcpt *ethTypes.
return
common
.
Address
{},
0
,
common
.
Hash
{},
fmt
.
Errorf
(
"%w: %v"
,
ErrEventNotFound
,
eventDisputeGameCreated
)
}
func
(
f
*
DisputeGameFactoryContract
)
decodeGame
(
result
*
batching
.
CallResult
)
types
.
GameMetadata
{
func
(
f
*
DisputeGameFactoryContract
)
decodeGame
(
idx
uint64
,
result
*
batching
.
CallResult
)
types
.
GameMetadata
{
gameType
:=
result
.
GetUint32
(
0
)
timestamp
:=
result
.
GetUint64
(
1
)
proxy
:=
result
.
GetAddress
(
2
)
return
types
.
GameMetadata
{
Index
:
idx
,
GameType
:
gameType
,
Timestamp
:
timestamp
,
Proxy
:
proxy
,
...
...
op-challenger/game/fault/contracts/gamefactory_test.go
View file @
5a829ce7
...
...
@@ -61,16 +61,19 @@ func TestLoadGame(t *testing.T) {
blockHash
:=
common
.
Hash
{
0xbb
,
0xce
}
stubRpc
,
factory
:=
setupDisputeGameFactoryTest
(
t
)
game0
:=
types
.
GameMetadata
{
Index
:
0
,
GameType
:
0
,
Timestamp
:
1234
,
Proxy
:
common
.
Address
{
0xaa
},
}
game1
:=
types
.
GameMetadata
{
Index
:
1
,
GameType
:
1
,
Timestamp
:
5678
,
Proxy
:
common
.
Address
{
0xbb
},
}
game2
:=
types
.
GameMetadata
{
Index
:
2
,
GameType
:
99
,
Timestamp
:
9988
,
Proxy
:
common
.
Address
{
0xcc
},
...
...
@@ -88,16 +91,19 @@ func TestGetAllGames(t *testing.T) {
blockHash
:=
common
.
Hash
{
0xbb
,
0xce
}
stubRpc
,
factory
:=
setupDisputeGameFactoryTest
(
t
)
game0
:=
types
.
GameMetadata
{
Index
:
0
,
GameType
:
0
,
Timestamp
:
1234
,
Proxy
:
common
.
Address
{
0xaa
},
}
game1
:=
types
.
GameMetadata
{
Index
:
1
,
GameType
:
1
,
Timestamp
:
5678
,
Proxy
:
common
.
Address
{
0xbb
},
}
game2
:=
types
.
GameMetadata
{
Index
:
2
,
GameType
:
99
,
Timestamp
:
9988
,
Proxy
:
common
.
Address
{
0xcc
},
...
...
@@ -135,6 +141,7 @@ func TestGetAllGamesAtOrAfter(t *testing.T) {
var
allGames
[]
types
.
GameMetadata
for
i
:=
0
;
i
<
test
.
gameCount
;
i
++
{
allGames
=
append
(
allGames
,
types
.
GameMetadata
{
Index
:
uint64
(
i
),
GameType
:
uint32
(
i
),
Timestamp
:
uint64
(
i
),
Proxy
:
common
.
Address
{
byte
(
i
)},
...
...
op-challenger/game/types/types.go
View file @
5a829ce7
...
...
@@ -40,6 +40,7 @@ func GameStatusFromUint8(i uint8) (GameStatus, error) {
}
type
GameMetadata
struct
{
Index
uint64
GameType
uint32
Timestamp
uint64
Proxy
common
.
Address
...
...
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