Skip to content

Conversation

@kalabukdima
Copy link
Collaborator

If finalized head is not available in the snapshot, throws HTTP 500. Otherwise, streams data capped to the finalized head

@kalabukdima kalabukdima requested a review from tmcgroul November 3, 2025 06:40
@mo4islona mo4islona requested a review from Copilot November 3, 2025 11:04
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 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_finalized public API method alongside the existing query method
  • Adds wait_for_finalized_block method 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.

Comment on lines +102 to +106
let capped_last = query
.last_block()
.map(|end| end.min(finalized_head.number))
.or(Some(finalized_head.number));
capped_last
Copy link

Copilot AI Nov 3, 2025

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
.or(Some(finalized_head.number));
capped_last
} else {
anyhow::bail!("Finalized head is not available yet");
Copy link

Copilot AI Nov 3, 2025

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'.

Suggested change
anyhow::bail!("Finalized head is not available yet");
anyhow::bail!("Cannot execute finalized query: finalized head is not available yet");

Copilot uses AI. Check for mistakes.
@kalabukdima kalabukdima merged commit a8e7c36 into master Nov 7, 2025
7 checks passed
@kalabukdima kalabukdima deleted the finalized-stream branch November 7, 2025 10:16
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