From 9c93ea8715d191fa20bc1bd6fe84ff579891e7c1 Mon Sep 17 00:00:00 2001 From: belopash Date: Mon, 15 Jan 2024 13:28:38 +0500 Subject: [PATCH 1/3] add transaction items to log and trace requests --- evm/evm-processor/src/ds-rpc/filter.ts | 22 ++++++++++++++++++- .../src/interfaces/data-request.ts | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/evm/evm-processor/src/ds-rpc/filter.ts b/evm/evm-processor/src/ds-rpc/filter.ts index 99bbcb437..0099a1067 100644 --- a/evm/evm-processor/src/ds-rpc/filter.ts +++ b/evm/evm-processor/src/ds-rpc/filter.ts @@ -4,7 +4,11 @@ import {Block, Log, StateDiff, Trace, Transaction} from '../mapping/entities' import {DataRequest} from '../interfaces/data-request' -function buildLogFilter(dataRequest: DataRequest): EntityFilter { +function buildLogFilter(dataRequest: DataRequest): EntityFilter { let items = new EntityFilter() for (let req of dataRequest.logs || []) { let {address, topic0, topic1, topic2, topic3, ...relations} = req @@ -40,6 +44,7 @@ function buildTransactionFilter(dataRequest: DataRequest): EntityFilter { @@ -140,6 +145,16 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void { if (rel.transaction) { include.addTransaction(log.transaction) } + if (rel.transactionLogs && log.transaction) { + for (let sibling of log.transaction.logs) { + include.addLog(sibling) + } + } + if (rel.transactionTraces && log.transaction) { + for (let trace of log.transaction.traces) { + include.addTrace(trace) + } + } } } @@ -182,6 +197,11 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void { if (rel.transaction) { include.addTransaction(trace.transaction) } + if (rel.transactionLogs && trace.transaction) { + for (let log of trace.transaction.logs) { + include.addLog(log) + } + } } } diff --git a/evm/evm-processor/src/interfaces/data-request.ts b/evm/evm-processor/src/interfaces/data-request.ts index 206a0b9e3..25e21fb47 100644 --- a/evm/evm-processor/src/interfaces/data-request.ts +++ b/evm/evm-processor/src/interfaces/data-request.ts @@ -20,6 +20,8 @@ export interface LogRequest { topic2?: Bytes32[] topic3?: Bytes32[] transaction?: boolean + transactionTraces?: boolean + transactionLogs?: boolean } @@ -41,6 +43,7 @@ export interface TraceRequest { suicideRefundAddress?: Bytes[] rewardAuthor?: Bytes20[] transaction?: boolean + transactionLogs?: boolean subtraces?: boolean parents?: boolean } From 9f5ac145a5c0972d83699fac16a9581edaaf8530 Mon Sep 17 00:00:00 2001 From: belopash Date: Mon, 15 Jan 2024 13:34:07 +0500 Subject: [PATCH 2/3] changes --- ...log-request-transaction-items_2024-01-15-08-33.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@subsquid/evm-processor/log-request-transaction-items_2024-01-15-08-33.json diff --git a/common/changes/@subsquid/evm-processor/log-request-transaction-items_2024-01-15-08-33.json b/common/changes/@subsquid/evm-processor/log-request-transaction-items_2024-01-15-08-33.json new file mode 100644 index 000000000..602844ea5 --- /dev/null +++ b/common/changes/@subsquid/evm-processor/log-request-transaction-items_2024-01-15-08-33.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@subsquid/evm-processor", + "comment": "add transaction items to log and trace requests", + "type": "minor" + } + ], + "packageName": "@subsquid/evm-processor" +} \ No newline at end of file From 3719dd3089277b4ee87dff9f7c96b84ce6109808 Mon Sep 17 00:00:00 2001 From: belopash Date: Wed, 17 Jan 2024 14:19:18 +0500 Subject: [PATCH 3/3] fixes --- evm/evm-processor/src/ds-rpc/filter.ts | 22 ++++++++++++++-------- evm/evm-processor/src/ds-rpc/request.ts | 10 ++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/evm/evm-processor/src/ds-rpc/filter.ts b/evm/evm-processor/src/ds-rpc/filter.ts index 0099a1067..544f3aef1 100644 --- a/evm/evm-processor/src/ds-rpc/filter.ts +++ b/evm/evm-processor/src/ds-rpc/filter.ts @@ -1,4 +1,4 @@ -import {assertNotNull, weakMemo} from '@subsquid/util-internal' +import {assertNotNull, groupBy, weakMemo} from '@subsquid/util-internal' import {EntityFilter, FilterBuilder} from '@subsquid/util-internal-processor-tools' import {Block, Log, StateDiff, Trace, Transaction} from '../mapping/entities' import {DataRequest} from '../interfaces/data-request' @@ -135,8 +135,11 @@ class IncludeSet { export function filterBlock(block: Block, dataRequest: DataRequest): void { let items = getItemFilter(dataRequest) - let include = new IncludeSet() + let logsByTransaction = groupBy(block.logs, log => log.transactionIndex) + let tracesByTransaction = groupBy(block.traces, trace => trace.transactionIndex) + let include = new IncludeSet() + if (items.logs.present()) { for (let log of block.logs) { let rel = items.logs.match(log) @@ -145,13 +148,15 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void { if (rel.transaction) { include.addTransaction(log.transaction) } - if (rel.transactionLogs && log.transaction) { - for (let sibling of log.transaction.logs) { + if (rel.transactionLogs) { + let logs = logsByTransaction.get(log.transactionIndex) ?? [] + for (let sibling of logs) { include.addLog(sibling) } } - if (rel.transactionTraces && log.transaction) { - for (let trace of log.transaction.traces) { + if (rel.transactionTraces) { + let traces = tracesByTransaction.get(log.transactionIndex) ?? [] + for (let trace of traces) { include.addTrace(trace) } } @@ -197,8 +202,9 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void { if (rel.transaction) { include.addTransaction(trace.transaction) } - if (rel.transactionLogs && trace.transaction) { - for (let log of trace.transaction.logs) { + if (rel.transactionLogs) { + let logs = logsByTransaction.get(trace.transactionIndex) ?? [] + for (let log of logs) { include.addLog(log) } } diff --git a/evm/evm-processor/src/ds-rpc/request.ts b/evm/evm-processor/src/ds-rpc/request.ts index f7968eeaf..5b90752b6 100644 --- a/evm/evm-processor/src/ds-rpc/request.ts +++ b/evm/evm-processor/src/ds-rpc/request.ts @@ -53,6 +53,11 @@ function logsRequested(req?: DataRequest): boolean { if (tx.logs) return true } } + if (req.traces) { + for (let trace of req.traces) { + if (trace.transactionLogs) return true + } + } return false } @@ -65,6 +70,11 @@ function tracesRequested(req?: DataRequest): boolean { if (tx.traces) return true } } + if (req.logs) { + for (let log of req.logs) { + if (log.transactionTraces) return true + } + } return false }