Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add transaction items to log and trace requests #224

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/evm-processor",
"comment": "add transaction items to log and trace requests",
"type": "minor"
}
],
"packageName": "@subsquid/evm-processor"
}
32 changes: 29 additions & 3 deletions evm/evm-processor/src/ds-rpc/filter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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'


function buildLogFilter(dataRequest: DataRequest): EntityFilter<Log, {transaction?: boolean}> {
function buildLogFilter(dataRequest: DataRequest): EntityFilter<Log, {
transaction?: boolean,
transactionLogs?: boolean,
transactionTraces?: boolean
}> {
let items = new EntityFilter()
for (let req of dataRequest.logs || []) {
let {address, topic0, topic1, topic2, topic3, ...relations} = req
Expand Down Expand Up @@ -40,6 +44,7 @@ function buildTransactionFilter(dataRequest: DataRequest): EntityFilter<Transact

function buildTraceFilter(dataRequest: DataRequest): EntityFilter<Trace, {
transaction?: boolean
transactionLogs?: boolean
subtraces?: boolean
parents?: boolean
}> {
Expand Down Expand Up @@ -130,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)
Expand All @@ -140,6 +148,18 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void {
if (rel.transaction) {
include.addTransaction(log.transaction)
}
if (rel.transactionLogs) {
let logs = logsByTransaction.get(log.transactionIndex) ?? []
for (let sibling of logs) {
include.addLog(sibling)
}
}
if (rel.transactionTraces) {
let traces = tracesByTransaction.get(log.transactionIndex) ?? []
for (let trace of traces) {
include.addTrace(trace)
}
}
}
}

Expand Down Expand Up @@ -182,6 +202,12 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void {
if (rel.transaction) {
include.addTransaction(trace.transaction)
}
if (rel.transactionLogs) {
let logs = logsByTransaction.get(trace.transactionIndex) ?? []
for (let log of logs) {
include.addLog(log)
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions evm/evm-processor/src/ds-rpc/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions evm/evm-processor/src/interfaces/data-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface LogRequest {
topic2?: Bytes32[]
topic3?: Bytes32[]
transaction?: boolean
transactionTraces?: boolean
transactionLogs?: boolean
}


Expand All @@ -41,6 +43,7 @@ export interface TraceRequest {
suicideRefundAddress?: Bytes[]
rewardAuthor?: Bytes20[]
transaction?: boolean
transactionLogs?: boolean
subtraces?: boolean
parents?: boolean
}
Expand Down
Loading