Commit 6c825478 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: more cleanup in migrate script

The `op-migrate` script had some leftover stuff
in it from early iterations on its development.
The leftover stuff was cleaned up to improve the
overall UX of the script. Now code should not need
to be commented out + rebuild the binary, it will
automatically detect when the script has already
ran on a datadir.

Also pass through the no check arg so that we can
re-enable the checking and dynamically change if
we want to run the data validation as part of the
migration.
parent c6932d70
package crossdomain
import (
"errors"
"fmt"
"math/big"
......@@ -13,26 +14,23 @@ import (
)
var (
abiTrue = common.Hash{31: 0x01}
//errLegacyStorageSlotNotFound = errors.New("cannot find storage slot")
abiTrue = common.Hash{31: 0x01}
errLegacyStorageSlotNotFound = errors.New("cannot find storage slot")
)
// MigrateWithdrawals will migrate a list of pending withdrawals given a StateDB.
func MigrateWithdrawals(withdrawals []*LegacyWithdrawal, db vm.StateDB, l1CrossDomainMessenger *common.Address) error {
func MigrateWithdrawals(withdrawals []*LegacyWithdrawal, db vm.StateDB, l1CrossDomainMessenger *common.Address, noCheck bool) error {
for i, legacy := range withdrawals {
legacySlot, err := legacy.StorageSlot()
if err != nil {
return err
}
legacyValue := db.GetState(predeploys.LegacyMessagePasserAddr, legacySlot)
if legacyValue != abiTrue {
// TODO: Re-enable this once we have the exact data we need on mainnet.
// This is disabled because the data file we're using for testing was
// generated after the database dump, which means that there are extra
// storage slots in the state that don't show up in the withdrawals list.
// return fmt.Errorf("%w: %s", errLegacyStorageSlotNotFound, legacySlot)
continue
if !noCheck {
legacyValue := db.GetState(predeploys.LegacyMessagePasserAddr, legacySlot)
if legacyValue != abiTrue {
return fmt.Errorf("%w: %s", errLegacyStorageSlotNotFound, legacySlot)
}
}
withdrawal, err := MigrateWithdrawal(legacy, l1CrossDomainMessenger)
......
package genesis
import (
"bytes"
"fmt"
"math/big"
......@@ -19,7 +20,10 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
var abiTrue = common.Hash{31: 0x01}
var (
abiTrue = common.Hash{31: 0x01}
bedrockTransitionBlockExtraData = []byte("BEDROCK")
)
type MigrationResult struct {
TransitionHeight uint64
......@@ -33,13 +37,15 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
num := rawdb.ReadHeaderNumber(ldb, hash)
header := rawdb.ReadHeader(ldb, hash, *num)
// Leaving this commented out so that it can be used to skip
// the DB migration in development.
//return &MigrationResult{
// TransitionHeight: *num,
// TransitionTimestamp: header.Time,
// TransitionBlockHash: hash,
//}, nil
if bytes.Equal(header.Extra, bedrockTransitionBlockExtraData) {
log.Info("Detected migration already happened", "root", header.Root, "blockhash", header.Hash())
return &MigrationResult{
TransitionHeight: *num,
TransitionTimestamp: header.Time,
TransitionBlockHash: hash,
}, nil
}
underlyingDB := state.NewDatabaseWithConfig(ldb, &trie.Config{
Preimages: true,
......@@ -86,8 +92,8 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
return nil, fmt.Errorf("cannot set implementations: %w", err)
}
log.Info("Starting to migrate withdrawals")
err = crossdomain.MigrateWithdrawals(withdrawals, db, &config.L1CrossDomainMessengerProxy)
log.Info("Starting to migrate withdrawals", "no-check", noCheck)
err = crossdomain.MigrateWithdrawals(withdrawals, db, &config.L1CrossDomainMessengerProxy, noCheck)
if err != nil {
return nil, fmt.Errorf("cannot migrate withdrawals: %w", err)
}
......@@ -96,11 +102,10 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
log.Info("Starting to migrate ERC20 ETH")
addrs := migrationData.Addresses()
newRoot, err := ether.MigrateLegacyETH(ldb, addrs, migrationData.OvmAllowances, int(config.L1ChainID), commit)
log.Info("Completed ERC20 ETH migration")
if err != nil {
return nil, fmt.Errorf("cannot migrate legacy eth: %w", err)
}
log.Info("Completed ERC20 ETH migration", "root", newRoot)
// Create the bedrock transition block
bedrockHeader := &types.Header{
......@@ -116,7 +121,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
GasLimit: (uint64)(config.L2GenesisBlockGasLimit),
GasUsed: 0,
Time: uint64(config.L2OutputOracleStartingTimestamp),
Extra: []byte("BEDROCK"),
Extra: bedrockTransitionBlockExtraData,
MixDigest: common.Hash{},
Nonce: types.BlockNonce{},
BaseFee: (*big.Int)(config.L2GenesisBlockBaseFeePerGas),
......
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