Skip to content

Memory-efficient streaming scan for large announcement sets #9

@truthixify

Description

@truthixify

Labels: Stellar Wave, stellar, perf, feature, drips, help-wanted
Tier: M (2–4 days)
Type: perf / feature

Context

scanAnnouncements currently takes a full array of announcements as input. For Spectre agents that have been running for months, this array can grow into the hundreds of thousands. Loading it all into memory is wasteful and breaks the agent's TEE memory budget.

We want a streaming API that can scan as the announcement stream arrives, never holding more than a small window in memory.

Scope

Add a new export scanAnnouncementsStream (Stellar first; pattern repeated per chain later):

async function* scanAnnouncementsStream(
  source: AsyncIterable<Announcement>,
  viewingKey: ...,
  spendingPubKey: ...,
  spendingKey: ...,
): AsyncGenerator<MatchedAnnouncement> { ... }

It must:

  1. Process announcements one at a time from the async iterable source.
  2. Yield matches as they're found (not in a batched array at the end).
  3. Keep peak memory bounded by O(window) where window is configurable (default 64).
  4. Support cancellation — if the consumer breaks out of the for-await loop, the stream stops cleanly.

Source providers

In the same PR, ship one source provider for Stellar:

async function* fetchAnnouncementsStream(network: Network, opts?): AsyncIterable<Announcement>

This wraps the existing paginated fetchAnnouncements and yields per page. Together they let a consumer write:

for await (const match of scanAnnouncementsStream(fetchAnnouncementsStream('stellar'), v, K, m)) {
  notify(match)
}

Acceptance criteria

  • Streaming scan implementation with tests.
  • Streaming fetch implementation with tests.
  • Memory benchmark: scanning 100k announcements with streaming must use less than 10× the memory of scanning 1k. (Numbers tunable but the property must hold.)
  • Existing scanAnnouncements becomes a thin wrapper over the streaming version (or deprecated cleanly).
  • Spectre follow-up issue filed describing the connector migration.

Why this matters

The TEE has tight memory limits. Spectre's current Stellar scan path will hit them within ~6 months of real production usage. We need to fix this before mainnet, not after.

Files

  • sdk/src/chains/stellar/scan.ts
  • sdk/src/chains/stellar/announcements.ts

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programdripsFunded via Drips NetworkfeatureNew feature workhelp wantedExtra attention is neededperfPerformance / optimizationstellarTouches Stellar / Soroban code

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions