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
ee33ff83
Unverified
Commit
ee33ff83
authored
Jul 25, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Add config and CLI args to support actually executing cannon
parent
3891726b
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
215 additions
and
65 deletions
+215
-65
main_test.go
op-challenger/cmd/main_test.go
+105
-29
config.go
op-challenger/config/config.go
+32
-15
config_test.go
op-challenger/config/config_test.go
+45
-18
flags.go
op-challenger/flags/flags.go
+33
-3
No files found.
op-challenger/cmd/main_test.go
View file @
ee33ff83
This diff is collapsed.
Click to expand it.
op-challenger/config/config.go
View file @
ee33ff83
...
...
@@ -9,11 +9,14 @@ import (
)
var
(
ErrMissingTraceType
=
errors
.
New
(
"missing trace type"
)
ErrMissingCannonDatadir
=
errors
.
New
(
"missing cannon datadir"
)
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
ErrMissingTraceType
=
errors
.
New
(
"missing trace type"
)
ErrMissingCannonDatadir
=
errors
.
New
(
"missing cannon datadir"
)
ErrMissingCannonL2
=
errors
.
New
(
"missing cannon L2"
)
ErrMissingCannonBin
=
errors
.
New
(
"missing cannon bin"
)
ErrMissingCannonAbsolutePreState
=
errors
.
New
(
"missing cannon absolute pre-state"
)
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
)
type
TraceType
string
...
...
@@ -56,9 +59,16 @@ type Config struct {
AgreeWithProposedOutput
bool
// Temporary config if we agree or disagree with the posted output
GameDepth
int
// Depth of the game tree
TraceType
TraceType
// Type of trace
AlphabetTrace
string
// String for the AlphabetTraceProvider
CannonDatadir
string
// Cannon Data Directory for the CannonTraceProvider
TraceType
TraceType
// Type of trace
// Specific to the alphabet trace provider
AlphabetTrace
string
// String for the AlphabetTraceProvider
// Specific to the cannon trace provider
CannonBin
string
// Path to the cannon executable to run when generating trace data
CannonAbsolutePreState
string
// File to load the absolute pre-state for Cannon traces from
CannonDatadir
string
// Cannon Data Directory
CannonL2
string
// L2 RPC Url
TxMgrConfig
txmgr
.
CLIConfig
}
...
...
@@ -67,8 +77,6 @@ func NewConfig(
l1EthRpc
string
,
gameAddress
common
.
Address
,
traceType
TraceType
,
alphabetTrace
string
,
cannonDatadir
string
,
agreeWithProposedOutput
bool
,
gameDepth
int
,
)
Config
{
...
...
@@ -79,9 +87,7 @@ func NewConfig(
AgreeWithProposedOutput
:
agreeWithProposedOutput
,
GameDepth
:
gameDepth
,
TraceType
:
traceType
,
AlphabetTrace
:
alphabetTrace
,
CannonDatadir
:
cannonDatadir
,
TraceType
:
traceType
,
TxMgrConfig
:
txmgr
.
NewCLIConfig
(
l1EthRpc
),
}
...
...
@@ -97,8 +103,19 @@ func (c Config) Check() error {
if
c
.
TraceType
==
""
{
return
ErrMissingTraceType
}
if
c
.
TraceType
==
TraceTypeCannon
&&
c
.
CannonDatadir
==
""
{
return
ErrMissingCannonDatadir
if
c
.
TraceType
==
TraceTypeCannon
{
if
c
.
CannonBin
==
""
{
return
ErrMissingCannonBin
}
if
c
.
CannonAbsolutePreState
==
""
{
return
ErrMissingCannonAbsolutePreState
}
if
c
.
CannonDatadir
==
""
{
return
ErrMissingCannonDatadir
}
if
c
.
CannonL2
==
""
{
return
ErrMissingCannonL2
}
}
if
c
.
TraceType
==
TraceTypeAlphabet
&&
c
.
AlphabetTrace
==
""
{
return
ErrMissingAlphabetTrace
...
...
op-challenger/config/config_test.go
View file @
ee33ff83
...
...
@@ -9,23 +9,40 @@ import (
)
var
(
validL1EthRpc
=
"http://localhost:8545"
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validAlphabetTrace
=
"abcdefgh"
validCannonDatadir
=
"/tmp/cannon"
agreeWithProposedOutput
=
true
gameDepth
=
4
validL1EthRpc
=
"http://localhost:8545"
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validAlphabetTrace
=
"abcdefgh"
validCannonBin
=
"./bin/cannon"
validCannonAbsolutPreState
=
"pre.json"
validCannonDatadir
=
"/tmp/cannon"
validCannonL2
=
"http://localhost:9545"
agreeWithProposedOutput
=
true
gameDepth
=
4
)
func
validConfig
(
traceType
TraceType
)
Config
{
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
traceType
,
validAlphabetTrace
,
validCannonDatadir
,
agreeWithProposedOutput
,
gameDepth
)
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
traceType
,
agreeWithProposedOutput
,
gameDepth
)
switch
traceType
{
case
TraceTypeAlphabet
:
cfg
.
AlphabetTrace
=
validAlphabetTrace
case
TraceTypeCannon
:
cfg
.
CannonBin
=
validCannonBin
cfg
.
CannonAbsolutePreState
=
validCannonAbsolutPreState
cfg
.
CannonDatadir
=
validCannonDatadir
cfg
.
CannonL2
=
validCannonL2
}
return
cfg
}
// TestValidConfigIsValid checks that the config provided by validConfig is actually valid
func
TestValidConfigIsValid
(
t
*
testing
.
T
)
{
err
:=
validConfig
(
TraceTypeCannon
)
.
Check
()
require
.
NoError
(
t
,
err
)
for
_
,
traceType
:=
range
TraceTypes
{
traceType
:=
traceType
t
.
Run
(
traceType
.
String
(),
func
(
t
*
testing
.
T
)
{
err
:=
validConfig
(
traceType
)
.
Check
()
require
.
NoError
(
t
,
err
)
})
}
}
func
TestTxMgrConfig
(
t
*
testing
.
T
)
{
...
...
@@ -40,30 +57,40 @@ func TestL1EthRpcRequired(t *testing.T) {
config
:=
validConfig
(
TraceTypeCannon
)
config
.
L1EthRpc
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingL1EthRPC
)
config
.
L1EthRpc
=
validL1EthRpc
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestGameAddressRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
GameAddress
=
common
.
Address
{}
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingGameAddress
)
config
.
GameAddress
=
validGameAddress
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestAlphabetTraceRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeAlphabet
)
config
.
AlphabetTrace
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingAlphabetTrace
)
config
.
AlphabetTrace
=
validAlphabetTrace
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestCannonTraceRequired
(
t
*
testing
.
T
)
{
func
TestCannonBinRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonBin
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonBin
)
}
func
TestCannonAbsolutePreStateRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonAbsolutePreState
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonAbsolutePreState
)
}
func
TestCannonDatadirRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonDatadir
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonDatadir
)
config
.
CannonDatadir
=
validCannonDatadir
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestCannonL2Required
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonL2
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonL2
)
}
op-challenger/flags/flags.go
View file @
ee33ff83
...
...
@@ -55,14 +55,29 @@ var (
// Optional Flags
AlphabetFlag
=
&
cli
.
StringFlag
{
Name
:
"alphabet"
,
Usage
:
"
Alphabet Trace (temporar
y)"
,
Usage
:
"
Correct Alphabet Trace (alphabet trace type onl
y)"
,
EnvVars
:
prefixEnvVars
(
"ALPHABET"
),
}
CannonBinFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-bin"
,
Usage
:
"Path to cannon executable to use when generating trace data (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_BIN"
),
}
CannonPreStateFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-prestate"
,
Usage
:
"Path to absolute prestate to use when generating trace data (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_PRESTATE"
),
}
CannonDatadirFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-datadir"
,
Usage
:
"
Cannon Data Directory
"
,
Usage
:
"
Directory to store data generated by cannon (cannon trace type only)
"
,
EnvVars
:
prefixEnvVars
(
"CANNON_DATADIR"
),
}
CannonL2Flag
=
&
cli
.
StringFlag
{
Name
:
"cannon-l2"
,
Usage
:
"L2 Address of L2 JSON-RPC endpoint to use (eth and debug namespace required) (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_L2"
),
}
)
// requiredFlags are checked by [CheckRequired]
...
...
@@ -77,7 +92,10 @@ var requiredFlags = []cli.Flag{
// optionalFlags is a list of unchecked cli flags
var
optionalFlags
=
[]
cli
.
Flag
{
AlphabetFlag
,
CannonBinFlag
,
CannonPreStateFlag
,
CannonDatadirFlag
,
CannonL2Flag
,
}
func
init
()
{
...
...
@@ -99,8 +117,17 @@ func CheckRequired(ctx *cli.Context) error {
gameType
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
switch
gameType
{
case
config
.
TraceTypeCannon
:
if
!
ctx
.
IsSet
(
CannonBinFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonBinFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonPreStateFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonPreStateFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonDatadirFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
"cannon-datadir"
)
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonDatadirFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonL2Flag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonL2Flag
.
Name
)
}
case
config
.
TraceTypeAlphabet
:
if
!
ctx
.
IsSet
(
AlphabetFlag
.
Name
)
{
...
...
@@ -132,7 +159,10 @@ func NewConfigFromCLI(ctx *cli.Context) (*config.Config, error) {
TraceType
:
traceTypeFlag
,
GameAddress
:
dgfAddress
,
AlphabetTrace
:
ctx
.
String
(
AlphabetFlag
.
Name
),
CannonBin
:
ctx
.
String
(
CannonBinFlag
.
Name
),
CannonAbsolutePreState
:
ctx
.
String
(
CannonPreStateFlag
.
Name
),
CannonDatadir
:
ctx
.
String
(
CannonDatadirFlag
.
Name
),
CannonL2
:
ctx
.
String
(
CannonL2Flag
.
Name
),
AgreeWithProposedOutput
:
ctx
.
Bool
(
AgreeWithProposedOutputFlag
.
Name
),
GameDepth
:
ctx
.
Int
(
GameDepthFlag
.
Name
),
TxMgrConfig
:
txMgrConfig
,
...
...
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