Skip to content

feat(tx-cache): add SSE subscription methods for transactions and orders#209

Draft
Evalir wants to merge 2 commits intomainfrom
evalir/feat/tx-cache-sse-subscriptions
Draft

feat(tx-cache): add SSE subscription methods for transactions and orders#209
Evalir wants to merge 2 commits intomainfrom
evalir/feat/tx-cache-sse-subscriptions

Conversation

@Evalir
Copy link
Member

@Evalir Evalir commented Mar 12, 2026

Description

Add subscribe_transactions() and subscribe_orders() methods to TxCache behind an sse feature flag. These connect to the /transactions/feed and /orders/feed SSE endpoints exposed by tx-pool-webservice and return typed Streams of TxEnvelope / SignedOrder that terminate on first error.

Uses eventsource-stream as a lightweight SSE parser over reqwest byte streams — no HTTP client coupling, minimal deps (futures-core, nom, pin-project-lite).

Changes

  • Workspace Cargo.toml: Add eventsource-stream = "0.2.3" to workspace deps
  • tx-cache/Cargo.toml: Add sse feature gating eventsource-stream, serde_json, and reqwest/stream
  • tx-cache/src/error.rs: Add Sse and Deserialization error variants with From impls, all behind #[cfg(feature = "sse")]
  • tx-cache/src/client.rs: Add subscribe_inner<T> generic helper and two public async methods (subscribe_transactions, subscribe_orders)

Design decisions

  • Terminate-on-error: Stream yields the error as its final item then ends — matches the existing stream_* convention. Reconnection can be layered by the consumer.
  • Feature-gated: Consumers that don't need SSE pay no dep cost.

Related Issue

Closes ENG-1987

Testing

  • Tests pass locally
  • New tests added (if applicable)
  • Clippy clean with --all-features and --no-default-features
  • cargo +nightly fmt clean

Add subscribe_transactions() and subscribe_orders() behind an \`sse\`
feature flag. These connect to the /transactions/feed and /orders/feed
SSE endpoints and return typed streams that terminate on first error.

Uses eventsource-stream as a lightweight, HTTP-client-agnostic SSE
parser over reqwest byte streams.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member Author

Evalir commented Mar 12, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Ensures HTTP error responses (404, 403, etc.) are correctly mapped
to TxCacheError variants instead of surfacing as confusing SSE
parse errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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