Repository navigation
Conversation
|
@PHADAR6 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! 🚀 |
PHADAR6
force-pushed
the
fix/issue-1490-make-revenue-settlement-batches-crash-safe-and
branch
from
October 21, 2026 01:39
9311105 to
a17fd96
Compare
Contributor
|
@PHADAR6 Our automated scan matched code from the PolinRider malware campaign, which steals developer credentials (GitHub, npm, wallets) and spreads through infected repositories:
What to do:
The PR will be re-scanned automatically and can be merged once it is clean. |
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.
Overview
This PR makes revenue settlement batches crash-safe and multi-instance safe by introducing an atomic claim step before payout, an outbox-style status machine (
claimed→submitted→completed/failed), and strict settlement bookkeeping. Each ledger row is linked to at most one non-failed settlement, a real payout hash is never erased, and events from terminal failures are released back to the unsettled pool so they are eventually paid exactly once.Related Issue
Changes
🔒 Atomic claim before payout
[MODIFY]
src/services/usageStore.tsmarkAsSettledis now strict: it throws when the settlement is missing, guards the update onsettlement_id IS NULL OR settlement_id = $1, and throws when the updated row count differs from the number of event ids (rolling back the transaction).FOR UPDATE SKIP LOCKED,WHERE settlement_id IS NULL), with the payout amount derived from the rows actually claimed.[ADD]
migrations/0027_settlement_claim_outbox.sqlclaimed,submitted,completed,failed.[ADD]
migrations/0027_settlement_claim_outbox.down.sql🧪 Tests
[MODIFY]
src/services/usageStore.test.tsmarkAsSettled: missing settlement throws, row-count mismatch throws and rolls back, guarded overwrite behaviour.[MODIFY]
src/__tests__/revenueSettlementService.test.tsState machine
At-most-once argument
A ledger row can only be linked to a settlement via the guarded claim (
settlement_id IS NULL), and the partial unique index prevents two non-failed settlements from referencing the same row. Claiming happens inside one short transaction that commits before any RPC call, so row locks are never held across the payout. A crash after claim but before payout leaves aclaimedsettlement with no hash, which the sweeper releases; a crash after the hash is persisted leaves asubmittedsettlement that reconciliation advances. Because a real payout hash is never cleared, a local failure after payout cannot cause the events to be re-claimed and paid again.Verification Results
stellar_tx_hashon a settlement that has oneclearTxHashpath removed; hash persisted onsubmittedrevenueSettlementService.test.tsandusageStore.test.tsnpm run db:check-migrationspasses0027up/down addednpm run lint,npm run typecheck,npm run build,npm testpassrunBatchOnce,reconcilePendingSettlementsOnce,markAsSettledCloses #1490