@@ -31,7 +31,8 @@ import { eventService } from './eventService';
3131
3232enum ProcessingMode {
3333 DETECTION = 'detection' , // Looking for migration events
34- FULL = 'full' // Full migration monitoring
34+ FULL = 'full' , // Full migration monitoring
35+ COMPLETED = 'completed' // Migration complete - no processing
3536}
3637
3738interface QueueItem {
@@ -102,8 +103,17 @@ export class BlockProcessor {
102103 } ) ;
103104
104105 if ( latestMigrationStage ) {
105- const isActiveStage = this . isMigrationActive ( latestMigrationStage . stage ) ;
106- if ( isActiveStage ) {
106+ // Check if migration is completed
107+ if ( this . isMigrationCompleted ( latestMigrationStage . stage ) ) {
108+ this . switchToCompletedMode ( ) ;
109+ Log . service ( {
110+ service : 'Block Processor' ,
111+ action : '🎉 Migration already completed (loaded from database)' ,
112+ details : { stage : latestMigrationStage . stage }
113+ } ) ;
114+ }
115+ // Check if migration is active
116+ else if ( this . isMigrationActive ( latestMigrationStage . stage ) ) {
107117 // Migration is active, switch to full mode
108118 this . switchToFullMode ( ) ;
109119 Log . service ( {
@@ -266,6 +276,22 @@ export class BlockProcessor {
266276 }
267277
268278 private async processBlock ( item : QueueItem ) : Promise < void > {
279+ // Process based on current mode
280+ if ( this . currentMode === ProcessingMode . COMPLETED ) {
281+ // Migration completed - skip all processing
282+ Log . service ( {
283+ service : 'Block Processor' ,
284+ action : 'Skipping block - migration completed' ,
285+ details : {
286+ chain : item . chain ,
287+ blockNumber : item . blockNumber ,
288+ timestamp : item . timestamp ? new Date ( item . timestamp ) . toISOString ( ) : null ,
289+ message : 'All processing stopped. Only FinalizedService is tracking blocks.'
290+ }
291+ } ) ;
292+ return ;
293+ }
294+
269295 Log . service ( {
270296 service : 'Block Processor' ,
271297 action : 'Processing block' ,
@@ -310,7 +336,6 @@ export class BlockProcessor {
310336 } ,
311337 } ) ;
312338
313- // Process based on current mode
314339 if ( this . currentMode === ProcessingMode . DETECTION ) {
315340 // Detection mode: only process relay chain for migration events
316341 if ( item . chain === 'relay-chain' ) {
@@ -320,7 +345,7 @@ export class BlockProcessor {
320345 Log . service ( {
321346 service : 'Block Processor' ,
322347 action : 'Skipping Asset Hub block in detection mode' ,
323- details : {
348+ details : {
324349 blockNumber : item . blockNumber ,
325350 timestamp : new Date ( item . timestamp ! ) . toISOString ( )
326351 }
@@ -329,7 +354,7 @@ export class BlockProcessor {
329354 } else if ( this . currentMode === ProcessingMode . FULL ) {
330355 // Full mode: use existing shouldProcessBlock logic for efficiency
331356 const shouldProcess = this . shouldProcessBlock ( item . blockNumber , item . chain ) ;
332-
357+
333358 if ( shouldProcess ) {
334359 // Full processing: events, storage queries, database writes
335360 if ( item . chain === 'asset-hub' ) {
@@ -342,8 +367,8 @@ export class BlockProcessor {
342367 Log . service ( {
343368 service : 'Block Processor' ,
344369 action : 'Skipping full processing - not near migration' ,
345- details : {
346- blockNumber : item . blockNumber ,
370+ details : {
371+ blockNumber : item . blockNumber ,
347372 chain : item . chain ,
348373 timestamp : new Date ( item . timestamp ! ) . toISOString ( )
349374 }
@@ -839,8 +864,17 @@ export class BlockProcessor {
839864 await this . setMigrationBlockNumber ( migrationStage . asScheduled . start . toNumber ( ) ) ;
840865 }
841866
867+ // Check if migration is completed
868+ if ( this . isMigrationCompleted ( currentStage ) ) {
869+ Log . service ( {
870+ service : 'Block Processor' ,
871+ action : '🎉 MigrationDone stage detected - switching to completed mode' ,
872+ details : { stage : currentStage , blockNumber : item . blockNumber }
873+ } ) ;
874+ this . switchToCompletedMode ( ) ;
875+ }
842876 // Check if we need to switch to full processing based on current stage
843- if ( this . isMigrationActive ( currentStage ) ) {
877+ else if ( this . isMigrationActive ( currentStage ) ) {
844878 Log . service ( {
845879 service : 'Block Processor' ,
846880 action : 'Active migration detected in finalized block, switching to full mode' ,
@@ -1049,7 +1083,7 @@ export class BlockProcessor {
10491083 }
10501084
10511085 this . currentMode = ProcessingMode . FULL ;
1052-
1086+
10531087 Log . service ( {
10541088 service : 'Block Processor' ,
10551089 action : 'Switched to full processing mode' ,
@@ -1068,14 +1102,41 @@ export class BlockProcessor {
10681102 }
10691103
10701104 this . currentMode = ProcessingMode . DETECTION ;
1071-
1105+
10721106 Log . service ( {
10731107 service : 'Block Processor' ,
10741108 action : 'Switched to detection mode' ,
10751109 details : { previousMode : ProcessingMode . FULL }
10761110 } ) ;
10771111 }
10781112
1113+ /**
1114+ * Switch to completed mode (migration is done - stop all processing)
1115+ */
1116+ private switchToCompletedMode ( ) : void {
1117+ if ( this . currentMode === ProcessingMode . COMPLETED ) {
1118+ return ; // Already in completed mode
1119+ }
1120+
1121+ const previousMode = this . currentMode ;
1122+ this . currentMode = ProcessingMode . COMPLETED ;
1123+
1124+ Log . service ( {
1125+ service : 'Block Processor' ,
1126+ action : '🎉 Migration COMPLETED - All processing stopped' ,
1127+ details : {
1128+ previousMode,
1129+ message : 'Only FinalizedService will continue tracking block numbers'
1130+ }
1131+ } ) ;
1132+
1133+ // Emit a special event for the frontend
1134+ eventService . emit ( 'migrationCompleted' , {
1135+ timestamp : new Date ( ) . toISOString ( ) ,
1136+ message : 'Migration has completed successfully. Monitoring has stopped.' ,
1137+ } ) ;
1138+ }
1139+
10791140 /**
10801141 * Get current processing mode
10811142 */
@@ -1087,10 +1148,17 @@ export class BlockProcessor {
10871148 * Check if a migration stage indicates active migration
10881149 */
10891150 private isMigrationActive ( stage : string ) : boolean {
1090- const inactiveStages = [ 'NotStarted' , 'Scheduled' , 'Complete' , 'Pending' ] ;
1151+ const inactiveStages = [ 'NotStarted' , 'Scheduled' , 'Complete' , 'Pending' , 'MigrationDone' ] ;
10911152 return ! inactiveStages . includes ( stage ) ;
10921153 }
10931154
1155+ /**
1156+ * Check if migration is completed
1157+ */
1158+ private isMigrationCompleted ( stage : string ) : boolean {
1159+ return stage === 'MigrationDone' ;
1160+ }
1161+
10941162 /**
10951163 * Set migration start block number and persist scheduled stage to database
10961164 */
0 commit comments