Skip to content

fix(indexer): guard against division-by-zero on zero-rate streams#498

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
dannyy2000:fix/zero-rate-stream-division-450
May 28, 2026
Merged

fix(indexer): guard against division-by-zero on zero-rate streams#498
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
dannyy2000:fix/zero-rate-stream-division-450

Conversation

@dannyy2000
Copy link
Copy Markdown
Contributor

Summary

  • Guard handleStreamCreated and handleStreamToppedUp against RangeError: Division by zero when rate_per_second == 0
  • When ratePerSecond === 0n, skip the BigInt division entirely and store endTime as null instead of crashing
  • Zero-rate streams are a valid contract state (amount < duration → rate rounds to 0), so these events must be indexed without loss
  • Add regression test in backend/tests/soroban-event-worker.test.ts that feeds a stream_created event with rate_per_second = 0 and asserts stream + streamEvent rows are persisted without throwing
  • Fix pre-existing broadcastToAdmin missing mock in the SSE service stub

Test plan

  • Run npx vitest run tests/soroban-event-worker.test.ts — all 3 tests pass
  • Confirm zero-rate stream events are no longer dropped/rejected by the indexer
  • Confirm endTime is null in DB for zero-rate streams

Closes #450
Closes #451
Closes #452
Closes #453

Zero-rate streams (rate_per_second == 0) are a valid on-chain state when
the deposited amount is smaller than the stream duration in seconds — the
contract rounds the rate down to zero. The previous code computed endTime
via BigInt division and threw RangeError on such events, causing the handler
to reject and the stream + event to go un-indexed.

Guard both handleStreamCreated and handleStreamToppedUp: when ratePerSecond
is 0n, skip the division entirely and store endTime as null. Add a regression
test that feeds a stream_created event with rate_per_second=0 and asserts the
stream and streamEvent rows are persisted without throwing. Also fix the
pre-existing broadcastToAdmin mock gap in the SSE service stub.

Closes LabsCrypt#450 LabsCrypt#451 LabsCrypt#452 LabsCrypt#453
@ogazboiz ogazboiz merged commit d9450b7 into LabsCrypt:main May 28, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants