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