From 79a427e6e008741124bc2c875f77e84908a7a32a Mon Sep 17 00:00:00 2001 From: Eldar Gabdullin Date: Tue, 9 Jan 2024 15:24:07 +0300 Subject: [PATCH] fix call trace parent-child relation setup --- .../master_2024-01-09-12-24.json | 10 +++++++ evm/evm-processor/src/mapping/relations.ts | 27 ++++++++----------- 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 common/changes/@subsquid/evm-processor/master_2024-01-09-12-24.json diff --git a/common/changes/@subsquid/evm-processor/master_2024-01-09-12-24.json b/common/changes/@subsquid/evm-processor/master_2024-01-09-12-24.json new file mode 100644 index 000000000..ef654345e --- /dev/null +++ b/common/changes/@subsquid/evm-processor/master_2024-01-09-12-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@subsquid/evm-processor", + "comment": "fix call trace parent-child relation setup", + "type": "patch" + } + ], + "packageName": "@subsquid/evm-processor" +} \ No newline at end of file diff --git a/evm/evm-processor/src/mapping/relations.ts b/evm/evm-processor/src/mapping/relations.ts index ae1ae8de4..adb023cc1 100644 --- a/evm/evm-processor/src/mapping/relations.ts +++ b/evm/evm-processor/src/mapping/relations.ts @@ -27,12 +27,15 @@ export function setUpRelations(block: Block): void { rec.transaction = tx tx.traces.push(rec) } - - if (i > 0) { - let prev = block.traces[i - 1] - if (isChild(prev, rec)) { - rec.parent = prev - populateSubtraces(prev, rec) + for (let j = i + 1; j < block.traces.length; j++) { + let next = block.traces[j] + if (isDescendent(rec, next)) { + rec.children.push(next) + if (next.traceAddress.length == rec.traceAddress.length + 1) { + next.parent = rec + } + } else { + break } } } @@ -61,19 +64,11 @@ function addressCompare(a: number[], b: number[]): number { } -function isChild(parent: Trace, child: Trace): boolean { +function isDescendent(parent: Trace, child: Trace): boolean { if (parent.transactionIndex != child.transactionIndex) return false - if (parent.traceAddress.length > child.traceAddress.length) return false + if (parent.traceAddress.length >= child.traceAddress.length) return false for (let i = 0; i < parent.traceAddress.length; i++) { if (parent.traceAddress[i] != child.traceAddress[i]) return false } return true } - - -function populateSubtraces(parent: Trace | undefined, child: Trace): void { - while (parent) { - parent.children.push(child) - parent = parent.parent - } -}