From c768fcd2ddbb2c6e8ca5228f509fcd1cee41661d Mon Sep 17 00:00:00 2001 From: tmcgroul Date: Tue, 23 Jul 2024 19:15:12 +0700 Subject: [PATCH 1/2] ignore migration events while parsing calls --- .../master_2024-07-23-12-11.json | 10 ++++++++++ .../substrate-data/src/parsing/call/parser.ts | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 common/changes/@subsquid/substrate-data/master_2024-07-23-12-11.json diff --git a/common/changes/@subsquid/substrate-data/master_2024-07-23-12-11.json b/common/changes/@subsquid/substrate-data/master_2024-07-23-12-11.json new file mode 100644 index 000000000..1f44bc57c --- /dev/null +++ b/common/changes/@subsquid/substrate-data/master_2024-07-23-12-11.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@subsquid/substrate-data", + "comment": "ignore events from `Migrations` pallet while parsing calls", + "type": "patch" + } + ], + "packageName": "@subsquid/substrate-data" +} \ No newline at end of file diff --git a/substrate/substrate-data/src/parsing/call/parser.ts b/substrate/substrate-data/src/parsing/call/parser.ts index c09f5b498..94722af9b 100644 --- a/substrate/substrate-data/src/parsing/call/parser.ts +++ b/substrate/substrate-data/src/parsing/call/parser.ts @@ -326,6 +326,14 @@ export class CallParser { while (this.eventPos >= 0) { let event = this.events[this.eventPos] if (event.phase === 'ApplyExtrinsic') { + if (event.name.startsWith('Migrations.')) { + let index = assertNotNull(event.extrinsicIndex) + let ex = this.extrinsics[index] + assert(ex == null, 'extrinsic for a migration event is unexpected') + this.skipExtrinsicEvents(index) + continue + } + if (event.extrinsicIndex !== this.extrinsic.index) return this.eventPos -= 1 return event @@ -334,4 +342,15 @@ export class CallParser { } } } + + private skipExtrinsicEvents(extrinsicIndex: number) { + while (true) { + let event = this.events[this.eventPos] + if (event.extrinsicIndex == extrinsicIndex) { + this.eventPos -= 1 + } else { + break + } + } + } } From 41354c45816f0dfd4662fec675b005bf85cdf2fe Mon Sep 17 00:00:00 2001 From: tmcgroul Date: Tue, 23 Jul 2024 21:37:08 +0700 Subject: [PATCH 2/2] add comment --- .../substrate-data/src/parsing/call/parser.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/substrate/substrate-data/src/parsing/call/parser.ts b/substrate/substrate-data/src/parsing/call/parser.ts index 94722af9b..ad2415b1f 100644 --- a/substrate/substrate-data/src/parsing/call/parser.ts +++ b/substrate/substrate-data/src/parsing/call/parser.ts @@ -326,15 +326,18 @@ export class CallParser { while (this.eventPos >= 0) { let event = this.events[this.eventPos] if (event.phase === 'ApplyExtrinsic') { - if (event.name.startsWith('Migrations.')) { - let index = assertNotNull(event.extrinsicIndex) - let ex = this.extrinsics[index] - assert(ex == null, 'extrinsic for a migration event is unexpected') - this.skipExtrinsicEvents(index) - continue + if (event.extrinsicIndex !== this.extrinsic.index) { + if (event.name.startsWith('Migrations.')) { + let index = assertNotNull(event.extrinsicIndex) + // Besides `Migrations.*` events there can be more parachain-defined events, + // so we skip all events related to the "phantom" extrinsic. + this.skipExtrinsicEvents(index) + continue + } else { + return + } } - if (event.extrinsicIndex !== this.extrinsic.index) return this.eventPos -= 1 return event } else {