Skip to content

feat: firehose mode with in-band slot watermarks - #6

Open
GabrielePicco wants to merge 4 commits into
masterfrom
feat/firehose-mode
Open

feat: firehose mode with in-band slot watermarks#6
GabrielePicco wants to merge 4 commits into
masterfrom
feat/firehose-mode

Conversation

@GabrielePicco

@GabrielePicco GabrielePicco commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the delivery mode the magicblock-validator delegation-record mirror needs (first consumer landing separately): a single channel carrying every delegation-record update on chain, with the ordering and losslessness guarantees a mirror requires to treat its entries as authoritative for the live path.

DlpSyncer::start_firehose(endpoint, api_key)

  • Delivers every record update (no per-record subscriptions, no replay buffering).
  • Lossless backpressure: firehose sends wait for channel capacity instead of try_send — a silently dropped update would let a mirror consumer serve stale record state forever. A slow consumer backpressures the stream; the intended consumer is a fast in-memory map writer.
  • Existing start (subscribed mode) behavior is completely unchanged.

AccountUpdate::SlotAdvanced(slot)

Emitted in firehose mode from the slot-update arm, in-band on the same channel as Delegated/Undelegated. That ordering is the point: receiving SlotAdvanced(s) proves every record update up to slot s was already delivered, so a consumer can conclude "this mirror entry is unchanged through slot s" — the freshness proof a mirror lookup needs. An out-of-band watch channel could race ahead of undrained updates and was deliberately not used.

SyncInterrupted semantics are unchanged and still void all previously delivered state.

Laserstream pin

Pinned helius-laserstream to rev 295e8528 — the same rev the magicblock-validator workspace pins — so the validator builds a single laserstream copy once it depends on this crate. (Previously this crate tracked branch v0.2.8+conn-fix, a different head of the same fork.)

Tests

The syncer is now directly drivable in tests (LaserStream handle is optional): coverage for firehose delivery + in-band watermarks + no replay buffering, and for subscribed-mode filtering staying unchanged. 9 unit tests + doc test pass; clippy/fmt clean.

Summary by CodeRabbit

  • New Features

    • Added a firehose mode that delivers all on-chain record updates without subscriptions.
    • Added slot-advance markers to indicate when updates through a confirmed slot are complete.
    • Added lossless backpressure for reliable full-state mirroring.
    • Existing subscribed synchronization continues to support filtering and replay behavior.
  • Documentation

    • Added usage guidance for firehose mode, slot markers, backpressure, mirror-state behavior, and interruptions.

- DlpSyncer::start_firehose delivers every delegation-record update on
  chain (no per-record subscriptions, no replay buffering) with lossless
  backpressure: sends wait for channel capacity because a silently dropped
  update would let a mirror consumer serve stale state forever.
- New AccountUpdate::SlotAdvanced(slot) watermark, emitted in firehose mode
  in-band with record updates: receiving SlotAdvanced(s) proves every record
  update up to slot s was already delivered on the channel, which is what
  lets a consumer treat an unchanged mirror entry as current state.
- Subscribed mode behavior is unchanged.
- Pin helius-laserstream to the same rev as the magicblock-validator
  workspace so downstream builds compile a single laserstream copy.
- Tests cover firehose delivery + watermarks and subscribed-mode filtering
  via a directly driven syncer (LaserStream handle now optional for tests).
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@GabrielePicco, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b0889f2a-d0f1-4673-911e-70448e8204ff

📥 Commits

Reviewing files that changed from the base of the PR and between f8932e3 and 3c71985.

📒 Files selected for processing (2)
  • Cargo.toml
  • src/syncer.rs

Walkthrough

DlpSyncer now supports subscribed and firehose delivery modes. Firehose mode delivers all valid delegation updates with lossless backpressure and SlotAdvanced watermarks. Documentation, tests, and the helius-laserstream revision were updated.

Changes

Firehose delivery

Layer / File(s) Summary
Firehose contract and documentation
src/types.rs, README.md, src/lib.rs
Adds AccountUpdate::SlotAdvanced and documents firehose delivery, ordering, backpressure, mirror state, and interruption handling.
Delivery mode and stream lifecycle
Cargo.toml, src/syncer.rs
Pins helius-laserstream, adds delivery-mode selection, exposes start_firehose, and updates stream-handle ownership.
Async delivery and validation
src/syncer.rs
Makes update processing asynchronous. Firehose delivery waits for channel capacity, sends all valid delegation updates and slot watermarks, and bypasses replay buffering. Tests cover firehose and subscribed behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the new firehose delivery mode and its in-band slot watermarks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/firehose-mode

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8932e36fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/syncer.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/syncer.rs`:
- Around line 763-783: Extend
firehose_delivers_all_records_and_inband_watermarks to include a
transaction-derived undelegation update using a fixture containing an
undelegation instruction. Send that transaction through syncer.handle_update,
then assert AccountUpdate::Undelegated is received before the subsequent
SlotAdvanced watermark, while preserving the existing no-replay-buffer
assertion.
- Around line 400-407: Remove the Firehose SlotAdvanced emission from the raw
Laserstream Slot handling in the syncer update match. Do not treat the incoming
slot as a watermark; instead, only emit AccountUpdate::SlotAdvanced after
updates are buffered and ordered by slot and index, or route this behavior
through a source that guarantees the required ordering.

In `@src/types.rs`:
- Around line 37-40: Document the source-breaking nature of adding the public
AccountUpdate::SlotAdvanced variant alongside its declaration in src/types.rs.
Clearly state that exhaustive matches in downstream crates must add an arm for
SlotAdvanced, and communicate this API change through the project’s established
release or changelog documentation mechanism.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 92bcf749-ab4e-4c39-abf4-5762c36a8747

📥 Commits

Reviewing files that changed from the base of the PR and between bda219e and f8932e3.

📒 Files selected for processing (5)
  • Cargo.toml
  • README.md
  • src/lib.rs
  • src/syncer.rs
  • src/types.rs

Comment thread src/syncer.rs
Comment thread src/syncer.rs
Comment thread src/types.rs
- The stream is not slot-ordered, so a bare slot notification cannot prove
  that updates at or before it were delivered. Firehose watermarks are now
  published RESUME_SAFETY_MARGIN_SLOTS behind the observed slot, keeping
  the SlotAdvanced contract sound under the same skew bound the resume
  logic already assumes.
- Test the transaction-derived Undelegated firehose path and the no-op
  watermark inside the margin.
- Bump to 0.2.0: the SlotAdvanced variant is a source-breaking addition
  for exhaustive matchers.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c979bb0ab4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/syncer.rs
Comment thread src/syncer.rs
- The skew margin is a budget, not a proven bound. A late update landing at
  or before a published watermark now voids all delivered state via
  SyncInterrupted (after delivering the update), so consumers rebuild from
  live updates instead of trusting a broken claim. Watermarks are also
  published monotonically.
- Undelegate instructions resolve their account indexes against the full
  runtime ordering (static keys, then lookup-table loaded writable and
  readonly addresses), so versioned transactions that load the delegation
  program or record through an ALT no longer miss the Undelegated event.
- Tests cover the violation path, the monotonic no-op inside the margin,
  and an ALT-loaded undelegation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1f13ee950

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/syncer.rs
Replay resumes from the last published watermark's slot, so redelivered
updates at that slot are expected duplicates, not skew. The watermark is
reset on every re-establishment and re-arms with the next slot
notification; consumers merge watermarks monotonically, so the brief
regression is invisible to them.
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