Skip to content

Commit

Permalink
op-challenger: add l2-rpc flag and deprecate cannon-l2 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Apr 19, 2024
1 parent 9478fc7 commit a6d8361
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 70 deletions.
2 changes: 1 addition & 1 deletion docs/fault-proof-alpha/run-challenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ make op-challenger op-program cannon
--cannon-bin ./cannon/bin/cannon \
--cannon-server ./op-program/bin/op-program \
--cannon-prestate <PRESTATE> \
--cannon-l2 <L2_URL> \
--l2-rpc <L2_URL> \
--private-key <PRIVATE_KEY>
```

Expand Down
2 changes: 1 addition & 1 deletion op-challenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ DISPUTE_GAME_FACTORY=$(jq -r .DisputeGameFactoryProxy .devnet/addresses.json)
--cannon-bin ./cannon/bin/cannon \
--cannon-server ./op-program/bin/op-program \
--cannon-prestate ./op-program/bin/prestate.json \
--cannon-l2 http://localhost:9545 \
--l2-rpc http://localhost:9545 \
--mnemonic "test test test test test test test test test test test junk" \
--hd-path "m/44'/60'/0'/0/8" \
--num-confirmations 1
Expand Down
45 changes: 33 additions & 12 deletions op-challenger/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ var (
gameFactoryAddressValue = "0xbb00000000000000000000000000000000000000"
cannonNetwork = "op-mainnet"
testNetwork = "op-sepolia"
l2Rpc = "http://example.com:9545"
cannonBin = "./bin/cannon"
cannonServer = "./bin/op-program"
cannonPreState = "./pre.json"
datadir = "./test_data"
cannonL2 = "http://example.com:9545"
rollupRpc = "http://example.com:8555"
asteriscNetwork = "op-mainnet"
asteriscBin = "./bin/asterisc"
asteriscServer = "./bin/op-program"
asteriscPreState = "./pre.json"
asteriscL2 = "http://example.com:9545"
)

func TestLogLevel(t *testing.T) {
Expand Down Expand Up @@ -300,18 +299,31 @@ func TestAsteriscRequiredArgs(t *testing.T) {
})
})

t.Run(fmt.Sprintf("TestAsteriscL2-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("TestL2Rpc-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTraceLegacy", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--cannon-l2"))
})

t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-l2"))
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--l2-rpc"))
})

t.Run("RequiredForAsteriscTrace", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-l2 is required", addRequiredArgsExcept(traceType, "--asterisc-l2"))
verifyArgsInvalid(t, "flag l2-rpc is required", addRequiredArgsExcept(traceType, "--l2-rpc"))
})

t.Run("ValidLegacy", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--l2-rpc", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, asteriscL2, cfg.AsteriscL2)
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("InvalidUsingBothFlags", func(t *testing.T) {
verifyArgsInvalid(t, "flag cannon-l2 and l2-rpc must not be both set", addRequiredArgsExcept(traceType, "", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
})
})

Expand Down Expand Up @@ -459,18 +471,27 @@ func TestCannonRequiredArgs(t *testing.T) {
})
})

t.Run(fmt.Sprintf("TestCannonL2-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
t.Run(fmt.Sprintf("TestL2Rpc-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTraceLegacy", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--cannon-l2"))
})

t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--l2-rpc"))
})

t.Run("RequiredForCannonTrace", func(t *testing.T) {
verifyArgsInvalid(t, "flag cannon-l2 is required", addRequiredArgsExcept(traceType, "--cannon-l2"))
verifyArgsInvalid(t, "flag l2-rpc is required", addRequiredArgsExcept(traceType, "--l2-rpc"))
})

t.Run("ValidLegacy", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--l2-rpc", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, cannonL2, cfg.CannonL2)
require.Equal(t, l2Rpc, cfg.L2Rpc)
})
})

Expand Down Expand Up @@ -741,7 +762,7 @@ func addRequiredCannonArgs(args map[string]string) {
args["--cannon-bin"] = cannonBin
args["--cannon-server"] = cannonServer
args["--cannon-prestate"] = cannonPreState
args["--cannon-l2"] = cannonL2
args["--l2-rpc"] = l2Rpc
addRequiredOutputArgs(args)
}

Expand All @@ -750,7 +771,7 @@ func addRequiredAsteriscArgs(args map[string]string) {
args["--asterisc-bin"] = asteriscBin
args["--asterisc-server"] = asteriscServer
args["--asterisc-prestate"] = asteriscPreState
args["--asterisc-l2"] = asteriscL2
args["--l2-rpc"] = l2Rpc
addRequiredOutputArgs(args)
}

Expand Down
23 changes: 11 additions & 12 deletions op-challenger/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
ErrMissingTraceType = errors.New("no supported trace types specified")
ErrMissingDatadir = errors.New("missing datadir")
ErrMaxConcurrencyZero = errors.New("max concurrency must not be 0")
ErrMissingCannonL2 = errors.New("missing cannon L2")
ErrMissingL2Rpc = errors.New("missing L2 rpc url")
ErrMissingCannonBin = errors.New("missing cannon bin")
ErrMissingCannonServer = errors.New("missing cannon server")
ErrMissingCannonAbsolutePreState = errors.New("missing cannon absolute pre-state")
Expand All @@ -35,7 +35,6 @@ var (
ErrCannonNetworkUnknown = errors.New("unknown cannon network")
ErrMissingRollupRpc = errors.New("missing rollup rpc url")

ErrMissingAsteriscL2 = errors.New("missing asterisc L2")
ErrMissingAsteriscBin = errors.New("missing asterisc bin")
ErrMissingAsteriscServer = errors.New("missing asterisc server")
ErrMissingAsteriscAbsolutePreState = errors.New("missing asterisc absolute pre-state")
Expand Down Expand Up @@ -122,16 +121,17 @@ type Config struct {

RollupRpc string // L2 Rollup RPC Url

L2Rpc string // L2 RPC Url

// Specific to the cannon trace provider
CannonBin string // Path to the cannon executable to run when generating trace data
CannonServer string // Path to the op-program executable that provides the pre-image oracle server
CannonAbsolutePreState string // File to load the absolute pre-state for Cannon traces from
CannonNetwork string
CannonRollupConfigPath string
CannonL2GenesisPath string
CannonL2 string // L2 RPC Url
CannonSnapshotFreq uint // Frequency of snapshots to create when executing cannon (in VM instructions)
CannonInfoFreq uint // Frequency of cannon progress log messages (in VM instructions)
CannonSnapshotFreq uint // Frequency of snapshots to create when executing cannon (in VM instructions)
CannonInfoFreq uint // Frequency of cannon progress log messages (in VM instructions)

// Specific to the asterisc trace provider
AsteriscBin string // Path to the asterisc executable to run when generating trace data
Expand All @@ -140,9 +140,8 @@ type Config struct {
AsteriscNetwork string
AsteriscRollupConfigPath string
AsteriscL2GenesisPath string
AsteriscL2 string // L2 RPC Url
AsteriscSnapshotFreq uint // Frequency of snapshots to create when executing asterisc (in VM instructions)
AsteriscInfoFreq uint // Frequency of asterisc progress log messages (in VM instructions)
AsteriscSnapshotFreq uint // Frequency of snapshots to create when executing asterisc (in VM instructions)
AsteriscInfoFreq uint // Frequency of asterisc progress log messages (in VM instructions)

MaxPendingTx uint64 // Maximum number of pending transactions (0 == no limit)

Expand Down Expand Up @@ -237,8 +236,8 @@ func (c Config) Check() error {
if c.CannonAbsolutePreState == "" {
return ErrMissingCannonAbsolutePreState
}
if c.CannonL2 == "" {
return ErrMissingCannonL2
if c.L2Rpc == "" {
return ErrMissingL2Rpc
}
if c.CannonSnapshotFreq == 0 {
return ErrMissingCannonSnapshotFreq
Expand Down Expand Up @@ -275,8 +274,8 @@ func (c Config) Check() error {
if c.AsteriscAbsolutePreState == "" {
return ErrMissingAsteriscAbsolutePreState
}
if c.AsteriscL2 == "" {
return ErrMissingAsteriscL2
if c.L2Rpc == "" {
return ErrMissingL2Rpc
}
if c.AsteriscSnapshotFreq == 0 {
return ErrMissingAsteriscSnapshotFreq
Expand Down
30 changes: 12 additions & 18 deletions op-challenger/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ var (
validCannonNetwork = "mainnet"
validCannonAbsolutPreState = "pre.json"
validDatadir = "/tmp/data"
validCannonL2 = "http://localhost:9545"
validL2Rpc = "http://localhost:9545"
validRollupRpc = "http://localhost:8555"

validAsteriscBin = "./bin/asterisc"
validAsteriscOpProgramBin = "./bin/op-program"
validAsteriscNetwork = "mainnet"
validAsteriscAbsolutPreState = "pre.json"
validAsteriscL2 = "http://localhost:9545"
)

var cannonTraceTypes = []TraceType{TraceTypeCannon, TraceTypePermissioned}
Expand All @@ -36,16 +35,16 @@ func applyValidConfigForCannon(cfg *Config) {
cfg.CannonBin = validCannonBin
cfg.CannonServer = validCannonOpProgramBin
cfg.CannonAbsolutePreState = validCannonAbsolutPreState
cfg.CannonL2 = validCannonL2
cfg.CannonNetwork = validCannonNetwork
cfg.L2Rpc = validL2Rpc
}

func applyValidConfigForAsterisc(cfg *Config) {
cfg.AsteriscBin = validAsteriscBin
cfg.AsteriscServer = validAsteriscOpProgramBin
cfg.AsteriscAbsolutePreState = validAsteriscAbsolutPreState
cfg.AsteriscL2 = validAsteriscL2
cfg.AsteriscNetwork = validAsteriscNetwork
cfg.L2Rpc = validL2Rpc
}

func validConfig(traceType TraceType) Config {
Expand Down Expand Up @@ -131,10 +130,10 @@ func TestCannonRequiredArgs(t *testing.T) {
require.ErrorIs(t, config.Check(), ErrMissingCannonAbsolutePreState)
})

t.Run(fmt.Sprintf("TestCannonL2Required-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("TestL2RpcRequired-%v", traceType), func(t *testing.T) {
config := validConfig(traceType)
config.CannonL2 = ""
require.ErrorIs(t, config.Check(), ErrMissingCannonL2)
config.L2Rpc = ""
require.ErrorIs(t, config.Check(), ErrMissingL2Rpc)
})

t.Run(fmt.Sprintf("TestCannonSnapshotFreq-%v", traceType), func(t *testing.T) {
Expand Down Expand Up @@ -238,9 +237,9 @@ func TestRequireConfigForMultipleTraceTypesForCannon(t *testing.T) {
require.NoError(t, cfg.Check())

// Require cannon specific args
cfg.CannonL2 = ""
require.ErrorIs(t, cfg.Check(), ErrMissingCannonL2)
cfg.CannonL2 = validCannonL2
cfg.CannonAbsolutePreState = ""
require.ErrorIs(t, cfg.Check(), ErrMissingCannonAbsolutePreState)
cfg.CannonAbsolutePreState = validCannonAbsolutPreState

// Require output cannon specific args
cfg.RollupRpc = ""
Expand All @@ -255,9 +254,9 @@ func TestRequireConfigForMultipleTraceTypesForAsterisc(t *testing.T) {
require.NoError(t, cfg.Check())

// Require asterisc specific args
cfg.AsteriscL2 = ""
require.ErrorIs(t, cfg.Check(), ErrMissingAsteriscL2)
cfg.AsteriscL2 = validAsteriscL2
cfg.AsteriscAbsolutePreState = ""
require.ErrorIs(t, cfg.Check(), ErrMissingAsteriscAbsolutePreState)
cfg.AsteriscAbsolutePreState = validAsteriscAbsolutPreState

// Require output asterisc specific args
cfg.RollupRpc = ""
Expand All @@ -273,11 +272,6 @@ func TestRequireConfigForMultipleTraceTypesForCannonAndAsterisc(t *testing.T) {
cfg.RollupRpc = validRollupRpc
require.NoError(t, cfg.Check())

// Require asterisc specific args
cfg.AsteriscL2 = ""
require.ErrorIs(t, cfg.Check(), ErrMissingAsteriscL2)
cfg.AsteriscL2 = validAsteriscL2

// Require cannon specific args
cfg.CannonBin = ""
require.ErrorIs(t, cfg.Check(), ErrMissingCannonBin)
Expand Down
Loading

0 comments on commit a6d8361

Please sign in to comment.