Commit fa0915f5 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

op-chain-ops: move top level stuff to ether package (#3743)

Moves the previously top level files to a new
package called `ether` that is responsible for
doing the legacy eth migration.

The OVM_ETH ERC20 token representation of ETH
will be migrated to actual ETH that is in the
storage trie.

This makes the system eth equiavalent.
parent 35499637
surgery: surgery:
go build -o ./surgery ./cmd/main.go go build -o ./surgery ./cmd/surgery/main.go
test: test:
go test ./... go test ./...
......
package main
import (
"os"
"strings"
ops "github.com/ethereum-optimism/optimism/op-chain-ops"
"github.com/ethereum/go-ethereum/log"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
)
func main() {
log.Root().SetHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(isatty.IsTerminal(os.Stderr.Fd()))))
app := &cli.App{
Name: "surgery",
Usage: "migrates data from v0 to Bedrock",
Commands: []*cli.Command{
{
Name: "dump-addresses",
Usage: "dumps addresses from OVM ETH",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "out-file",
Aliases: []string{"o"},
Usage: "file to write addresses to",
Required: true,
},
},
Action: dumpAddressesAction,
},
{
Name: "migrate",
Usage: "migrates state in OVM ETH",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "genesis-file",
Aliases: []string{"g"},
Usage: "path to a genesis file",
Required: true,
},
&cli.StringFlag{
Name: "out-dir",
Aliases: []string{"o"},
Usage: "path to output directory",
Required: true,
},
&cli.StringFlag{
Name: "address-lists",
Aliases: []string{"a"},
Usage: "comma-separated list of address files to read",
Required: true,
},
&cli.StringFlag{
Name: "allowance-lists",
Aliases: []string{"l"},
Usage: "comma-separated list of allowance lists to read",
Required: true,
},
&cli.IntFlag{
Name: "chain-id",
Usage: "chain ID",
Value: 1,
Required: false,
},
&cli.IntFlag{
Name: "leveldb-cache-size-mb",
Usage: "leveldb cache size in MB",
Value: 16,
Required: false,
},
&cli.IntFlag{
Name: "leveldb-file-handles",
Usage: "leveldb file handles",
Value: 16,
Required: false,
},
},
Action: migrateAction,
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "data-dir",
Aliases: []string{"d"},
Usage: "data directory to read",
Required: true,
},
},
}
if err := app.Run(os.Args); err != nil {
log.Crit("error in migration", "err", err)
}
}
func dumpAddressesAction(cliCtx *cli.Context) error {
dataDir := cliCtx.String("data-dir")
outFile := cliCtx.String("out-file")
return ops.DumpAddresses(dataDir, outFile)
}
func migrateAction(cliCtx *cli.Context) error {
dataDir := cliCtx.String("data-dir")
outDir := cliCtx.String("out-dir")
genesisPath := cliCtx.String("genesis-file")
addressLists := strings.Split(cliCtx.String("address-lists"), ",")
allowanceLists := strings.Split(cliCtx.String("allowance-lists"), ",")
chainID := cliCtx.Int("chain-id")
levelDBCacheSize := cliCtx.Int("leveldb-cache-size-mb")
levelDBHandles := cliCtx.Int("leveldb-file-handles")
genesis, err := ops.ReadGenesisFromFile(genesisPath)
if err != nil {
return err
}
return ops.Migrate(dataDir, outDir, genesis, addressLists, allowanceLists, chainID, levelDBCacheSize, levelDBHandles)
}
package state_surgery package ether
import ( import (
"bufio" "bufio"
......
package state_surgery package ether
import ( import (
"bytes" "bytes"
......
package state_surgery package ether
import ( import (
"path/filepath" "path/filepath"
......
package state_surgery package ether
import ( import (
"encoding/json" "encoding/json"
......
package state_surgery package ether
import ( import (
"math/big" "math/big"
......
package state_surgery package ether
import ( import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
......
package state_surgery package ether
import ( import (
"fmt" "fmt"
......
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