Skip to content

Conversation

JasoonS
Copy link
Contributor

@JasoonS JasoonS commented Sep 25, 2025

  • Introduced a new example for streaming height updates in examples/height_stream.
  • Updated hypersync-client to support streaming from the /height/stream SSE endpoint.
  • Modified dependencies in Cargo.toml to include necessary libraries for the new functionality.

Summary by CodeRabbit

  • New Features
    • Added real-time height streaming in the client, enabling continuous updates via server-sent events.
    • Supports multiple payload formats and includes robust error handling.
  • Examples
    • Introduced a runnable example demonstrating how to subscribe to and print live height updates.
  • Chores
    • Updated HTTP client features to support streaming responses.
    • Included the new example in the workspace configuration.

…eaming capabilities

* Introduced a new example for streaming height updates in `examples/height_stream`.
* Updated `hypersync-client` to support streaming from the `/height/stream` SSE endpoint.
* Modified dependencies in `Cargo.toml` to include necessary libraries for the new functionality.
Copy link

coderabbitai bot commented Sep 25, 2025

Walkthrough

Adds a new example crate examples/height_stream and integrates it into the workspace. Enhances hypersync-client with a new Client::stream_height method using SSE to stream block heights, including dependency update to enable streaming. Provides an example binary that consumes and prints streamed heights.

Changes

Cohort / File(s) Summary
Workspace update
Cargo.toml
Adds examples/height_stream to the workspace members; formatting adjustments to the list.
New example crate config
examples/height_stream/Cargo.toml
Introduces a new crate with package metadata and dependencies: path hypersync-client, tokio (full), env_logger, anyhow.
Example: height stream binary
examples/height_stream/src/main.rs
Adds a Tokio binary that builds a Client, subscribes to height SSE via stream_height, prints heights, and exits on error.
Client dependency feature
hypersync-client/Cargo.toml
Enables reqwest’s "stream" feature in addition to "json" and "rustls-tls".
Client SSE streaming feature
hypersync-client/src/lib.rs
Adds Client::stream_height that connects to /height/sse, handles optional bearer auth, parses SSE data (plain number or JSON { "height": N }), and emits u64 via an mpsc channel; includes necessary imports and background task handling.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App as Example Binary
  participant Client as hypersync_client::Client
  participant Req as reqwest
  participant Server as Hypersync HTTP(S)
  participant Chan as mpsc::channel

  App->>Client: stream_height()
  activate Client
  Client->>Req: GET /height/sse<br/>Accept: text/event-stream<br/>(Bearer if configured)
  Req->>Server: HTTP request
  Server-->>Req: 200 OK + SSE stream
  Client->>Chan: spawn task to read SSE and send heights
  deactivate Client

  loop For each SSE event
    Req-->>Client: next SSE event
    Client->>Client: parse data (number or JSON {height})
    alt valid height
      Client-->>Chan: Ok(u64)
    else non-height / parse error
      Client-->>Client: ignore or map error
    end
  end

  loop Consumer
    App-->>Chan: recv()
    alt Ok(height)
      App->>App: print height
    else Err(e)
      App->>App: log error and break
    end
  end
Loading
sequenceDiagram
  autonumber
  actor User
  participant Main as examples/height_stream::main
  participant Client as Arc<Client>
  participant Chan as mpsc::Receiver<Result<u64>>

  User->>Main: run binary
  Main->>Main: init env_logger, tokio
  Main->>Client: construct with URL
  Main->>Client: stream_height()
  Client-->>Main: mpsc Receiver
  Main->>Chan: loop recv()
  alt height
    Chan-->>Main: Ok(u64)
    Main->>Main: println!(height)
  else error
    Chan-->>Main: Err(e)
    Main->>Main: log and exit loop
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • JonoPrest

Poem

A hop, a skip, a streaming height,
I tune to SSE by moonlit night.
With whiskers twitching, logs aglow,
I watch the block numbers grow.
If errors nibble at the wire—
I thump, I bail, then re-inspire. 🐇⚡️

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately reflects the primary changes by noting both the addition of a height stream example and the enhancement of the hypersync-client with streaming support, aligning directly with the PR’s objectives without extraneous detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch height-sse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between a1ec5d3 and 52197ee.

📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • examples/height_stream/Cargo.toml (1 hunks)
  • examples/height_stream/src/main.rs (1 hunks)
  • hypersync-client/Cargo.toml (1 hunks)
  • hypersync-client/src/lib.rs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/height_stream/src/main.rs (1)
hypersync-client/src/lib.rs (1)
  • new (71-93)
⏰ 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). (2)
  • GitHub Check: test_release
  • GitHub Check: test_dev
🔇 Additional comments (4)
hypersync-client/Cargo.toml (1)

57-57: Enabling reqwest streaming support looks good.

Adding the stream feature is necessary for accessing bytes_stream() and similar SSE helpers, so this change is spot on.

Cargo.toml (1)

4-15: Thanks for registering the new example in the workspace.

Including examples/height_stream here keeps the workspace consistent and ensures the example builds with the rest of the project.

examples/height_stream/Cargo.toml (1)

1-10: Example crate manifest looks solid.

The dependencies line up with the runtime you’re using, and the path link back to hypersync-client keeps everything in sync.

examples/height_stream/src/main.rs (1)

6-30: Nice, concise example.

This is a clear illustration of the new API, and the error handling is straightforward.

Comment on lines +555 to +564
///
/// Returns a channel receiver that yields `u64` heights. The sender task runs in the background
/// and closes the channel if the connection drops or an error occurs. Messages that cannot be
/// parsed are ignored.
pub async fn stream_height(self: Arc<Self>) -> Result<mpsc::Receiver<Result<u64>>> {
let mut url = self.url.clone();
let mut segments = url.path_segments_mut().ok().context("get path segments")?;
segments.push("height");
segments.push("sse");
std::mem::drop(segments);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix the /height/stream endpoint path.

The doc comment (and PR objective) call out /height/stream, but the code currently appends "sse", so the client will receive a 404. Please point the request at the documented path instead.

-        segments.push("height");
-        segments.push("sse");
+        segments.push("height");
+        segments.push("stream");
🤖 Prompt for AI Agents
In hypersync-client/src/lib.rs around lines 555 to 564 the path segments
appended for the height streaming endpoint use "sse" causing requests to hit the
wrong URL; change the appended segment from "sse" to "stream" so the client
targets "/height/stream" as documented (update the segments.push call
accordingly and keep the rest of the function unchanged).

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.

1 participant