Commit af9a5eed authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4118 from ethereum-optimism/fix/migrate-cleanup-2

op-chain-ops: more cleanup in migrate script
parents 3694de47 6c825478
package crossdomain
import (
"errors"
"fmt"
"math/big"
......@@ -14,25 +15,22 @@ import (
var (
abiTrue = common.Hash{31: 0x01}
//errLegacyStorageSlotNotFound = errors.New("cannot find storage slot")
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
}
if !noCheck {
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
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