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

Merge pull request #4105 from ethereum-optimism/fix/chain-ops-cleanup

op-chain-ops: various cleanup
parents c1e7f122 9e02ddbd
...@@ -76,6 +76,10 @@ func main() { ...@@ -76,6 +76,10 @@ func main() {
Name: "dry-run", Name: "dry-run",
Usage: "Dry run the upgrade by not committing the database", Usage: "Dry run the upgrade by not committing the database",
}, },
cli.BoolFlag{
Name: "no-check",
Usage: "Do not perform sanity checks. This should only be used for testing",
},
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
deployConfig := ctx.String("deploy-config") deployConfig := ctx.String("deploy-config")
...@@ -153,7 +157,8 @@ func main() { ...@@ -153,7 +157,8 @@ func main() {
} }
dryRun := ctx.Bool("dry-run") dryRun := ctx.Bool("dry-run")
if _, err := genesis.MigrateDB(ldb, config, block, &migrationData, !dryRun); err != nil { noCheck := ctx.Bool("no-check")
if _, err := genesis.MigrateDB(ldb, config, block, &migrationData, !dryRun, noCheck); err != nil {
return err return err
} }
......
...@@ -40,7 +40,7 @@ func NewLegacyWithdrawal(target, sender *common.Address, data []byte, nonce *big ...@@ -40,7 +40,7 @@ func NewLegacyWithdrawal(target, sender *common.Address, data []byte, nonce *big
func (w *LegacyWithdrawal) Encode() ([]byte, error) { func (w *LegacyWithdrawal) Encode() ([]byte, error) {
enc, err := EncodeCrossDomainMessageV0(w.Target, w.Sender, w.Data, w.Nonce) enc, err := EncodeCrossDomainMessageV0(w.Target, w.Sender, w.Data, w.Nonce)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot encode LegacyWithdrawal: %w", err)
} }
out := make([]byte, len(enc)+len(predeploys.L2CrossDomainMessengerAddr.Bytes())) out := make([]byte, len(enc)+len(predeploys.L2CrossDomainMessengerAddr.Bytes()))
...@@ -108,7 +108,7 @@ func (w *LegacyWithdrawal) Decode(data []byte) error { ...@@ -108,7 +108,7 @@ func (w *LegacyWithdrawal) Decode(data []byte) error {
func (w *LegacyWithdrawal) Hash() (common.Hash, error) { func (w *LegacyWithdrawal) Hash() (common.Hash, error) {
encoded, err := w.Encode() encoded, err := w.Encode()
if err != nil { if err != nil {
return common.Hash{}, nil return common.Hash{}, fmt.Errorf("cannot hash LegacyWithdrawal: %w", err)
} }
hash := crypto.Keccak256(encoded) hash := crypto.Keccak256(encoded)
return common.BytesToHash(hash), nil return common.BytesToHash(hash), nil
...@@ -119,7 +119,7 @@ func (w *LegacyWithdrawal) Hash() (common.Hash, error) { ...@@ -119,7 +119,7 @@ func (w *LegacyWithdrawal) Hash() (common.Hash, error) {
func (w *LegacyWithdrawal) StorageSlot() (common.Hash, error) { func (w *LegacyWithdrawal) StorageSlot() (common.Hash, error) {
hash, err := w.Hash() hash, err := w.Hash()
if err != nil { if err != nil {
return common.Hash{}, err return common.Hash{}, fmt.Errorf("cannot compute storage slot: %w", err)
} }
preimage := make([]byte, 64) preimage := make([]byte, 64)
copy(preimage, hash.Bytes()) copy(preimage, hash.Bytes())
......
...@@ -28,7 +28,7 @@ type MigrationResult struct { ...@@ -28,7 +28,7 @@ type MigrationResult struct {
} }
// MigrateDB will migrate an old l2geth database to the new bedrock style system // MigrateDB will migrate an old l2geth database to the new bedrock style system
func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, migrationData *migration.MigrationData, commit bool) (*MigrationResult, error) { func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, migrationData *migration.MigrationData, commit, noCheck bool) (*MigrationResult, error) {
hash := rawdb.ReadHeadHeaderHash(ldb) hash := rawdb.ReadHeadHeaderHash(ldb)
num := rawdb.ReadHeaderNumber(ldb, hash) num := rawdb.ReadHeaderNumber(ldb, hash)
header := rawdb.ReadHeader(ldb, hash, *num) header := rawdb.ReadHeader(ldb, hash, *num)
...@@ -56,11 +56,18 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m ...@@ -56,11 +56,18 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
return nil, fmt.Errorf("cannot serialize withdrawals: %w", err) return nil, fmt.Errorf("cannot serialize withdrawals: %w", err)
} }
if err := CheckWithdrawals(db, withdrawals); err != nil { if !noCheck {
return nil, fmt.Errorf("withdrawals mismatch: %w", err) log.Info("Checking withdrawals...")
if err := CheckWithdrawals(db, withdrawals); err != nil {
return nil, fmt.Errorf("withdrawals mismatch: %w", err)
}
log.Info("Withdrawals accounted for!")
} else {
log.Info("Skipping checking withdrawals")
} }
// Now start the migration // Now start the migration
log.Info("Setting the Proxies")
if err := SetL2Proxies(db); err != nil { if err := SetL2Proxies(db); err != nil {
return nil, fmt.Errorf("cannot set L2Proxies: %w", err) return nil, fmt.Errorf("cannot set L2Proxies: %w", err)
} }
...@@ -181,7 +188,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal ...@@ -181,7 +188,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal
for _, wd := range withdrawals { for _, wd := range withdrawals {
slot, err := wd.StorageSlot() slot, err := wd.StorageSlot()
if err != nil { if err != nil {
return err return fmt.Errorf("cannot check withdrawals: %w", err)
} }
knownSlots[slot] = true knownSlots[slot] = true
} }
...@@ -195,7 +202,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal ...@@ -195,7 +202,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal
return true return true
}) })
if err != nil { if err != nil {
return err return fmt.Errorf("cannot iterate over LegacyMessagePasser: %w", err)
} }
// Check that all of the slots from storage correspond to a known message // Check that all of the slots from storage correspond to a known message
...@@ -211,7 +218,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal ...@@ -211,7 +218,7 @@ func CheckWithdrawals(db vm.StateDB, withdrawals []*crossdomain.LegacyWithdrawal
_, ok := slots[slot] _, ok := slots[slot]
//nolint:staticcheck //nolint:staticcheck
if !ok { if !ok {
//return nil, fmt.Errorf("Unknown input message: %s", slot) return fmt.Errorf("Unknown input message: %s", slot)
} }
} }
......
...@@ -24,6 +24,7 @@ type Config struct { ...@@ -24,6 +24,7 @@ type Config struct {
StartingL1BlockNumber uint64 StartingL1BlockNumber uint64
L2DBPath string L2DBPath string
DryRun bool DryRun bool
NoCheck bool
} }
func Migrate(cfg *Config) (*genesis.MigrationResult, error) { func Migrate(cfg *Config) (*genesis.MigrationResult, error) {
...@@ -81,5 +82,5 @@ func Migrate(cfg *Config) (*genesis.MigrationResult, error) { ...@@ -81,5 +82,5 @@ func Migrate(cfg *Config) (*genesis.MigrationResult, error) {
} }
defer ldb.Close() defer ldb.Close()
return genesis.MigrateDB(ldb, deployConfig, block, &migrationData, !cfg.DryRun) return genesis.MigrateDB(ldb, deployConfig, block, &migrationData, !cfg.DryRun, cfg.NoCheck)
} }
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