Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-challenger: Migrate config over to supporting multiple L2s #13833

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions op-challenger/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func TestGameFactoryAddress(t *testing.T) {
verifyArgsInvalid(t, "flag game-factory-address or network is required", addRequiredArgsExcept(types.TraceTypeAlphabet, "--game-factory-address"))
})

t.Run("RequiredWhenMultipleNetworksSupplied", func(t *testing.T) {
verifyArgsInvalid(t, "flag game-factory-address required when multiple networks specified", addRequiredArgsExcept(types.TraceTypeAlphabet, "--game-factory-address", "--network", "op-sepolia,op-mainnet"))
})

t.Run("Valid", func(t *testing.T) {
addr := common.Address{0xbb, 0xcc, 0xdd}
cfg := configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--game-factory-address", "--game-factory-address="+addr.Hex()))
Expand Down Expand Up @@ -205,7 +209,7 @@ func TestNetwork(t *testing.T) {
addr := common.Address{0xbb, 0xcc, 0xdd}
cfg := configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--game-factory-address", "--network=1234", "--game-factory-address="+addr.Hex()))
require.Equal(t, addr, cfg.GameFactoryAddress)
require.Equal(t, "1234", cfg.Cannon.Network)
require.Equal(t, []string{"1234"}, cfg.Cannon.Networks)
})
}

Expand Down Expand Up @@ -473,7 +477,7 @@ func TestAsteriscBaseRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, l2EthRpc, cfg.L2Rpc)
require.Equal(t, []string{l2EthRpc}, cfg.L2Rpcs)
})
})

Expand Down Expand Up @@ -549,12 +553,12 @@ func TestAsteriscBaseRequiredArgs(t *testing.T) {
delete(args, "--game-factory-address")
args["--network"] = "op-sepolia"
cfg := configForArgs(t, toArgList(args))
require.Equal(t, "op-sepolia", cfg.Asterisc.Network)
require.Equal(t, []string{"op-sepolia"}, cfg.Asterisc.Networks)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--network", testNetwork))
require.Equal(t, testNetwork, cfg.Asterisc.Network)
require.Equal(t, []string{testNetwork}, cfg.Asterisc.Networks)
})
})

Expand All @@ -565,7 +569,7 @@ func TestAsteriscBaseRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--rollup-config=rollup.json", "--l2-genesis=genesis.json"))
require.Equal(t, "rollup.json", cfg.Asterisc.RollupConfigPath)
require.Equal(t, []string{"rollup.json"}, cfg.Asterisc.RollupConfigPaths)
})
})

Expand All @@ -576,7 +580,7 @@ func TestAsteriscBaseRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--rollup-config=rollup.json", "--l2-genesis=genesis.json"))
require.Equal(t, "genesis.json", cfg.Asterisc.L2GenesisPath)
require.Equal(t, []string{"genesis.json"}, cfg.Asterisc.L2GenesisPaths)
})
})
}
Expand All @@ -590,7 +594,7 @@ func TestAlphabetRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(types.TraceTypeAlphabet))
require.Equal(t, l2EthRpc, cfg.L2Rpc)
require.Equal(t, []string{l2EthRpc}, cfg.L2Rpcs)
})
})
}
Expand Down Expand Up @@ -694,7 +698,7 @@ func TestCannonRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, l2EthRpc, cfg.L2Rpc)
require.Equal(t, []string{l2EthRpc}, cfg.L2Rpcs)
})
})

Expand Down Expand Up @@ -776,7 +780,7 @@ func TestCannonRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--network", testNetwork))
require.Equal(t, testNetwork, cfg.Cannon.Network)
require.Equal(t, []string{testNetwork}, cfg.Cannon.Networks)
})
})

Expand All @@ -795,7 +799,7 @@ func TestCannonRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--cannon-rollup-config=rollup.json", "--cannon-l2-genesis=genesis.json"))
require.Equal(t, "rollup.json", cfg.Cannon.RollupConfigPath)
require.Equal(t, []string{"rollup.json"}, cfg.Cannon.RollupConfigPaths)
})
})

Expand All @@ -806,7 +810,7 @@ func TestCannonRequiredArgs(t *testing.T) {

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--network", "--cannon-rollup-config=rollup.json", "--cannon-l2-genesis=genesis.json"))
require.Equal(t, "genesis.json", cfg.Cannon.L2GenesisPath)
require.Equal(t, []string{"genesis.json"}, cfg.Cannon.L2GenesisPaths)
})
})
}
Expand Down
16 changes: 8 additions & 8 deletions op-challenger/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ type Config struct {

TraceTypes []types.TraceType // Type of traces supported

RollupRpc string // L2 Rollup RPC Url
SupervisorRPC string // L2 supervisor RPC URL
L2Rpc string // L2 RPC Url
RollupRpc string // L2 Rollup RPC Url
SupervisorRPC string // L2 supervisor RPC URL
L2Rpcs []string // L2 RPC Url

// Specific to the cannon trace provider
Cannon vm.Config
Expand Down Expand Up @@ -112,7 +112,7 @@ func NewConfig(
L1EthRpc: l1EthRpc,
L1Beacon: l1BeaconApi,
RollupRpc: l2RollupRpc,
L2Rpc: l2EthRpc,
L2Rpcs: []string{l2EthRpc},
GameFactoryAddress: gameFactoryAddress,
MaxConcurrency: uint(runtime.NumCPU()),
PollInterval: DefaultPollInterval,
Expand All @@ -131,7 +131,7 @@ func NewConfig(
VmType: types.TraceTypeCannon,
L1: l1EthRpc,
L1Beacon: l1BeaconApi,
L2: l2EthRpc,
L2s: []string{l2EthRpc},
SnapshotFreq: DefaultCannonSnapshotFreq,
InfoFreq: DefaultCannonInfoFreq,
DebugInfo: true,
Expand All @@ -141,7 +141,7 @@ func NewConfig(
VmType: types.TraceTypeAsterisc,
L1: l1EthRpc,
L1Beacon: l1BeaconApi,
L2: l2EthRpc,
L2s: []string{l2EthRpc},
SnapshotFreq: DefaultAsteriscSnapshotFreq,
InfoFreq: DefaultAsteriscInfoFreq,
BinarySnapshots: true,
Expand All @@ -150,7 +150,7 @@ func NewConfig(
VmType: types.TraceTypeAsteriscKona,
L1: l1EthRpc,
L1Beacon: l1BeaconApi,
L2: l2EthRpc,
L2s: []string{l2EthRpc},
SnapshotFreq: DefaultAsteriscSnapshotFreq,
InfoFreq: DefaultAsteriscInfoFreq,
BinarySnapshots: true,
Expand All @@ -170,7 +170,7 @@ func (c Config) Check() error {
if c.L1Beacon == "" {
return ErrMissingL1Beacon
}
if c.L2Rpc == "" {
if len(c.L2Rpcs) == 0 {
return ErrMissingL2Rpc
}
if c.GameFactoryAddress == (common.Address{}) {
Expand Down
112 changes: 44 additions & 68 deletions op-challenger/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func applyValidConfigForCannon(t *testing.T, cfg *Config) {
cfg.Cannon.VmBin = vmBin
cfg.Cannon.Server = server
cfg.CannonAbsolutePreStateBaseURL = validCannonAbsolutePreStateBaseURL
cfg.Cannon.Network = validCannonNetwork
cfg.Cannon.Networks = []string{validCannonNetwork}
}

func applyValidConfigForAsterisc(t *testing.T, cfg *Config) {
Expand All @@ -94,7 +94,7 @@ func applyValidConfigForAsterisc(t *testing.T, cfg *Config) {
cfg.Asterisc.VmBin = vmBin
cfg.Asterisc.Server = server
cfg.AsteriscAbsolutePreStateBaseURL = validAsteriscAbsolutePreStateBaseURL
cfg.Asterisc.Network = validAsteriscNetwork
cfg.Asterisc.Networks = []string{validAsteriscNetwork}
}

func applyValidConfigForAsteriscKona(t *testing.T, cfg *Config) {
Expand All @@ -108,7 +108,7 @@ func applyValidConfigForAsteriscKona(t *testing.T, cfg *Config) {
cfg.AsteriscKona.VmBin = vmBin
cfg.AsteriscKona.Server = server
cfg.AsteriscKonaAbsolutePreStateBaseURL = validAsteriscKonaAbsolutePreStateBaseURL
cfg.AsteriscKona.Network = validAsteriscKonaNetwork
cfg.AsteriscKona.Networks = []string{validAsteriscKonaNetwork}
}

func validConfig(t *testing.T, traceType types.TraceType) Config {
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestCannonRequiredArgs(t *testing.T) {

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

Expand All @@ -246,51 +246,43 @@ func TestCannonRequiredArgs(t *testing.T) {

t.Run(fmt.Sprintf("TestCannonNetworkOrRollupConfigRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = ""
cfg.Cannon.RollupConfigPath = ""
cfg.Cannon.L2GenesisPath = "genesis.json"
cfg.Cannon.Networks = nil
cfg.Cannon.RollupConfigPaths = nil
cfg.Cannon.L2GenesisPaths = []string{"genesis.json"}
require.ErrorIs(t, cfg.Check(), vm.ErrMissingRollupConfig)
})

t.Run(fmt.Sprintf("TestCannonNetworkOrL2GenesisRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = ""
cfg.Cannon.RollupConfigPath = "foo.json"
cfg.Cannon.L2GenesisPath = ""
cfg.Cannon.Networks = nil
cfg.Cannon.RollupConfigPaths = []string{"foo.json"}
cfg.Cannon.L2GenesisPaths = nil
require.ErrorIs(t, cfg.Check(), vm.ErrMissingL2Genesis)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndRollup-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("TestMaySpecifyNetworkAndCustomConfigs-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = validCannonNetwork
cfg.Cannon.RollupConfigPath = "foo.json"
cfg.Cannon.L2GenesisPath = ""
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndRollupConfig)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndL2Genesis-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = validCannonNetwork
cfg.Cannon.RollupConfigPath = ""
cfg.Cannon.L2GenesisPath = "foo.json"
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndL2Genesis)
cfg.Cannon.Networks = []string{validCannonNetwork}
cfg.Cannon.RollupConfigPaths = []string{"foo.json"}
cfg.Cannon.L2GenesisPaths = []string{"genesis.json"}
require.NoError(t, cfg.Check())
})

t.Run(fmt.Sprintf("TestNetworkMustBeValid-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = "unknown"
cfg.Cannon.Networks = []string{"unknown"}
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkUnknown)
})

t.Run(fmt.Sprintf("TestNetworkMayBeAnyChainID-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = "467294"
cfg.Cannon.Networks = []string{"467294"}
require.NoError(t, cfg.Check())
})

t.Run(fmt.Sprintf("TestNetworkInvalidWhenNotEntirelyNumeric-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Cannon.Network = "467294a"
cfg.Cannon.Networks = []string{"467294a"}
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkUnknown)
})

Expand Down Expand Up @@ -360,7 +352,7 @@ func TestAsteriscRequiredArgs(t *testing.T) {

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

Expand All @@ -382,39 +374,31 @@ func TestAsteriscRequiredArgs(t *testing.T) {

t.Run(fmt.Sprintf("TestAsteriscNetworkOrRollupConfigRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Asterisc.Network = ""
cfg.Asterisc.RollupConfigPath = ""
cfg.Asterisc.L2GenesisPath = "genesis.json"
cfg.Asterisc.Networks = nil
cfg.Asterisc.RollupConfigPaths = nil
cfg.Asterisc.L2GenesisPaths = []string{"genesis.json"}
require.ErrorIs(t, cfg.Check(), vm.ErrMissingRollupConfig)
})

t.Run(fmt.Sprintf("TestAsteriscNetworkOrL2GenesisRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Asterisc.Network = ""
cfg.Asterisc.RollupConfigPath = "foo.json"
cfg.Asterisc.L2GenesisPath = ""
cfg.Asterisc.Networks = nil
cfg.Asterisc.RollupConfigPaths = []string{"foo.json"}
cfg.Asterisc.L2GenesisPaths = nil
require.ErrorIs(t, cfg.Check(), vm.ErrMissingL2Genesis)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndRollup-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Asterisc.Network = validAsteriscNetwork
cfg.Asterisc.RollupConfigPath = "foo.json"
cfg.Asterisc.L2GenesisPath = ""
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndRollupConfig)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndL2Genesis-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("MaySpecifyNetworkAndCustomConfigs-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Asterisc.Network = validAsteriscNetwork
cfg.Asterisc.RollupConfigPath = ""
cfg.Asterisc.L2GenesisPath = "foo.json"
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndL2Genesis)
cfg.Asterisc.Networks = []string{validAsteriscNetwork}
cfg.Asterisc.RollupConfigPaths = []string{"foo.json"}
cfg.Asterisc.L2GenesisPaths = []string{"genesis.json"}
require.NoError(t, cfg.Check())
})

t.Run(fmt.Sprintf("TestNetworkMustBeValid-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.Asterisc.Network = "unknown"
cfg.Asterisc.Networks = []string{"unknown"}
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkUnknown)
})

Expand Down Expand Up @@ -484,7 +468,7 @@ func TestAsteriscKonaRequiredArgs(t *testing.T) {

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

Expand All @@ -506,39 +490,31 @@ func TestAsteriscKonaRequiredArgs(t *testing.T) {

t.Run(fmt.Sprintf("TestAsteriscKonaNetworkOrRollupConfigRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.AsteriscKona.Network = ""
cfg.AsteriscKona.RollupConfigPath = ""
cfg.AsteriscKona.L2GenesisPath = "genesis.json"
cfg.AsteriscKona.Networks = nil
cfg.AsteriscKona.RollupConfigPaths = nil
cfg.AsteriscKona.L2GenesisPaths = []string{"genesis.json"}
require.ErrorIs(t, cfg.Check(), vm.ErrMissingRollupConfig)
})

t.Run(fmt.Sprintf("TestAsteriscKonaNetworkOrL2GenesisRequired-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.AsteriscKona.Network = ""
cfg.AsteriscKona.RollupConfigPath = "foo.json"
cfg.AsteriscKona.L2GenesisPath = ""
cfg.AsteriscKona.Networks = nil
cfg.AsteriscKona.RollupConfigPaths = []string{"foo.json"}
cfg.AsteriscKona.L2GenesisPaths = nil
require.ErrorIs(t, cfg.Check(), vm.ErrMissingL2Genesis)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndRollup-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.AsteriscKona.Network = validAsteriscKonaNetwork
cfg.AsteriscKona.RollupConfigPath = "foo.json"
cfg.AsteriscKona.L2GenesisPath = ""
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndRollupConfig)
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndL2Genesis-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("MaySpecifyNetworkAndCustomConfig-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.AsteriscKona.Network = validAsteriscKonaNetwork
cfg.AsteriscKona.RollupConfigPath = ""
cfg.AsteriscKona.L2GenesisPath = "foo.json"
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkAndL2Genesis)
cfg.AsteriscKona.Networks = []string{validAsteriscKonaNetwork}
cfg.AsteriscKona.RollupConfigPaths = []string{"foo.json"}
cfg.AsteriscKona.L2GenesisPaths = []string{"genesis.json"}
require.NoError(t, cfg.Check())
})

t.Run(fmt.Sprintf("TestNetworkMustBeValid-%v", traceType), func(t *testing.T) {
cfg := validConfig(t, traceType)
cfg.AsteriscKona.Network = "unknown"
cfg.AsteriscKona.Networks = []string{"unknown"}
require.ErrorIs(t, cfg.Check(), vm.ErrNetworkUnknown)
})

Expand Down
Loading