diff --git a/op-chain-ops/cmd/celo-migrate/main.go b/op-chain-ops/cmd/celo-migrate/main.go index bab69eb9b2857..b7d27791bc4b2 100644 --- a/op-chain-ops/cmd/celo-migrate/main.go +++ b/op-chain-ops/cmd/celo-migrate/main.go @@ -49,6 +49,10 @@ var ( Usage: "Path to write the rollup config JSON file, to be provided to op-node with the 'rollup.config' flag", Required: true, } + migrationBlockTimeFlag = &cli.Uint64Flag{ + Name: "migration-block-time", + Usage: "Specifies a unix timestamp to use for the migration block. If not provided, the current time will be used.", + } oldDBPathFlag = &cli.PathFlag{ Name: "old-db", Usage: "Path to the old Celo chaindata dir, can be found at '/celo/chaindata'", @@ -104,6 +108,7 @@ var ( l1RPCFlag, l2AllocsFlag, outfileRollupConfigFlag, + migrationBlockTimeFlag, } // Ignore onlyAncients flag and duplicate newDBPathFlag for full migration fullMigrationFlags = append(blockMigrationFlags[1:], stateMigrationFlags[1:]...) @@ -127,6 +132,7 @@ type stateMigrationOptions struct { l2AllocsPath string outfileRollupConfig string newDBPath string + migrationBlockTime uint64 } func parseBlockMigrationOptions(ctx *cli.Context) blockMigrationOptions { @@ -150,6 +156,7 @@ func parseStateMigrationOptions(ctx *cli.Context) stateMigrationOptions { l1RPC: ctx.String(l1RPCFlag.Name), l2AllocsPath: ctx.Path(l2AllocsFlag.Name), outfileRollupConfig: ctx.Path(outfileRollupConfigFlag.Name), + migrationBlockTime: ctx.Uint64(migrationBlockTimeFlag.Name), } } @@ -337,7 +344,7 @@ func runStateMigration(opts stateMigrationOptions) error { } // Write changes to state to actual state database - cel2Header, err := applyStateMigrationChanges(config, l2Genesis, opts.newDBPath) + cel2Header, err := applyStateMigrationChanges(config, l2Genesis, opts.newDBPath, opts.migrationBlockTime) if err != nil { return err } diff --git a/op-chain-ops/cmd/celo-migrate/state.go b/op-chain-ops/cmd/celo-migrate/state.go index 7511e45869e1c..67be76047d981 100644 --- a/op-chain-ops/cmd/celo-migrate/state.go +++ b/op-chain-ops/cmd/celo-migrate/state.go @@ -7,6 +7,7 @@ import ( "fmt" "math/big" "os" + "time" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-service/predeploys" @@ -50,7 +51,7 @@ var ( } ) -func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Genesis, dbPath string) (*types.Header, error) { +func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Genesis, dbPath string, migrationBlockTime uint64) (*types.Header, error) { log.Info("Opening Celo database", "dbPath", dbPath) ldb, err := openDB(dbPath) @@ -119,6 +120,10 @@ func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Gene baseFee = header.BaseFee } + if migrationBlockTime == 0 { + migrationBlockTime = uint64(time.Now().Unix()) + } + // Create the header for the Cel2 transition block. cel2Header := &types.Header{ ParentHash: header.Hash(), @@ -132,7 +137,7 @@ func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Gene Number: migrationBlock, GasLimit: header.GasLimit, GasUsed: 0, - Time: header.Time + 5, + Time: migrationBlockTime, Extra: []byte("CeL2 migration"), MixDigest: common.Hash{}, Nonce: types.BlockNonce{},