Commit bc1cad20 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: read l2 addrs from json file

There is now a new config flag for reading the L2Addresses
from disk. Note that the name L2Addresses should probably be
changed or migrated into the `DeployConfig` because now we
have overlapping sources of config.

There are deployment deps that would also need to be changed, so
doing the config change would require PRs across multiple repos.

The `sdk` tasks also consume a JSON file with addresses and this JSON
is different than that JSON which is not ideal.
parent f539a28b
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"errors"
"math/big" "math/big"
"os" "os"
"path/filepath" "path/filepath"
...@@ -12,7 +13,6 @@ import ( ...@@ -12,7 +13,6 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
op_state "github.com/ethereum-optimism/optimism/op-chain-ops/state" op_state "github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
...@@ -55,6 +55,10 @@ func main() { ...@@ -55,6 +55,10 @@ func main() {
Name: "evm-messages", Name: "evm-messages",
Usage: "Path to evm-messages.json", Usage: "Path to evm-messages.json",
}, },
&cli.StringFlag{
Name: "l2-addresses",
Usage: "Path to l2-addresses.json",
},
&cli.StringFlag{ &cli.StringFlag{
Name: "db-path", Name: "db-path",
Usage: "Path to database", Usage: "Path to database",
...@@ -104,6 +108,11 @@ func main() { ...@@ -104,6 +108,11 @@ func main() {
EvmMessages: evmMessages, EvmMessages: evmMessages,
} }
l2Addrs, err := genesis.NewL2Addresses(ctx.String("l2-addresses"))
if err != nil {
return err
}
l1RpcURL := ctx.String("l1-rpc-url") l1RpcURL := ctx.String("l1-rpc-url")
l1Client, err := ethclient.Dial(l1RpcURL) l1Client, err := ethclient.Dial(l1RpcURL)
if err != nil { if err != nil {
...@@ -142,15 +151,14 @@ func main() { ...@@ -142,15 +151,14 @@ func main() {
return err return err
} }
l2Addrs := genesis.L2Addresses{ // TODO: think about optimal config, there are a lot of deps
ProxyAdminOwner: config.ProxyAdminOwner, // regarding changing this
// TODO: these values are not in the config if config.ProxyAdminOwner != l2Addrs.ProxyAdminOwner {
L1StandardBridgeProxy: common.Address{}, return errors.New("mismatched ProxyAdminOwner config")
L1CrossDomainMessengerProxy: common.Address{},
L1ERC721BridgeProxy: common.Address{},
} }
if err := genesis.MigrateDB(wrappedDB, config, block, &l2Addrs, &migrationData); err != nil { if err := genesis.MigrateDB(wrappedDB, config, block, l2Addrs, &migrationData); err != nil {
return err return err
} }
......
package genesis package genesis
import ( import (
"encoding/json"
"fmt"
"os"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys" "github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/state" "github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -12,10 +16,25 @@ import ( ...@@ -12,10 +16,25 @@ import (
// L2Addresses represents L1 contract addresses // L2Addresses represents L1 contract addresses
// that are required for the construction of an L2 state // that are required for the construction of an L2 state
type L2Addresses struct { type L2Addresses struct {
ProxyAdminOwner common.Address ProxyAdminOwner common.Address `json:"proxyAdminOwner"`
L1StandardBridgeProxy common.Address L1StandardBridgeProxy common.Address `json:"l1StandardBridgeProxy"`
L1CrossDomainMessengerProxy common.Address L1CrossDomainMessengerProxy common.Address `json:"l1CrossDomainMessengerProxy"`
L1ERC721BridgeProxy common.Address L1ERC721BridgeProxy common.Address `json:"l1ERC721BridgeProxy"`
}
// NewL2Addresses will read the L2Addresses from a json file on disk
func NewL2Addresses(path string) (*L2Addresses, error) {
file, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("cannot find L2Addresses json at %s: %w", path, err)
}
var addrs L2Addresses
if err := json.Unmarshal(file, &addrs); err != nil {
return nil, err
}
return &addrs, nil
} }
// BuildL2DeveloperGenesis will build the developer Optimism Genesis // BuildL2DeveloperGenesis will build the developer Optimism Genesis
......
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