fix(indexer): guard against division-by-zero on zero-rate streams#498
Merged
ogazboiz merged 1 commit intoMay 28, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
handleStreamCreatedandhandleStreamToppedUpagainstRangeError: Division by zerowhenrate_per_second == 0ratePerSecond === 0n, skip the BigInt division entirely and storeendTimeasnullinstead of crashingbackend/tests/soroban-event-worker.test.tsthat feeds astream_createdevent withrate_per_second = 0and asserts stream + streamEvent rows are persisted without throwingbroadcastToAdminmissing mock in the SSE service stubTest plan
npx vitest run tests/soroban-event-worker.test.ts— all 3 tests passendTimeisnullin DB for zero-rate streamsCloses #450
Closes #451
Closes #452
Closes #453