Skip to content

Commit

Permalink
Merge pull request #7856 from ethereum-optimism/extra-networks
Browse files Browse the repository at this point in the history
op-node: enable all network options by default
  • Loading branch information
trianglesphere authored Oct 30, 2023
2 parents 19fc020 + d75c85b commit 8a33c02
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 36 deletions.
5 changes: 2 additions & 3 deletions op-challenger/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -17,8 +16,8 @@ import (
var (
l1EthRpc = "http://example.com:8545"
gameFactoryAddressValue = "0xbb00000000000000000000000000000000000000"
cannonNetwork = chaincfg.AvailableNetworks()[0]
otherCannonNetwork = chaincfg.AvailableNetworks()[1]
cannonNetwork = "op-mainnet"
otherCannonNetwork = "op-goerli"
cannonBin = "./bin/cannon"
cannonServer = "./bin/op-program"
cannonPreState = "./pre.json"
Expand Down
23 changes: 1 addition & 22 deletions op-node/chaincfg/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,14 @@ var L2ChainIDToNetworkDisplayName = func() map[string]string {
}()

// AvailableNetworks returns the selection of network configurations that is available by default.
// Other configurations that are part of the superchain-registry can be used with the --beta.network flag.
func AvailableNetworks() []string {
return []string{"op-mainnet", "op-goerli", "op-sepolia"}
}

// BetaAvailableNetworks returns all available network configurations in the superchain-registry.
// This set of configurations is experimental, and may change at any time.
func BetaAvailableNetworks() []string {
var networks []string
for _, cfg := range superchain.OPChains {
networks = append(networks, cfg.Chain+"-"+cfg.Superchain)
}
return networks
}

func IsAvailableNetwork(name string, beta bool) bool {
name = handleLegacyName(name)
available := AvailableNetworks()
if beta {
available = BetaAvailableNetworks()
}
for _, v := range available {
if v == name {
return true
}
}
return false
}

func handleLegacyName(name string) string {
switch name {
case "goerli":
Expand Down Expand Up @@ -91,7 +70,7 @@ func ChainByName(name string) *superchain.ChainConfig {
func GetRollupConfig(name string) (*rollup.Config, error) {
chainCfg := ChainByName(name)
if chainCfg == nil {
return nil, fmt.Errorf("invalid network %s", name)
return nil, fmt.Errorf("invalid network: %q", name)
}
rollupCfg, err := rollup.LoadOPStackRollupConfig(chainCfg.ChainID)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions op-node/chaincfg/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func TestGetRollupConfig(t *testing.T) {
}

for name, expectedCfg := range configsByName {
require.True(t, IsAvailableNetwork(name, false))

gotCfg, err := GetRollupConfig(name)
require.NoError(t, err)

Expand Down
7 changes: 3 additions & 4 deletions op-node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,10 @@ var (
Value: false,
}
BetaExtraNetworks = &cli.BoolFlag{
Name: "beta.extra-networks",
Usage: fmt.Sprintf("Beta feature: enable selection of a predefined-network from the superchain-registry. "+
"The superchain-registry is experimental, and the availability of configurations may change."+
"Available networks: %s", strings.Join(chaincfg.BetaAvailableNetworks(), ", ")),
Name: "beta.extra-networks",
Usage: "Legacy flag, ignored, all superchain-registry networks are enabled by default.",
EnvVars: prefixEnvVars("BETA_EXTRA_NETWORKS"),
Hidden: true, // hidden, this is deprecated, the flag is not used anymore.
}
RollupHalt = &cli.StringFlag{
Name: "rollup.halt",
Expand Down
7 changes: 3 additions & 4 deletions op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,16 @@ func NewDriverConfig(ctx *cli.Context) *driver.Config {
func NewRollupConfig(log log.Logger, ctx *cli.Context) (*rollup.Config, error) {
network := ctx.String(flags.Network.Name)
rollupConfigPath := ctx.String(flags.RollupConfig.Name)
if ctx.Bool(flags.BetaExtraNetworks.Name) {
log.Warn("The beta.extra-networks flag is deprecated and can be omitted safely.")
}
if network != "" {
if rollupConfigPath != "" {
log.Error(`Cannot configure network and rollup-config at the same time.
Startup will proceed to use the network-parameter and ignore the rollup config.
Conflicting configuration is deprecated, and will stop the op-node from starting in the future.
`, "network", network, "rollup_config", rollupConfigPath)
}
// check that the network is available
if !chaincfg.IsAvailableNetwork(network, ctx.Bool(flags.BetaExtraNetworks.Name)) {
return nil, fmt.Errorf("unavailable network: %q", network)
}
config, err := chaincfg.GetRollupConfig(network)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion op-program/host/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestDefaultCLIOptionsMatchDefaultConfig(t *testing.T) {

func TestNetwork(t *testing.T) {
t.Run("Unknown", func(t *testing.T) {
verifyArgsInvalid(t, "unavailable network: \"bar\"", replaceRequiredArg("--network", "bar"))
verifyArgsInvalid(t, "invalid network: \"bar\"", replaceRequiredArg("--network", "bar"))
})

t.Run("Required", func(t *testing.T) {
Expand Down

0 comments on commit 8a33c02

Please sign in to comment.