|
1 | | -import type { PalletRcMigratorMigrationStage, PalletRcMigratorQueuePriority } from '../types/pjs'; |
| 1 | +import type { PalletRcMigratorMigrationStage, PalletRcMigratorQueuePriority, PalletRcMigratorAccountsMigratedBalances } from '../types/pjs'; |
2 | 2 | import type { ApiDecoration } from '@polkadot/api/types'; |
3 | 3 | import type { Vec, Bytes } from '@polkadot/types'; |
4 | 4 | import type { Event } from '@polkadot/types/interfaces'; |
@@ -49,6 +49,7 @@ export class BlockProcessor { |
49 | 49 | private processing: Map<string, boolean> = new Map(); |
50 | 50 | private lastBlockNumber: Map<string, number> = new Map(); |
51 | 51 | private previousDmpQueueSize: number = 0; |
| 52 | + private previousRcBalanceMigration: { kept: string; migrated: string } | null = null; |
52 | 53 | private currentMode: ProcessingMode = ProcessingMode.DETECTION; |
53 | 54 | private migrationStartBlockNumber?: number; |
54 | 55 | private rcPriorityConfigQueried: boolean = false; |
@@ -745,29 +746,33 @@ export class BlockProcessor { |
745 | 746 | try { |
746 | 747 | // Query priority config only once on first full mode block |
747 | 748 | if (!this.rcPriorityConfigQueried) { |
748 | | - const [migrationStage, dmpMessageQueue, umpQueuePriority] = await Promise.all([ |
| 749 | + const [migrationStage, dmpMessageQueue, umpQueuePriority, rcBalanceMigration] = await Promise.all([ |
749 | 750 | apiAt.query.rcMigrator.rcMigrationStage<PalletRcMigratorMigrationStage>(), |
750 | 751 | apiAt.query.dmp.downwardMessageQueues<Vec<PolkadotCorePrimitivesInboundDownwardMessage>>( |
751 | 752 | 1000 |
752 | 753 | ), |
753 | 754 | apiAt.query.rcMigrator.ahUmpQueuePriorityConfig<PalletRcMigratorQueuePriority>(), |
| 755 | + apiAt.query.rcMigrator.rcMigratedBalance<PalletRcMigratorAccountsMigratedBalances>(), |
754 | 756 | ]); |
755 | 757 |
|
756 | 758 | await this.handleRcMigrationStage(migrationStage, item); |
757 | 759 | await this.handleRcDownwardMessageQueues(dmpMessageQueue, item); |
758 | 760 | await this.handleUmpQueuePriority(umpQueuePriority, item); |
| 761 | + await this.handleRcBalanceMigration(rcBalanceMigration, item); |
759 | 762 |
|
760 | 763 | this.rcPriorityConfigQueried = true; |
761 | 764 | } else { |
762 | | - const [migrationStage, dmpMessageQueue] = await Promise.all([ |
| 765 | + const [migrationStage, dmpMessageQueue, rcBalanceMigration] = await Promise.all([ |
763 | 766 | apiAt.query.rcMigrator.rcMigrationStage<PalletRcMigratorMigrationStage>(), |
764 | 767 | apiAt.query.dmp.downwardMessageQueues<Vec<PolkadotCorePrimitivesInboundDownwardMessage>>( |
765 | 768 | 1000 |
766 | 769 | ), |
| 770 | + apiAt.query.rcMigrator.rcMigratedBalance<PalletRcMigratorAccountsMigratedBalances>(), |
767 | 771 | ]); |
768 | 772 |
|
769 | 773 | await this.handleRcMigrationStage(migrationStage, item); |
770 | 774 | await this.handleRcDownwardMessageQueues(dmpMessageQueue, item); |
| 775 | + await this.handleRcBalanceMigration(rcBalanceMigration, item); |
771 | 776 | } |
772 | 777 |
|
773 | 778 | Log.service({ |
@@ -1067,6 +1072,63 @@ export class BlockProcessor { |
1067 | 1072 | } |
1068 | 1073 | } |
1069 | 1074 |
|
| 1075 | + private async handleRcBalanceMigration( |
| 1076 | + balanceMigration: PalletRcMigratorAccountsMigratedBalances, |
| 1077 | + item: QueueItem |
| 1078 | + ): Promise<void> { |
| 1079 | + try { |
| 1080 | + const kept = balanceMigration.kept.toString(); |
| 1081 | + const migrated = balanceMigration.migrated.toString(); |
| 1082 | + |
| 1083 | + // Don't emit if migrated goes to 0 after previously being above 0 (migration completion reset) |
| 1084 | + if ( |
| 1085 | + this.previousRcBalanceMigration && |
| 1086 | + this.previousRcBalanceMigration.migrated !== '0' && |
| 1087 | + migrated === '0' |
| 1088 | + ) { |
| 1089 | + Log.service({ |
| 1090 | + service: 'RC Balance Migration', |
| 1091 | + action: 'Ignoring reset to zero (migration completed)', |
| 1092 | + details: { |
| 1093 | + previousMigrated: this.previousRcBalanceMigration.migrated, |
| 1094 | + }, |
| 1095 | + }); |
| 1096 | + return; |
| 1097 | + } |
| 1098 | + |
| 1099 | + // Only emit if values have changed |
| 1100 | + if ( |
| 1101 | + !this.previousRcBalanceMigration || |
| 1102 | + this.previousRcBalanceMigration.kept !== kept || |
| 1103 | + this.previousRcBalanceMigration.migrated !== migrated |
| 1104 | + ) { |
| 1105 | + eventService.emit('rcBalanceMigration', { |
| 1106 | + kept: kept.toString(), |
| 1107 | + migrated: migrated.toString(), |
| 1108 | + timestamp: new Date(item.timestamp!).toISOString(), |
| 1109 | + }); |
| 1110 | + |
| 1111 | + Log.service({ |
| 1112 | + service: 'RC Balance Migration', |
| 1113 | + action: 'Balance migration values updated', |
| 1114 | + details: { |
| 1115 | + kept: kept.toString(), |
| 1116 | + migrated: migrated.toString(), |
| 1117 | + }, |
| 1118 | + }); |
| 1119 | + |
| 1120 | + // Update tracking variable |
| 1121 | + this.previousRcBalanceMigration = { kept, migrated }; |
| 1122 | + } |
| 1123 | + } catch (error) { |
| 1124 | + Log.service({ |
| 1125 | + service: 'RC Balance Migration', |
| 1126 | + action: 'Error processing RC balance migration', |
| 1127 | + error: error as Error, |
| 1128 | + }); |
| 1129 | + } |
| 1130 | + } |
| 1131 | + |
1070 | 1132 | /** |
1071 | 1133 | * Lightweight detection mode - only looks for migration scheduling events on Relay Chain |
1072 | 1134 | */ |
|
0 commit comments