From ee62cdf10a6fa3d39940bf17a0eba9f33a8f58a2 Mon Sep 17 00:00:00 2001 From: piersy Date: Wed, 3 Jul 2024 12:20:19 +0100 Subject: [PATCH] Fix migration script gap in migrated blocks (#189) * Fix migration script gap in migrated blocks The range of ancient blocks to remove from the non ancients database was off by one and resulted in a gap between ancients and non ancients. Also corrected some log statements that were off by one. --- op-chain-ops/cmd/celo-migrate/ancients.go | 2 +- op-chain-ops/cmd/celo-migrate/non-ancients.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/op-chain-ops/cmd/celo-migrate/ancients.go b/op-chain-ops/cmd/celo-migrate/ancients.go index b9e1fb975974..8ae9557871c4 100644 --- a/op-chain-ops/cmd/celo-migrate/ancients.go +++ b/op-chain-ops/cmd/celo-migrate/ancients.go @@ -50,7 +50,7 @@ func migrateAncientsDb(oldDBPath, newDBPath string, batchSize, bufferSize uint64 return numAncientsNewBefore, numAncientsNewBefore, nil } - log.Info("Ancient Block Migration Started", "process", "ancients", "startBlock", numAncientsNewBefore, "endBlock", numAncientsOld, "count", numAncientsOld-numAncientsNewBefore, "step", batchSize) + log.Info("Ancient Block Migration Started", "process", "ancients", "startBlock", numAncientsNewBefore, "endBlock", numAncientsOld-1, "count", numAncientsOld-numAncientsNewBefore, "step", batchSize) g, ctx := errgroup.WithContext(context.Background()) readChan := make(chan RLPBlockRange, bufferSize) diff --git a/op-chain-ops/cmd/celo-migrate/non-ancients.go b/op-chain-ops/cmd/celo-migrate/non-ancients.go index 2d2c1726ac18..0183f9059d5a 100644 --- a/op-chain-ops/cmd/celo-migrate/non-ancients.go +++ b/op-chain-ops/cmd/celo-migrate/non-ancients.go @@ -51,8 +51,9 @@ func migrateNonAncientsDb(oldDbPath, newDbPath string, numAncients, batchSize ui // get the last block number hash := rawdb.ReadHeadHeaderHash(newDB) lastBlock := *rawdb.ReadHeaderNumber(newDB, hash) + lastAncient := numAncients - 1 - log.Info("Non-Ancient Block Migration Started", "process", "non-ancients", "startBlock", numAncients, "endBlock", lastBlock, "count", lastBlock-numAncients, "lastAncientBlock", numAncients) + log.Info("Non-Ancient Block Migration Started", "process", "non-ancients", "startBlock", numAncients, "endBlock", lastBlock, "count", lastBlock-lastAncient, "lastAncientBlock", lastAncient) for i := numAncients; i <= lastBlock; i += batchSize { numbersHash := rawdb.ReadAllHashesInRange(newDB, i, i+batchSize-1) @@ -88,8 +89,8 @@ func migrateNonAncientsDb(oldDbPath, newDbPath string, numAncients, batchSize ui } } - if numAncients > 0 { - toBeRemoved := rawdb.ReadAllHashesInRange(newDB, 1, numAncients) + if lastAncient > 0 { + toBeRemoved := rawdb.ReadAllHashesInRange(newDB, 1, lastAncient) log.Info("Removing frozen blocks", "process", "non-ancients", "count", len(toBeRemoved)) batch := newDB.NewBatch() for _, numberHash := range toBeRemoved {