[Backend] Fix top-up double-write race between API handler and event indexer
Overview & Background
depositedAmount has two independent writers applying the same top-up. After topUpStream(...) returns, the API handler runs UPDATE "Stream" SET "depositedAmount" = ("depositedAmount" + $1) ... (increment). Independently the Soroban event worker's handleStreamToppedUp sets depositedAmount to the absolute on-chain value. The handler writes no TOPPED_UP event, so the worker's transactionHash_eventType dedup offers no protection. Since pollTransactionStatus confirms the tx before the handler's increment, the indexer can commit first and the handler then adds the amount on top — permanently overcounting depositedAmount and drifting endTime projections.
Technical Specification & Architecture
- Make exactly one writer authoritative:
- Option A (preferred): the indexer (
backend/src/workers/soroban-event-worker.ts:926-983) ownsdepositedAmountfrom the event; the API handler (backend/src/controllers/stream.controller.ts:709-722) only reportstxHash. - Option B: make the handler's update conditional on the event row not existing yet, inside one transaction.
- Option A (preferred): the indexer (
- If the handler must write, emit a
TOPPED_UPevent so the existing dedup key (transactionHash_eventType) covers it. - Reconcile any already-overcounted rows (one-off repair query or re-derive from event log).
Target Files
backend/src/controllers/stream.controller.tsbackend/src/workers/soroban-event-worker.tsbackend/src/services/sorobanService.ts
Acceptance Criteria
- [ ] A single top-up increments
depositedAmountexactly once regardless of indexer/API ordering. - [ ] Integration test simulating both writers arriving in both orders passes.
- [ ] Data repair plan (or migration) documented for existing overcounted streams.
@eazeeshow has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Hi maintainer, I can get this issue fixed quickly. Please assign it to me
ℹ️ Repo Maintainers: To accept this application, review their application or assign @eazeeshow to this issue.
Congratulations, @eazeeshow! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.
🧑💻 @eazeeshow: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
This issue has been completed by @eazeeshow as part of the Stellar Wave Program's 11th Wave 🥳
😎 @eazeeshow: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.