Implement donation status recovery for PENDING/FAILED transactions#34
Open
Just-Bamford wants to merge 2 commits into
Open
Implement donation status recovery for PENDING/FAILED transactions#34Just-Bamford wants to merge 2 commits into
Just-Bamford wants to merge 2 commits into
Conversation
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.
Pr Description
The
DonationsService.createDonationmethod (lines ~46-72) had a critical flaw in its idempotency handling. When a donation with an existingtxHashwas found in the database, it would immediately return the cached record without any verification of the actual on-chain status.this pr Closes #2
Concrete Impact
Stale FAILED Status During RPC Outages
verifyDonationOnChainwas called during a Stellar RPC or Horizon outage, it would store the donation with statusFAILEDFAILEDstatustxHashwould return this staleFAILEDrecordNo Recovery Mechanism
Persistent PENDING States
PENDINGstatus would never be re-checkedSolution Implementation
Core Changes
1. Idempotent Re-Verification Logic
When an existing donation is found by
txHash, the system now:Step 1: Status Check
PENDINGorFAILEDCONFIRMEDorREFUNDED, returns immediately (no re-verification needed)Step 2: Time Window Validation
Date.now() - existing.createdAt.getTime()Step 3: On-Chain Re-Verification
retryVerifyDonationmethod which:contractIdexistsstellarTxs.verifyDonationTransactionwith original parameters:txHash: Transaction hash to verifydestination: Campaign contract addressamount: Expected donation amountasset: Asset type and issueracceptedAssets: List of assets the campaign acceptsStep 4: Campaign Statistics Update
campaigns.recalculateCampaignStats(campaign.id)raisedAmountand other metrics reflect the recovered donationStep 5: Return with Recovery Flag
recovered: truestatus: CONFIRMED, recovered: falsestatus: CONFIRMED, recovered: truestatus: FAILED, recovered: false2. Idempotency Window (30 seconds)
The 30-second window serves multiple purposes:
const idempotencyWindowMs = 30_000but can be moved to environment variable3. Recovery Transparency
Added
recovered?: booleanfield toDonationResponseDto: