Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion op-chain-ops/cmd/celo-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<datadir>/celo/chaindata'",
Expand Down Expand Up @@ -104,6 +108,7 @@ var (
l1RPCFlag,
l2AllocsFlag,
outfileRollupConfigFlag,
migrationBlockTimeFlag,
}
// Ignore onlyAncients flag and duplicate newDBPathFlag for full migration
fullMigrationFlags = append(blockMigrationFlags[1:], stateMigrationFlags[1:]...)
Expand All @@ -127,6 +132,7 @@ type stateMigrationOptions struct {
l2AllocsPath string
outfileRollupConfig string
newDBPath string
migrationBlockTime uint64
}

func parseBlockMigrationOptions(ctx *cli.Context) blockMigrationOptions {
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions op-chain-ops/cmd/celo-migrate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand All @@ -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{},
Expand Down