Key duplicate-payment protection by operation, not by transaction - #177
Open
collinsezedike wants to merge 2 commits into
Open
Key duplicate-payment protection by operation, not by transaction#177collinsezedike wants to merge 2 commits into
collinsezedike wants to merge 2 commits into
Conversation
|
@collinsezedike Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@collinsezedike is attempting to deploy a commit to the determined's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
What
processed_tx(the watcher's dedup ledger) andlink_payments(the cumulative-accounting ledger from issue 1.4) both keyed uniqueness ontx_hashalone. A Stellar transaction can carry up to 100 operations, and a payment is one operation, not the whole transaction — so a second payment operation sharing a transaction with the first was silently discarded as a false duplicate, permanently: there is no re-processing path once a hash is marked done.Why
Two concrete failure modes, both silent fund loss from the seller's point of view:
underpaidforever even though the full amount arrived.paid, no webhook fires, and the payment is fully verifiable on-chain yet invisible to the app.Closes #152
How
processed_txon(tx_hash, operation_id)—operation_idis Horizon's per-operationpagingToken.WatcherStateRepository.isProcessed/markProcessedboth take it now, andwatcher-loop.tspassespayment.pagingTokenthrough.link_payments's uniqueness the same way:recordPayment'sonConflictDoNothingwas silently dropping a split payment's second operation even after theprocessed_txfix, since it enforced uniqueness ontx_hashalone too (this wasn't explicitly called out in the issue text, but the "done when" criteria don't hold without it — the cumulative-payment ledger from issue 1.4 sits directly downstream of the same bug).migrateLegacyProcessedTxTable,migrateLegacyLinkPaymentsTableindb/client.ts), notALTER TABLE ADD COLUMN— SQLite can't move a column into/out of a PRIMARY KEY, and the whole point is thattx_hashstops being unique on its own. Legacy rows getoperation_id = NULL;isProcessedtreats a NULL row as "the whole transaction was processed", preserving today's dedup behavior for anything already settled. Migrations are idempotent and no-op on a fresh database.Test plan
pnpm typecheckpnpm testpnpm buildapps/api/test/worker/watcher-loop.test.tsapps/api/test/bootstrap-migrations.test.tsstill passes (its legacylink_paymentsfixture predates theledgercolumn, which caught a real bug in my first migration draft — it assumedledgeralways existed on a legacy table)docs/FIXLOG.mdrow (BUG-152)One thing worth flagging: the FIXLOG "Fix commit" cell references this branch's current HEAD (
9650020), which won't match the final commit hash once this squash-merges. Please update that cell to the actual merge commit when you land this, same as the other rows in the table.