Commit 4c09d293 authored by Mark Tyneway's avatar Mark Tyneway

op-migrate: automatically create op-node config

parent 0be4c1c3
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/json"
"math/big" "math/big"
"os" "os"
"path/filepath" "path/filepath"
...@@ -90,6 +91,11 @@ func main() { ...@@ -90,6 +91,11 @@ func main() {
Usage: "LevelDB number of handles", Usage: "LevelDB number of handles",
Value: 60, Value: 60,
}, },
cli.StringFlag{
Name: "rollup-config-out",
Usage: "Path that op-node config will be written to disk",
Value: "rollup.json",
},
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
deployConfig := ctx.String("deploy-config") deployConfig := ctx.String("deploy-config")
...@@ -171,7 +177,17 @@ func main() { ...@@ -171,7 +177,17 @@ func main() {
dryRun := ctx.Bool("dry-run") dryRun := ctx.Bool("dry-run")
noCheck := ctx.Bool("no-check") noCheck := ctx.Bool("no-check")
if _, err := genesis.MigrateDB(ldb, config, block, &migrationData, !dryRun, noCheck); err != nil { res, err := genesis.MigrateDB(ldb, config, block, &migrationData, !dryRun, noCheck)
if err != nil {
return err
}
opNodeConfig, err := config.RollupConfig(block, res.TransitionBlockHash)
if err != nil {
return err
}
if err := writeJSON(ctx.String("rollup-config-out"), opNodeConfig); err != nil {
return err return err
} }
...@@ -183,3 +199,15 @@ func main() { ...@@ -183,3 +199,15 @@ func main() {
log.Crit("error in migration", "err", err) log.Crit("error in migration", "err", err)
} }
} }
func writeJSON(outfile string, input interface{}) error {
f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
return enc.Encode(input)
}
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -270,8 +269,9 @@ func (d *DeployConfig) InitDeveloperDeployedAddresses() error { ...@@ -270,8 +269,9 @@ func (d *DeployConfig) InitDeveloperDeployedAddresses() error {
return nil return nil
} }
// TODO: convert the input to this function
// RollupConfig converts a DeployConfig to a rollup.Config // RollupConfig converts a DeployConfig to a rollup.Config
func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2Genesis *core.Genesis) (*rollup.Config, error) { func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash) (*rollup.Config, error) {
if d.OptimismPortalProxy == (common.Address{}) { if d.OptimismPortalProxy == (common.Address{}) {
return nil, errors.New("OptimismPortalProxy cannot be address(0)") return nil, errors.New("OptimismPortalProxy cannot be address(0)")
} }
...@@ -286,7 +286,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2Genesis *core.G ...@@ -286,7 +286,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2Genesis *core.G
Number: l1StartBlock.NumberU64(), Number: l1StartBlock.NumberU64(),
}, },
L2: eth.BlockID{ L2: eth.BlockID{
Hash: l2Genesis.ToBlock().Hash(), Hash: l2GenesisBlockHash,
Number: 0, Number: 0,
}, },
L2Time: l1StartBlock.Time(), L2Time: l1StartBlock.Time(),
......
...@@ -67,7 +67,7 @@ var Subcommands = cli.Commands{ ...@@ -67,7 +67,7 @@ var Subcommands = cli.Commands{
return err return err
} }
rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis) rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis.ToBlock().Hash())
if err != nil { if err != nil {
return err return err
} }
...@@ -155,7 +155,7 @@ var Subcommands = cli.Commands{ ...@@ -155,7 +155,7 @@ var Subcommands = cli.Commands{
return fmt.Errorf("error creating l2 developer genesis: %w", err) return fmt.Errorf("error creating l2 developer genesis: %w", err)
} }
rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis) rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis.ToBlock().Hash())
if err != nil { if err != nil {
return err return err
} }
......
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