-
Notifications
You must be signed in to change notification settings - Fork 2
Support /finalized-stream in hotblocks DB #43
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
Conversation
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.
Pull Request Overview
This PR adds support for querying only finalized blocks by introducing a new /finalized-stream endpoint and corresponding query logic. This allows clients to request data only up to the finalized head, ensuring they don't receive potentially reorged blocks.
- Introduces new
query_finalizedpublic API method alongside the existingquerymethod - Adds
wait_for_finalized_blockmethod to track finalized block progression - Implements finalized block capping logic to constrain queries within finalized boundaries
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/hotblocks/src/query/service.rs | Refactored query logic into internal method with finalized flag, added query_finalized public method |
| crates/hotblocks/src/query/running.rs | Added logic to cap query's last_block to finalized head when only_finalized is true |
| crates/hotblocks/src/query/response.rs | Threaded only_finalized parameter through to RunningQuery |
| crates/hotblocks/src/dataset_controller/dataset_controller.rs | Added wait_for_finalized_block method mirroring wait_for_block |
| crates/hotblocks/src/api.rs | Added /finalized-stream endpoint and refactored stream handlers to share internal implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let capped_last = query | ||
| .last_block() | ||
| .map(|end| end.min(finalized_head.number)) | ||
| .or(Some(finalized_head.number)); | ||
| capped_last |
Copilot
AI
Nov 3, 2025
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.
[nitpick] The variable capped_last is unnecessary and reduces clarity. Directly return the result of the expression on line 102-105.
| let capped_last = query | |
| .last_block() | |
| .map(|end| end.min(finalized_head.number)) | |
| .or(Some(finalized_head.number)); | |
| capped_last | |
| query | |
| .last_block() | |
| .map(|end| end.min(finalized_head.number)) | |
| .or(Some(finalized_head.number)) |
| .or(Some(finalized_head.number)); | ||
| capped_last | ||
| } else { | ||
| anyhow::bail!("Finalized head is not available yet"); |
Copilot
AI
Nov 3, 2025
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.
The error message 'Finalized head is not available yet' should be more specific about the context. Consider including that this is for a finalized query, e.g., 'Cannot execute finalized query: finalized head is not available yet'.
| anyhow::bail!("Finalized head is not available yet"); | |
| anyhow::bail!("Cannot execute finalized query: finalized head is not available yet"); |
If finalized head is not available in the snapshot, throws HTTP 500. Otherwise, streams data capped to the finalized head