Skip to content

Speed up getting last event#25

Merged
evgeny-stakewise merged 3 commits intooperator-v4from
speedup-protocol-config
Feb 25, 2026
Merged

Speed up getting last event#25
evgeny-stakewise merged 3 commits intooperator-v4from
speedup-protocol-config

Conversation

@evgeny-stakewise
Copy link
Contributor

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to speed up fetching the most recent on-chain contract event by scanning block ranges in parallel with a configurable concurrency limit.

Changes:

  • Add MAX_CONCURRENCY/max_concurrency configuration to control parallelism for event log scans.
  • Update _get_last_event to query multiple block chunks concurrently (batching) instead of strictly sequentially.
  • Document the new environment variable in .env.example.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/config/settings.py Introduces max_concurrency setting used to batch parallel event log queries.
src/common/contracts.py Refactors last-event scan logic to run batched concurrent get_logs calls.
.env.example Adds example MAX_CONCURRENCY configuration and comments.
Comments suppressed due to low confidence (2)

src/common/contracts.py:61

  • Building the full ranges list upfront can allocate a large list when from_block is far in the past, even though only one batch is needed in the common case. Consider generating chunk ranges lazily and processing them batch-by-batch to avoid extra memory/time overhead.
        # Build all chunk ranges from newest to oldest
        ranges: list[tuple[BlockNumber, BlockNumber]] = []
        current_to = to_block
        while current_to >= from_block:
            chunk_from = BlockNumber(max(current_to - blocks_range, from_block))
            ranges.append((chunk_from, BlockNumber(current_to)))
            current_to = BlockNumber(current_to - blocks_range - 1)

.env.example:21

  • The example sets MAX_CONCURRENCY=10, but the code default is 8. Consider aligning the example with the default (or documenting why the recommended value differs) to avoid confusing operators.
# Maximum number of parallel event scan queries
MAX_CONCURRENCY=10

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@evgeny-stakewise evgeny-stakewise merged commit bf32ad2 into operator-v4 Feb 25, 2026
5 checks passed
@evgeny-stakewise evgeny-stakewise deleted the speedup-protocol-config branch February 25, 2026 12:05
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.

3 participants