From 85ac7c905b30d983b2280347af55627028999b5c Mon Sep 17 00:00:00 2001 From: alecps Date: Wed, 5 Mar 2025 16:44:00 -0500 Subject: [PATCH 1/2] add runDbCheckFromLastMigrated --- op-chain-ops/cmd/celo-migrate/main.go | 43 ++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/op-chain-ops/cmd/celo-migrate/main.go b/op-chain-ops/cmd/celo-migrate/main.go index 9c56fa1387c6..ee8eb3de5463 100644 --- a/op-chain-ops/cmd/celo-migrate/main.go +++ b/op-chain-ops/cmd/celo-migrate/main.go @@ -110,6 +110,11 @@ var ( Usage: "Path to the db to perform a continuity check on", Required: true, } + dbCheckStartFlag = &cli.Uint64Flag{ + Name: "start", + Usage: "Block number to start the db check from. If not set, the db check will start from block 0.", + Value: 0, + } dbCheckFailFastFlag = &cli.BoolFlag{ Name: "fail-fast", Usage: "Fail fast on the first error encountered. If set, the db check will stop on the first error encountered, otherwise it will continue to check all blocks and print out all errors at the end.", @@ -169,6 +174,7 @@ type fullMigrationOptions struct { type dbCheckOptions struct { dbPath string + start uint64 batchSize uint64 failFast bool } @@ -209,6 +215,7 @@ func parseDBCheckOptions(ctx *cli.Context) dbCheckOptions { dbPath: ctx.String(dbCheckPathFlag.Name), batchSize: ctx.Uint64(batchSizeFlag.Name), failFast: ctx.Bool(dbCheckFailFastFlag.Name), + start: ctx.Uint64(dbCheckStartFlag.Name), } } @@ -333,6 +340,11 @@ func runPreMigration(opts preMigrationOptions) ([]*rawdb.NumberHash, uint64, err } } + err = runDBCheckFromLastMigrated(opts) + if err != nil { + return nil, 0, fmt.Errorf("failed to run db check from last migrated block: %w", err) + } + var numAncientsNewBefore uint64 var numAncientsNewAfter uint64 var strayAncientBlocks []*rawdb.NumberHash @@ -618,7 +630,7 @@ func runDBCheck(opts dbCheckOptions) (err error) { } log.Info("Checking continuity of ancient blocks", "start", 0, "end", lastAncientNumber, "count", lastAncientNumber+1) - if err := checkContinuity(0, lastAncientNumber, func(start, count uint64) (*RLPBlockRange, error) { + if err := checkContinuity(opts.start, lastAncientNumber, func(start, count uint64) (*RLPBlockRange, error) { return loadAncientRange(ancientDB, start, count) }); err != nil { return err @@ -643,6 +655,35 @@ func runDBCheck(opts dbCheckOptions) (err error) { return nil } +func runDBCheckFromLastMigrated(opts preMigrationOptions) (err error) { + newFreezer, err := NewChainFreezer(filepath.Join(opts.newDBPath, "ancient"), "", false) + if err != nil { + return fmt.Errorf("failed to open new freezer: %w", err) + } + numAncientsInNewDB, err := newFreezer.Ancients() + if err != nil { + return fmt.Errorf("failed to get number of ancients in new freezer: %w", err) + } + err = newFreezer.Close() + if err != nil { + return fmt.Errorf("failed to close new freezer: %w", err) + } + + var start uint64 + if numAncientsInNewDB == 0 { + start = 0 + } else { + start = numAncientsInNewDB - 1 + } + + err = runDBCheck(dbCheckOptions{dbPath: opts.oldDBPath, start: start, batchSize: opts.batchSize, failFast: true}) + if err != nil { + return fmt.Errorf("failed to run db continuity check: %w", err) + } + + return nil +} + func timer(name string) func() { start := time.Now() return func() { From 4cf83d3bf16c5860852cc9805c913d17542f4977 Mon Sep 17 00:00:00 2001 From: alecps Date: Thu, 6 Mar 2025 10:14:44 -0500 Subject: [PATCH 2/2] small logging fix --- op-chain-ops/cmd/celo-migrate/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op-chain-ops/cmd/celo-migrate/main.go b/op-chain-ops/cmd/celo-migrate/main.go index ee8eb3de5463..689e7163647d 100644 --- a/op-chain-ops/cmd/celo-migrate/main.go +++ b/op-chain-ops/cmd/celo-migrate/main.go @@ -629,7 +629,7 @@ func runDBCheck(opts dbCheckOptions) (err error) { return nil } - log.Info("Checking continuity of ancient blocks", "start", 0, "end", lastAncientNumber, "count", lastAncientNumber+1) + log.Info("Checking continuity of ancient blocks", "start", opts.start, "end", lastAncientNumber, "count", lastAncientNumber-opts.start+1) if err := checkContinuity(opts.start, lastAncientNumber, func(start, count uint64) (*RLPBlockRange, error) { return loadAncientRange(ancientDB, start, count) }); err != nil {