Skip to content

Commit 884a3aa

Browse files
committed
Fix boundaries for migration
1 parent 59aad94 commit 884a3aa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

cmd/migrate_valid.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func RunValidationMigration(cmd *cobra.Command, args []string) {
5555

5656
// Calculate work distribution for workers
5757
numWorkers := DEFAULT_WORKERS
58+
if config.Cfg.Migrator.WorkerCount > 0 {
59+
numWorkers = int(config.Cfg.Migrator.WorkerCount)
60+
}
5861
workRanges := divideBlockRange(rangeStartBlock, rangeEndBlock, numWorkers)
5962
log.Info().Msgf("Starting %d workers to process migration", len(workRanges))
6063

@@ -376,7 +379,9 @@ func (m *Migrator) DetermineMigrationBoundaries(targetStartBlock, targetEndBlock
376379
}
377380

378381
log.Info().Msgf("Block in the target storage for range %s to %s: count=%s, max=%s", startBlock.String(), endBlock.String(), blockCount.String(), maxStoredBlock.String())
379-
if maxStoredBlock != nil && maxStoredBlock.Cmp(startBlock) >= 0 {
382+
// Only adjust start block if we actually have blocks stored (count > 0)
383+
// When count is 0, maxStoredBlock might be 0 but that doesn't mean block 0 exists
384+
if blockCount.Sign() > 0 && maxStoredBlock != nil && maxStoredBlock.Cmp(startBlock) >= 0 {
380385
startBlock = new(big.Int).Add(maxStoredBlock, big.NewInt(1))
381386
}
382387

@@ -411,7 +416,9 @@ func (m *Migrator) DetermineMigrationBoundariesForRange(rangeStart, rangeEnd *bi
411416
}
412417

413418
actualStart := rangeStart
414-
if maxStoredBlock != nil && maxStoredBlock.Cmp(rangeStart) >= 0 {
419+
// Only adjust start block if we actually have blocks stored (blockCount > 0)
420+
// When blockCount is 0, maxStoredBlock might be 0 but that doesn't mean block 0 exists
421+
if blockCount.Sign() > 0 && maxStoredBlock != nil && maxStoredBlock.Cmp(rangeStart) >= 0 {
415422
// We have some blocks already, start from the next one
416423
actualStart = new(big.Int).Add(maxStoredBlock, big.NewInt(1))
417424

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func init() {
239239
rootCmd.PersistentFlags().Uint("migrator-batchSize", 2000, "Batch size for storage operations in migrator")
240240
rootCmd.PersistentFlags().Uint("migrator-startBlock", 0, "Start block for migration")
241241
rootCmd.PersistentFlags().Uint("migrator-endBlock", 0, "End block for migration")
242+
rootCmd.PersistentFlags().Uint("migrator-workerCount", 0, "Worker count for migration")
242243

243244
viper.BindPFlag("rpc.url", rootCmd.PersistentFlags().Lookup("rpc-url"))
244245
viper.BindPFlag("rpc.blocks.blocksPerRequest", rootCmd.PersistentFlags().Lookup("rpc-blocks-blocksPerRequest"))
@@ -443,6 +444,8 @@ func init() {
443444
viper.BindPFlag("migrator.startBlock", rootCmd.PersistentFlags().Lookup("migrator-startBlock"))
444445
viper.BindPFlag("migrator.endBlock", rootCmd.PersistentFlags().Lookup("migrator-endBlock"))
445446
viper.BindPFlag("migrator.batchSize", rootCmd.PersistentFlags().Lookup("migrator-batchSize"))
447+
viper.BindPFlag("migrator.workerCount", rootCmd.PersistentFlags().Lookup("migrator-workerCount"))
448+
446449
rootCmd.AddCommand(orchestratorCmd)
447450
rootCmd.AddCommand(apiCmd)
448451
rootCmd.AddCommand(validateAndFixCmd)

configs/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ type MigratorConfig struct {
267267
StartBlock uint `mapstructure:"startBlock"`
268268
EndBlock uint `mapstructure:"endBlock"`
269269
BatchSize uint `mapstructure:"batchSize"`
270+
WorkerCount uint `mapstructure:"workerCount"`
270271
}
271272

272273
type Config struct {

0 commit comments

Comments
 (0)