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
700a1dbc
Unverified
Commit
700a1dbc
authored
May 09, 2024
by
refcell
Committed by
GitHub
May 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(op-challenger): sort the games listing subcommand (#10454)
parent
7e2bb8a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
8 deletions
+63
-8
list_games.go
op-challenger/cmd/list_games.go
+63
-8
No files found.
op-challenger/cmd/list_games.go
View file @
700a1dbc
package
main
import
(
"cmp"
"context"
"fmt"
"slices"
...
...
@@ -14,6 +15,7 @@ import (
opservice
"github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/dial"
openum
"github.com/ethereum-optimism/optimism/op-service/enum"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
...
...
@@ -21,6 +23,22 @@ import (
"github.com/urfave/cli/v2"
)
var
ColumnTypes
=
[]
string
{
"time"
,
"claimCount"
,
"l2BlockNum"
}
var
(
SortByFlag
=
&
cli
.
StringFlag
{
Name
:
"sort-by"
,
Usage
:
"Sort games by column. Valid options: "
+
openum
.
EnumString
(
ColumnTypes
),
EnvVars
:
opservice
.
PrefixEnvVar
(
flags
.
EnvVarPrefix
,
"SORT_BY"
),
}
SortOrderFlag
=
&
cli
.
StringFlag
{
Name
:
"sort-order"
,
Usage
:
"Sort order for games. Valid options: 'asc' or 'desc'."
,
Value
:
"asc"
,
EnvVars
:
opservice
.
PrefixEnvVar
(
flags
.
EnvVarPrefix
,
"SORT_ORDER"
),
}
)
func
ListGames
(
ctx
*
cli
.
Context
)
error
{
logger
,
err
:=
setupLogging
(
ctx
)
if
err
!=
nil
{
...
...
@@ -34,6 +52,14 @@ func ListGames(ctx *cli.Context) error {
if
err
!=
nil
{
return
err
}
sortBy
:=
ctx
.
String
(
SortByFlag
.
Name
)
if
!
slices
.
Contains
(
ColumnTypes
,
sortBy
)
{
return
fmt
.
Errorf
(
"invalid sort-by value: %v"
,
sortBy
)
}
sortOrder
:=
ctx
.
String
(
SortOrderFlag
.
Name
)
if
sortOrder
!=
""
&&
sortOrder
!=
"asc"
&&
sortOrder
!=
"desc"
{
return
fmt
.
Errorf
(
"invalid sort-order value: %v"
,
sortOrder
)
}
gameWindow
:=
ctx
.
Duration
(
flags
.
GameWindowFlag
.
Name
)
...
...
@@ -49,7 +75,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
(),
gameWindow
)
return
listGames
(
ctx
.
Context
,
caller
,
contract
,
head
.
Hash
(),
gameWindow
,
sortBy
,
sortOrder
)
}
type
gameInfo
struct
{
...
...
@@ -61,7 +87,7 @@ type gameInfo struct {
err
error
}
func
listGames
(
ctx
context
.
Context
,
caller
*
batching
.
MultiCaller
,
factory
*
contracts
.
DisputeGameFactoryContract
,
block
common
.
Hash
,
gameWindow
time
.
Duration
)
error
{
func
listGames
(
ctx
context
.
Context
,
caller
*
batching
.
MultiCaller
,
factory
*
contracts
.
DisputeGameFactoryContract
,
block
common
.
Hash
,
gameWindow
time
.
Duration
,
sortBy
,
sortOrder
string
)
error
{
earliestTimestamp
:=
clock
.
MinCheckedTimestamp
(
clock
.
SystemClock
,
gameWindow
)
games
,
err
:=
factory
.
GetGamesAtOrAfter
(
ctx
,
block
,
earliestTimestamp
)
if
err
!=
nil
{
...
...
@@ -69,7 +95,7 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
}
slices
.
Reverse
(
games
)
infos
:=
make
([]
*
gameInfo
,
len
(
games
))
infos
:=
make
([]
gameInfo
,
len
(
games
))
var
wg
sync
.
WaitGroup
for
idx
,
game
:=
range
games
{
gameContract
,
err
:=
contracts
.
NewFaultDisputeGameContract
(
ctx
,
metrics
.
NoopContractMetrics
,
game
.
Proxy
,
caller
)
...
...
@@ -77,8 +103,9 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
return
fmt
.
Errorf
(
"failed to create dispute game contract: %w"
,
err
)
}
info
:=
gameInfo
{
GameMetadata
:
game
}
infos
[
idx
]
=
&
info
infos
[
idx
]
=
info
gameProxy
:=
game
.
Proxy
currIndex
:=
idx
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
...
...
@@ -87,20 +114,46 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
info
.
err
=
fmt
.
Errorf
(
"failed to retrieve metadata for game %v: %w"
,
gameProxy
,
err
)
return
}
info
.
status
=
status
info
.
l2BlockNum
=
l2BlockNum
info
.
rootClaim
=
rootClaim
info
s
[
currIndex
]
.
status
=
status
info
s
[
currIndex
]
.
l2BlockNum
=
l2BlockNum
info
s
[
currIndex
]
.
rootClaim
=
rootClaim
claimCount
,
err
:=
gameContract
.
GetClaimCount
(
ctx
)
if
err
!=
nil
{
info
.
err
=
fmt
.
Errorf
(
"failed to retrieve claim count for game %v: %w"
,
gameProxy
,
err
)
return
}
info
.
claimCount
=
claimCount
info
s
[
currIndex
]
.
claimCount
=
claimCount
}()
}
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"
)
// Sort infos by the specified column
switch
sortBy
{
case
"time"
:
slices
.
SortFunc
(
infos
,
func
(
i
,
j
gameInfo
)
int
{
if
sortOrder
==
"desc"
{
return
cmp
.
Compare
(
j
.
Timestamp
,
i
.
Timestamp
)
}
return
cmp
.
Compare
(
i
.
Timestamp
,
j
.
Timestamp
)
})
case
"claimCount"
:
slices
.
SortFunc
(
infos
,
func
(
i
,
j
gameInfo
)
int
{
if
sortOrder
==
"desc"
{
return
cmp
.
Compare
(
j
.
claimCount
,
i
.
claimCount
)
}
return
cmp
.
Compare
(
i
.
claimCount
,
j
.
claimCount
)
})
case
"l2BlockNum"
:
slices
.
SortFunc
(
infos
,
func
(
i
,
j
gameInfo
)
int
{
if
sortOrder
==
"desc"
{
return
cmp
.
Compare
(
j
.
l2BlockNum
,
i
.
l2BlockNum
)
}
return
cmp
.
Compare
(
i
.
l2BlockNum
,
j
.
l2BlockNum
)
})
}
for
_
,
game
:=
range
infos
{
if
game
.
err
!=
nil
{
return
game
.
err
...
...
@@ -114,6 +167,8 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
func
listGamesFlags
()
[]
cli
.
Flag
{
cliFlags
:=
[]
cli
.
Flag
{
SortByFlag
,
SortOrderFlag
,
flags
.
L1EthRpcFlag
,
flags
.
FactoryAddressFlag
,
flags
.
GameWindowFlag
,
...
...
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