Skip to content

Performance Optimization for eth_getLogs/eth_getFilterLogs with Large-scale Query Parameters #6343

@0xbigapple

Description

@0xbigapple

Background

eth_getLogs and eth_getFilterLogs are interfaces for querying smart contract event logs. To quickly find blocks containing target events, these interfaces use Bloom filters to index data. The partialMatch method searches the Section-Bloom database using these filters. However, when query conditions contain a large number of topics or addresses (e.g. querying TRC20 transfers for multiple addresses or querying multiple contracts for a single address), it causes many duplicate database queries and slows down the response. While version 4.8.0 added limits on topic counts and block ranges to prevent long request times, these restrictions force users to split their queries into multiple smaller requests.

We have optimized the partialMatch method to avoid duplicate database queries and improve interface performance. This optimization allows nodes to support larger queries, reducing the number of requests users need to make.

Rationale

Why should this feature exist?

  • Large queries are slow due to duplicate database operations. Users have to split their queries into smaller ones to work around current limits, which is not user-friendly.

What are the use-cases?

  • NFT exchanges & DEX: Monitor Transfer events for multiple tokens
  • Data analysis platforms: Batch query historical events for analysis and visualization

Specification

Let's take eth_getLogs as an example to see how event log queries locate target blocks:

  1. Converts query conditions (address, topics) into Bloom filter positions
  2. For each section (2048 blocks), call partialMatch to find possible blocks
  3. The partialMatch method queries Section-Bloom database for matching blocks

Due to Bloom filter properties, duplicate queries occur: with 2048 total bits and 3 bits per condition, when condition count reaches 683 (683 * 3 > 2048), bit collisions are inevitable, leading to duplicate database queries.

Test results using random from-address from USDT transfer records:

Test Set BitIndex Duplication Rate
10 topics 0%
100 topics 7%
500 topics 28.8%
1000 topics 48.4%

Optimization of partialMatch method:

  1. Preprocess bitIndexes[][] to extract unique bitIndexes
  2. Query database only once for each unique bitIndex
  3. Reassemble final BitSet using query results

This reduces IO operations and improves query speed.

Test Specification

  • Verifies result consistency before and after optimization
  • Compares performance with same inputs

Scope Of Impact

Affected Modules:

  • JSON-RPC interface layer (EthApi)

Affected interfaces:

  • eth_getLogs
  • eth_getFilterLogs

Implementation

Do you have ideas regarding the implementation of this feature?
Y

Are you willing to implement this feature?
Y

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions