-
Notifications
You must be signed in to change notification settings - Fork 29
fix: Fix block processing bottleneck #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #395 +/- ##
=======================================
- Coverage 95.5% 95.5% -0.1%
=======================================
Files 87 87
Lines 24543 24601 +58
=======================================
+ Hits 23456 23509 +53
- Misses 1087 1092 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/services/blockwatcher/service.rs
Outdated
| let (_process_result, _trigger_result) = tokio::join!(process_handle, trigger_handle); | ||
|
|
||
| // Clear fetched blocks to free memory for next iteration | ||
| block_tracker.clear_fetched_blocks(&network.slug).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there's overlap in processing? E.g. the cron is set to 60 seconds, but a cycle takes 70 seconds to complete due to slow/delay in rpc. Next cycle overlaps with already running cycle. Now first cycle completed and cleared memory midsts second cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is a good solution, so I would spend some time analysing, but perhaps we can map it with network_slug+index so that we can track overlaps in iterations (through an index) wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept thinking the same tbh, I am trying to find a possible better approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have simplified by just creating a local variable per execution, it will only live inside each execution
WalkthroughThe pull request refactors block tracking to differentiate between fetched and missed blocks. A new Changes
Sequence DiagramsequenceDiagram
participant PL as Pipeline
participant SVC as Service
participant TR as Trigger Stage
participant TRK as BlockTracker
PL->>SVC: process_new_blocks(blocks, tracker)
Note over SVC: Initialize fetched_block_numbers: HashSet
SVC->>TR: Process each block + fetched_blocks set
loop For each fetched block
TR->>TR: Add block to fetched_block_numbers
TR->>TRK: record_block(network, num, &fetched_blocks)
alt Block was fetched
TRK->>TRK: Record as processed
else Block not in fetched_blocks
TRK->>TRK: Treat as missed, log error
end
end
rect rgb(200, 220, 255)
Note over SVC: Cleanup phase
SVC->>TRK: record_block(remaining, &fetched_blocks)
TRK->>TRK: Identify truly missed blocks
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/services/blockwatcher/service.rs(6 hunks)src/services/blockwatcher/tracker.rs(12 hunks)tests/integration/blockwatcher/service.rs(13 hunks)tests/integration/mocks/services.rs(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/integration/mocks/services.rs (1)
src/services/blockwatcher/tracker.rs (2)
record_block(31-36)record_block(96-160)
tests/integration/blockwatcher/service.rs (1)
src/services/blockwatcher/tracker.rs (2)
new(30-30)new(72-78)
src/services/blockwatcher/tracker.rs (1)
src/services/blockwatcher/error.rs (2)
block_tracker_error(77-83)storage_error(68-74)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Redirect rules - openzeppelin-monitor
- GitHub Check: Header rules - openzeppelin-monitor
- GitHub Check: Pages changed - openzeppelin-monitor
- GitHub Check: boostsecurity - boostsecurityio/semgrep-pro
- GitHub Check: boostsecurity - boostsecurityio/osv-scanner
- GitHub Check: boostsecurity - boostsecurityio/scanner
- GitHub Check: clippy
- GitHub Check: test
- GitHub Check: msrv
- GitHub Check: boostsecurity - boostsecurityio/boost-sca
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (rust)
Summary
We have moved
record_blockto sync pipeline to avoid race conditions, now we have the following to keep the proper tracking of missing blocks:Solution
Implemented a two-stage tracking system that records blocks at different points in the processing pipeline:
When a gap is detected, the system checks if the missing block was fetched to determine the actual failure type.
Checklist
Summary by CodeRabbit
Refactor
Tests