Skip to content

feat(evm-processor): filterLogsOnNode RPC ingestion setting - #702

Merged
abernatskiy merged 3 commits into
masterfrom
feat/evm-rpc-filtered-logs
Dec 4, 2026
Merged

abernatskiy merged 3 commits into
masterfrom
feat/evm-rpc-filtered-logs

Conversation

@abernatskiy

Copy link
Copy Markdown
Contributor

Why

Without a gateway, the RPC data source fetches every finalized block with eth_getBlockByNumber, and all its logs with an unfiltered eth_getLogs per 10 blocks, then filters logs locally. For a contract with few events, the number of calls grows with the block range rather than with the number of matching logs. Some public endpoints also refuse eth_getLogs without an address, so this mode cannot backfill from them at all.

What

A new optional setting:

processor.setRpcDataIngestionSettings({
    filterLogsOnNode: {blockRange: 2000} // blocks per eth_getLogs call: the provider's range limit
})

For finalized ranges whose requests select blocks by logs only (addLog, with any relation, no includeAllBlocks):

  • Logs: one eth_getLogs per distinct address/topics filter over each split of up to blockRange blocks. Overlapping results are deduplicated.
  • Blocks: only blocks with matching logs are fetched, plus the last block of the split, which the processor needs to record progress. That last block carries only its header.
  • Relations:
    • transaction: transactions come with the block.
    • Receipt fields, transactionTraces, transactionStateDiffs: fetched per matching block, as before.
    • transactionLogs: gets all logs of the matching blocks.
  • Everything else is unchanged: hot blocks, and ranges whose requests include transactions, traces, state diffs or includeAllBlocks, are ingested as before. When those share a processor with filtered ranges, they are fetched in 10-block pieces.

Trade-off: the logs bloom check cannot work on filtered results, so a node that misses logs goes unnoticed. The setting's doc comment says so. A log whose blockHash differs from the fetched block's hash causes a retry, then an error.

Both modes: eth_getLogs now also splits ranges on common provider block-range limit errors and follows Alchemy's suggested range. Before, these errors stopped the processor.

Tests

  • Current behaviour, pinned (these also pass on master):
    • cold ingestion: every block is fetched, eth_getLogs carries only the range, logs are filtered locally, and the bloom check rejects a block with logs missing;
    • eth_getLogs range splitting.
  • New mode:
    • the filtered calls, and which blocks are fetched;
    • the same logs as the default mode;
    • deduplication of overlapping filters, and requests that can match nothing;
    • splitting by blockRange and on provider range errors;
    • transactions, receipts and transactionLogs;
    • retries on a blockHash mismatch;
    • fallback for other requests, and ranges that mix both;
    • validation of blockRange.
  • Unit: the eligibility rules, and the new error patterns.

Checked against Ethereum mainnet over the same 1,000 finalized blocks, with output identical in both modes:

Request Default filterLogsOnNode
Uniswap V3 factory logs (2 logs) 1,101 calls, 56.7 s 5 calls, 1.1 s
USDC/WETH 0.05% swaps with transactions and gasUsed (2,765 items) 2,009 calls, 111.4 s 1,396 calls, 85.4 s

🤖 Generated with Claude Code

Without a gateway, the RPC data source fetches every finalized block
(eth_getBlockByNumber) and all its logs (unfiltered eth_getLogs per 10
blocks), then filters logs locally. The number of calls grows with the
block range, not with the number of matching logs.

`setRpcDataIngestionSettings({filterLogsOnNode: {blockRange}})` lets
ranges whose requests select blocks by logs only be fetched with
eth_getLogs filtered by address and topics, over splits of `blockRange`
blocks. Only blocks with matching logs are fetched, plus the last block
of each split for the processor's progress. Log relations work: the
transaction comes with the block, receipts/traces/state diffs are
fetched per matching block, and `transactionLogs` gets all logs of
matching blocks. Ranges with other requests or includeAllBlocks, and
hot blocks, are ingested as before.

The logs bloom check cannot work on filtered results, so a node that
misses logs goes unnoticed; the setting documents this. Logs whose
blockHash differs from the fetched block are retried, then rejected.

eth_getLogs also splits ranges on common provider block-range limit
errors and follows Alchemy's suggested range, in both modes.

Tests pin the current cold ingestion (every block fetched, unfiltered
eth_getLogs, local filtering, bloom check) and eth_getLogs splitting,
and cover the new mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Transaction-log refetches can accept logs from the wrong fork without retry, while oversized unfiltered batches increase memory usage and delay checkpoints.

2 open issues
What changed in this PR

Adds optional node-side log filtering to speed up finalized EVM ingestion without a gateway.

Changes:

  • Fetches matching logs and their blocks, plus a progress header.
  • Handles provider range limits while preserving filters.
  • Adds ingestion tests, fixtures, and a minor-release change record.
File Description
evm/​evm-processor/​src/​processor.ts Exposes and documents the setting.
evm/​evm-processor/​src/​ds-rpc/​rpc.ts Implements filtered fetching and range-error handling.
evm/​evm-processor/​src/​ds-rpc/​rpc.test.ts Tests range splitting and filter propagation.
evm/​evm-processor/​src/​ds-rpc/​log-filter.ts Builds filters and determines eligibility.
evm/​evm-processor/​src/​ds-rpc/​log-filter.test.ts Tests eligibility and matching.
evm/​evm-processor/​src/​ds-rpc/​cold.test.ts Tests default and filtered ingestion.
evm/​evm-processor/​src/​ds-rpc/​client.ts Routes finalized requests through filtered ingestion.
evm/​evm-processor/​src/​ds-rpc/​chain.fixture.ts Provides an in-memory chain and RPC mock.
common/​changes/​@subsquid/​evm-processor/​feat-evm-rpc-filtered-logs_2026-12-04-20-15.json Records the feature for release.

Review effort: Balanced

Comment thread evm/evm-processor/src/ds-rpc/rpc.ts Resolved
Comment thread evm/evm-processor/src/ds-rpc/client.ts Resolved
…ck batches

- The per-block eth_getLogs refetch for the transactionLogs relation is
  now checked against the block hash too, retrying on a mismatch like the
  filtered response.
- Each run of consecutive ranges gets its own cold-ingest split size, so
  ranges that are not filtered keep batches of at most 10 blocks instead
  of one batch of up to `blockRange` blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The ingestion loop can advance to the next run before the current run finishes, allowing later blocks to be checkpointed while an earlier block is permanently skipped.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread evm/evm-processor/src/ds-rpc/client.ts Resolved
…op on head

With stopOnHead, cold ingestion of a run of ranges can end at the chain
head before the run's end. Starting the next run with a fresh head could
then deliver blocks past a gap. Stop instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the optional node-side log filtering change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@abernatskiy
abernatskiy merged commit f16a6e6 into master Dec 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants