Skip to content

[Backend] Fix indexer division-by-zero on zero-rate streams #450

@ogazboiz

Description

@ogazboiz

Join the discussion on Telegram

Why this matters

The Soroban event indexer crashes (per-event) on a legitimate on-chain state. In backend/src/workers/soroban-event-worker.ts, both handleStreamCreated and handleStreamToppedUp compute the stream end time with:

const durationSeconds = Number(BigInt(depositedAmount) / BigInt(ratePerSecond));

The contract explicitly allows rate_per_second == 0. When a sender funds a "dust" stream (amount smaller than the duration in seconds), create_stream rounds rate_per_second = net_amount / duration down to 0 — this is a tested, supported path (see test_create_stream_zero_rate in contracts/stream_contract/src/test.rs). When such a stream emits a stream_created event, BigInt(x) / 0n throws RangeError: Division by zero, the handler rejects, and the event is never indexed. Because the worker sorts stream_created first in a batch, a single zero-rate stream can also block dependent events in the same batch.

Acceptance criteria

  • Guard against ratePerSecond === 0n in handleStreamCreated and handleStreamToppedUp; when the rate is zero, store the stream without computing a finite endTime (e.g. leave endTime null or set it to startTime).
  • Ensure no streamEvent rows are lost for zero-rate streams.
  • Add a regression test in backend/tests/soroban-event-worker.test.ts that feeds a stream_created event with rate_per_second = 0 and asserts the stream + event are persisted without throwing.

Files to touch

  • backend/src/workers/soroban-event-worker.ts
  • backend/tests/soroban-event-worker.test.ts

Out of scope

  • Changing whether the contract permits zero-rate streams (tracked separately).

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksbugSomething isn't workinghigh-priorityCritical items for MVPindexerBlockchain data indexing

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