flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Backend] Stop persisting financial state from placeholder simulated- transactions

Open blurbeast opened this issue 2 weeks ago • 4 comments

Overview & Background

Pause, resume, and withdraw currently return hard-coded placeholder hashes (txHash: 'simulated-pause-' + streamId etc.) from simulation-only calls that never land on-chain — yet the withdraw route unconditionally mutates financial state: it increments withdrawnAmount, may flip isActive to false, and writes a WITHDRAWN StreamEvent keyed by the fake hash. Pause returns success: true while isPaused is never touched. Because every withdrawal of the same stream reuses the same placeholder hash, the upsert's update: {} silently swallows the 2nd+ WITHDRAWN events. Claimable balances and stream status become wrong.


Technical Specification & Architecture

  1. Simulation stubs must not mutate accounting:
    • backend/src/services/sorobanService.ts:524 (simulated-pause-), :557 (simulated-resume-), :589 (simulated-withdraw-) run simulateContractCall and return a mock hash.
    • backend/src/routes/v1/streams/withdraw.ts:104-133 performs the UPDATE "Stream" SET "withdrawnAmount" ... regardless; :136-153 writes the event with transactionHash: result.txHash.
  2. Choose one authoritative writer: let the indexer own withdrawnAmount/events from real on-chain events, or gate the stubs behind an explicit sandbox flag with a simulated: true response and zero DB writes.
  3. Fix the pause docstring lie in backend/src/controllers/stream.controller.ts:736-738 (claims "updates the database") and return honest state (isPaused unchanged) or implement the state change.

Target Files

  • backend/src/services/sorobanService.ts
  • backend/src/routes/v1/streams/withdraw.ts
  • backend/src/controllers/stream.controller.ts

Acceptance Criteria

  • [ ] Simulated/sandbox calls never write withdrawnAmount, isActive, or StreamEvent rows.
  • [ ] API responses from simulations are explicitly marked simulated: true and carry no fake tx hash presented as real.
  • [ ] Event upserts use real submitted tx hashes (unique per transaction).
  • [ ] Tests cover: repeated withdraw attempts cannot double-count; pause reflects true state.

blurbeast avatar Nov 18 '26 19:11 blurbeast

@DammyAji has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

Hello maintainer. I'd like to work on this issue please. I'd be sure to implement changes as described. Thank you.

ℹ️ Repo Maintainers: To accept this application, review their application or assign @DammyAji to this issue.

DammyAji avatar Nov 21 '26 12:11 DammyAji

@OlamideAdesina 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 @OlamideAdesina to this issue.

OlamideAdesina avatar Nov 21 '26 12:11 OlamideAdesina

Congratulations, @OlamideAdesina! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

🧑‍💻 @OlamideAdesina: 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 🌊

drips-wave[bot] avatar Nov 21 '26 12:11 drips-wave[bot]

This issue has been completed by @OlamideAdesina as part of the Stellar Wave Program's 11th Wave 🥳

😎 @OlamideAdesina: 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.

drips-wave[bot] avatar Nov 22 '26 09:11 drips-wave[bot]