Skip to content

fix: make referral and milestone payouts atomic - #155

Open
0xQuerencia wants to merge 1 commit into
mainfrom
fix/atomic-referral-rewards-20261101
Open

0xQuerencia wants to merge 1 commit into
mainfrom
fix/atomic-referral-rewards-20261101

Conversation

@0xQuerencia

Copy link
Copy Markdown
Collaborator

Verified data-integrity defect

Referral fulfillment currently marks a referral rewarded_at before separately invoking adjust_user_pixels. If the wallet transaction fails, the referral remains claimed and can never earn the promised pixels on retry. Similarly, separate milestone count and credit operations can race when several referred projects are approved concurrently.

Fix

  • Migration 0236 adds settle_referral_reward_atomic: validates the reward, serializes per-referrer payout/milestones with a user-row lock, marks the individual referral and credits the wallet and any applicable milestone in one PostgreSQL transaction.
  • Dashboard approves/pays via the atomic RPC, and only sends notices after successful settlement.
  • PostgreSQL integration tests cover duplicate claims, concurrent milestones, and deliberately failed wallet writes which must roll back both the referral flag and balance change.
  • No change to referral eligibility, rate tiers, or milestone amounts.

Do not deploy without migration 0236. Keep open until CI, code review, and database checks are green. Production was not modified by creating this PR.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants