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
import (
"context"
"encoding/json"
"math/big"
"os"
"path/filepath"
......@@ -90,6 +91,11 @@ func main() {
Usage: "LevelDB number of handles",
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 {
deployConfig := ctx.String("deploy-config")
......@@ -171,7 +177,17 @@ func main() {
dryRun := ctx.Bool("dry-run")
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
}
......@@ -183,3 +199,15 @@ func main() {
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 (
"github.com/ethereum/go-ethereum/common"
"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/log"
"github.com/ethereum/go-ethereum/rpc"
......@@ -270,8 +269,9 @@ func (d *DeployConfig) InitDeveloperDeployedAddresses() error {
return nil
}
// TODO: convert the input to this function
// 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{}) {
return nil, errors.New("OptimismPortalProxy cannot be address(0)")
}
......@@ -286,7 +286,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2Genesis *core.G
Number: l1StartBlock.NumberU64(),
},
L2: eth.BlockID{
Hash: l2Genesis.ToBlock().Hash(),
Hash: l2GenesisBlockHash,
Number: 0,
},
L2Time: l1StartBlock.Time(),
......
......@@ -67,7 +67,7 @@ var Subcommands = cli.Commands{
return err
}
rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis)
rollupConfig, err := config.RollupConfig(l1StartBlock, l2Genesis.ToBlock().Hash())
if err != nil {
return err
}
......@@ -155,7 +155,7 @@ var Subcommands = cli.Commands{
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 {
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