From a4a31c3f4f36dc6ebc91ae269e4d8d1bd7389a7e Mon Sep 17 00:00:00 2001 From: tmcgroul Date: Wed, 17 Jul 2024 15:57:17 +0700 Subject: [PATCH 1/3] allow to load sibling calls --- .../substrate-processor/src/ds-rpc-filter.ts | 6 ++++ .../src/interfaces/data-request.ts | 1 + .../src/interfaces/data.ts | 1 + substrate/substrate-processor/src/mapping.ts | 28 +++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/substrate/substrate-processor/src/ds-rpc-filter.ts b/substrate/substrate-processor/src/ds-rpc-filter.ts index da50e0c4d..f42e0a048 100644 --- a/substrate/substrate-processor/src/ds-rpc-filter.ts +++ b/substrate/substrate-processor/src/ds-rpc-filter.ts @@ -152,6 +152,11 @@ function filterBlock(block: Block, dataRequest: DataRequest): void { if (rel.extrinsic) { include.addExtrinsic(call.extrinsic) } + if (rel.siblings) { + for (let sibling of call.siblings) { + include.addCall(sibling) + } + } } } @@ -175,6 +180,7 @@ function filterBlock(block: Block, dataRequest: DataRequest): void { call.extrinsic = undefined } call.subcalls = call.subcalls.filter(sub => include.calls.has(sub)) + call.siblings = call.siblings.filter(sib => include.calls.has(sib)) call.events = call.events.filter(event => include.events.has(event)) return true }) diff --git a/substrate/substrate-processor/src/interfaces/data-request.ts b/substrate/substrate-processor/src/interfaces/data-request.ts index 7f7491dcf..b2d19b33c 100644 --- a/substrate/substrate-processor/src/interfaces/data-request.ts +++ b/substrate/substrate-processor/src/interfaces/data-request.ts @@ -31,6 +31,7 @@ export interface CallRelations { extrinsic?: boolean stack?: boolean events?: boolean + siblings?: boolean } diff --git a/substrate/substrate-processor/src/interfaces/data.ts b/substrate/substrate-processor/src/interfaces/data.ts index 63d6e5aae..1cc9527a2 100644 --- a/substrate/substrate-processor/src/interfaces/data.ts +++ b/substrate/substrate-processor/src/interfaces/data.ts @@ -122,6 +122,7 @@ export type Call = Simplify< parentCall?: Call getParentCall(): Call subcalls: Call[] + siblings: Call[] events: Event[] } > diff --git a/substrate/substrate-processor/src/mapping.ts b/substrate/substrate-processor/src/mapping.ts index d34ba10ed..55d8e40a6 100644 --- a/substrate/substrate-processor/src/mapping.ts +++ b/substrate/substrate-processor/src/mapping.ts @@ -155,6 +155,7 @@ export class Call { #extrinsic?: Extrinsic #parentCall?: Call #subcalls?: Call[] + #siblings?: Call[] #events?: Event[] #ethereumTransactTo?: Bytes #ethereumTransactSighash?: Bytes @@ -219,6 +220,15 @@ export class Call { this.#subcalls = calls } + get siblings(): Call[] { + this.#siblings = this.#siblings || [] + return this.#siblings + } + + set siblings(calls: Call[]) { + this.#siblings = calls + } + get events(): Event[] { this.#events = this.#events || [] return this.#events @@ -405,6 +415,9 @@ export function setUpItems(block: Block): void { rec.parentCall = prev populateSubcalls(prev, rec) } + if (isSibling(prev, rec)) { + populateSiblings(prev, rec) + } } } @@ -462,6 +475,15 @@ function populateSubcalls(parent: Call | undefined, child: Call): void { } +function populateSiblings(prev: Call, call: Call) { + call.siblings.unshift(prev, ...prev.siblings) + for (let sibling of prev.siblings) { + sibling.siblings.unshift(call) + } + prev.siblings.unshift(call) +} + + function callCompare(a: Call, b: Call) { return a.extrinsicIndex - b.extrinsicIndex || addressCompare(a.address, b.address) } @@ -487,3 +509,9 @@ function isSubcall(parent: CallKey, call: CallKey): boolean { } return true } + + +function isSibling(call1: CallKey, call2: CallKey): boolean { + if (call1.extrinsicIndex != call2.extrinsicIndex) return false + return call1.address.length == call2.address.length +} From fc12eaa001592109a235ec20b7664cb797b4c631 Mon Sep 17 00:00:00 2001 From: tmcgroul Date: Wed, 17 Jul 2024 16:03:30 +0700 Subject: [PATCH 2/3] rename arguments --- substrate/substrate-processor/src/mapping.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/substrate-processor/src/mapping.ts b/substrate/substrate-processor/src/mapping.ts index 55d8e40a6..073a77e59 100644 --- a/substrate/substrate-processor/src/mapping.ts +++ b/substrate/substrate-processor/src/mapping.ts @@ -511,7 +511,7 @@ function isSubcall(parent: CallKey, call: CallKey): boolean { } -function isSibling(call1: CallKey, call2: CallKey): boolean { - if (call1.extrinsicIndex != call2.extrinsicIndex) return false - return call1.address.length == call2.address.length +function isSibling(a: CallKey, b: CallKey): boolean { + if (a.extrinsicIndex != b.extrinsicIndex) return false + return a.address.length == b.address.length } From 119866b1586e1bcfe54b63fd94c0dd577e127650 Mon Sep 17 00:00:00 2001 From: tmcgroul Date: Wed, 17 Jul 2024 16:27:56 +0700 Subject: [PATCH 3/3] changes --- .../call-siblings_2024-07-17-09-27.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@subsquid/substrate-processor/call-siblings_2024-07-17-09-27.json diff --git a/common/changes/@subsquid/substrate-processor/call-siblings_2024-07-17-09-27.json b/common/changes/@subsquid/substrate-processor/call-siblings_2024-07-17-09-27.json new file mode 100644 index 000000000..33d4200b7 --- /dev/null +++ b/common/changes/@subsquid/substrate-processor/call-siblings_2024-07-17-09-27.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@subsquid/substrate-processor", + "comment": "allow to request sibling calls", + "type": "minor" + } + ], + "packageName": "@subsquid/substrate-processor" +} \ No newline at end of file