Commit 0196cf74 authored by George C. Knee's avatar George C. Knee Committed by GitHub

`op-chain-ops`: invert lookup from chainID to superchain (#9203)

* fix: replace d->name lookup with name->id lookup

There can be (and are) more than one superchain with a given id. Conversely, each superchain will have exactly one id.

* refactor: update op-upgrade given previous commit

* refactor: update op-version-check to use upgrades.SuperChainI

Closes #9292

* chore: check err condition separately

* Update op-chain-ops/upgrades/check.go
Co-authored-by: default avatarcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* refactor: remove  SuperChainID

we can get this information from the superchain registry

* chore: prevent panic if superchain name not registered

---------
Co-authored-by: default avatarcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
parent d48b4595
...@@ -79,11 +79,16 @@ func entrypoint(ctx *cli.Context) error { ...@@ -79,11 +79,16 @@ func entrypoint(ctx *cli.Context) error {
} }
superchainName := ctx.String("superchain-target") superchainName := ctx.String("superchain-target")
if superchainName == "" { sc, ok := superchain.Superchains[superchainName]
superchainName, err = upgrades.ToSuperchainName(l1ChainID.Uint64()) if !ok {
if err != nil { return fmt.Errorf("superchain name %s not registered", superchainName)
return err
} }
declaredChainID := sc.Config.L1.ChainID
if declaredChainID != l1ChainID.Uint64() {
return fmt.Errorf("superchain %s has chainID %d, but the l1-rpc-url returned a chainId of %d",
superchainName, declaredChainID, l1ChainID.Uint64())
} }
chainIDs := ctx.Uint64Slice("chain-ids") chainIDs := ctx.Uint64Slice("chain-ids")
......
...@@ -105,12 +105,14 @@ func entrypoint(ctx *cli.Context) error { ...@@ -105,12 +105,14 @@ func entrypoint(ctx *cli.Context) error {
return fmt.Errorf("cannot fetch L1 chain ID: %w", err) return fmt.Errorf("cannot fetch L1 chain ID: %w", err)
} }
superchainName, err := upgrades.ToSuperchainName(l1ChainID.Uint64()) sc, ok := superchain.Superchains[chainConfig.Superchain]
if err != nil { if !ok {
return fmt.Errorf("error getting superchain name: %w", err) return fmt.Errorf("superchain name %s not registered", chainConfig.Superchain)
} }
if superchainName != chainConfig.Superchain { declaredL1ChainID := sc.Config.L1.ChainID
if l1ChainID.Uint64() != declaredL1ChainID {
// L2 corresponds to a different superchain than L1, skip // L2 corresponds to a different superchain than L1, skip
log.Info("Ignoring L1/L2", "l1-chain-id", l1ChainID, "l2-chain-id", l2ChainID) log.Info("Ignoring L1/L2", "l1-chain-id", l1ChainID, "l2-chain-id", l2ChainID)
continue continue
......
...@@ -122,17 +122,3 @@ func cmpVersion(v1, v2 string) bool { ...@@ -122,17 +122,3 @@ func cmpVersion(v1, v2 string) bool {
} }
return v1 == v2 return v1 == v2
} }
// ToSuperchainName turns a base layer chain id into a superchain network name.
func ToSuperchainName(chainID uint64) (string, error) {
if chainID == 1 {
return "mainnet", nil
}
if chainID == 5 {
return "goerli", nil
}
if chainID == 11155111 {
return "sepolia", nil
}
return "", fmt.Errorf("unsupported chain ID %d", chainID)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment