Speed up getting last event#25
Merged
evgeny-stakewise merged 3 commits intooperator-v4from Feb 25, 2026
Merged
Conversation
There was a problem hiding this comment.
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_concurrencyconfiguration to control parallelism for event log scans. - Update
_get_last_eventto 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
rangeslist upfront can allocate a large list whenfrom_blockis 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.
cyc60
reviewed
Feb 25, 2026
cyc60
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.