Skip to content

ethrpc: auto-split FilterLogs on block range / result size errors#204

Merged
pkieltyka merged 2 commits intomasterfrom
ethrpc-filter-logs-auto-split
Mar 13, 2026
Merged

ethrpc: auto-split FilterLogs on block range / result size errors#204
pkieltyka merged 2 commits intomasterfrom
ethrpc-filter-logs-auto-split

Conversation

@pkieltyka
Copy link
Member

Add automatic range splitting to Provider.FilterLogs() so callers get transparent retry when nodes reject eth_getLogs requests for being too large (block range exceeded, too many results, etc.).

Uses an AIMD strategy (multiplicative decrease /1.5 on error, additive increase +10% on success) to discover the node's true limit. Once calibrated, the known-good range is reused directly with no further probing.

New options: WithFilterLogsMaxRange(n), WithAutoFilterLogsRange(bool). Feature is disabled by default — zero behavioral change unless opted in.

Add automatic range splitting to Provider.FilterLogs() so callers get
transparent retry when nodes reject eth_getLogs requests for being too
large (block range exceeded, too many results, etc.).

Uses an AIMD strategy (multiplicative decrease /1.5 on error, additive
increase +10% on success) to discover the node's true limit. Once
calibrated, the known-good range is reused directly with no further
probing.

New options: WithFilterLogsMaxRange(n), WithAutoFilterLogsRange(bool).
Feature is disabled by default — zero behavioral change unless opted in.
@pkieltyka pkieltyka requested a review from a team March 13, 2026 15:53
Reject requests with a total block range exceeding 10,000 when
auto-split is enabled, to prevent hammering nodes with hundreds of
sub-queries. Only applies when the feature is opted into — disabled
mode is a direct pass-through as before.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 223520ca7b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +90 to +94
if batchRange < 1 {
batchRange = 1
}

continue // retry the same cursor with a smaller range

Choose a reason for hiding this comment

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

P1 Badge Stop retrying when a single-block request still fails

If a "too much data" error occurs when batchRange has already reached 1, the code clamps it back to 1 and immediately retries the exact same sub-query, so cursor never advances and FilterLogs can loop forever until the context is canceled. This is reachable when one block alone exceeds provider limits (or when the error matcher is overly broad), so auto-split can hang callers instead of returning an actionable error.

Useful? React with 👍 / 👎.

return nil, err
}

end := cursor + batchRange

Choose a reason for hiding this comment

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

P2 Badge Enforce maxRange as block count, not inclusive delta

WithFilterLogsMaxRange is documented as "at most maxRange blocks", but the split window is computed as end = cursor + batchRange and both endpoints are included, so each request spans batchRange+1 blocks. For example, maxRange=1 still queries two blocks at a time, which can violate strict upstream limits and trigger avoidable retries/errors.

Useful? React with 👍 / 👎.

@pkieltyka pkieltyka merged commit cdbaaee into master Mar 13, 2026
8 checks passed
@pkieltyka pkieltyka deleted the ethrpc-filter-logs-auto-split branch March 13, 2026 16:03
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.

1 participant