Fix Stellar payout idempotency by using payoutId as memo - #73
Open
edochieblessing09-max wants to merge 1 commit into
Open
Conversation
cybermax4200
previously approved these changes
Aug 22, 2026
cybermax4200
left a comment
Contributor
There was a problem hiding this comment.
The ci checks are failing, please kindly fix them
cybermax4200
dismissed
their stale review
August 22, 2026 05:40
The ci checks are failing, please kindly fix them
cybermax4200
requested changes
Aug 22, 2026
cybermax4200
left a comment
Contributor
There was a problem hiding this comment.
The ci checks are failing, please kindly fix them
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.
Closes #53
Description
What is the issue?
This resolves a high-priority financial-risk bug where users could accidentally receive double reward payouts. Previously,
submitRewardbuilt a Stellar payment without amemoor idempotency key. If a payout succeeded on the Stellar network but the worker crashed or the database marking transaction failed before the row could be marked asPAID, therewardPayoutSweeperwould eventually reclaim thePROCESSINGtask back toPENDING. This resulted in the same payout being submitted to the blockchain again with no pre-check to prevent duplicates.How does this fix the issue?
This PR introduces exactly-once semantics across process restarts and multiple instances by utilizing native Stellar Memos and pre-submit Horizon queries:
Deterministic Idempotency Key:
submitRewardwas updated to acceptpayoutIdas a parameter.payoutIdand attach it to the transaction as a 32-byteMemo.hash. This serves as a stable, deterministic idempotency reference.Pre-submit Idempotency Check:
userWallet's recent transactions on the Horizon network.payoutIdhash memo, it short-circuits and immediately returns the existingtxHashinstead of building a new transaction.PAIDstatus, the subsequent retry will correctly identify the payment as already complete.Acceptance Criteria Met:
payoutIdthat already has an on-chain transaction will not create a second payment.submitRewardrecords and returns a stable idempotency reference on-chain.Relevant Files Modified:
src/services/stellarService.tssrc/workers/rewardWorker.ts