Skip to content

Fix/issue referral cache invalidation - #189

Open
praizeD10 wants to merge 2 commits into
SPulse-Org:mainfrom
praizeD10:fix/issue-referral-cache-invalidation
Open

Fix/issue referral cache invalidation#189
praizeD10 wants to merge 2 commits into
SPulse-Org:mainfrom
praizeD10:fix/issue-referral-cache-invalidation

Conversation

@praizeD10

Copy link
Copy Markdown

closes #162

Problem

The prediction_market contract cached HasReferrer per bettor at first bet
and never invalidated it. A user who registered with no referrer, then
later added one, would still be treated as having no referrer — referral
fees were silently returned to the bettor instead of paid to the referrer.

Solution

  • Implemented the referral_registry contract (was empty) with credit() that
    checks Referrer storage directly on every call — no caching
  • Removed HasReferrer cache from prediction_market entirely
  • Removed DataKey::HasReferrer variant

Behavior

  • User with referrer: fee goes to referrer, referrer gets bonus points
  • User without referrer: fee returned to bettor (no loss)
  • User who adds referrer after first bet: immediately eligible for referral fees

Files Changed

  • referral_registry/src/lib.rs — full implementation (347 lines)
  • prediction_market/src/lib.rs — removed cache, always invoke credit()

Wraith Protocol Dev added 2 commits August 24, 2026 12:44
…er cache

The prediction_market contract cached HasReferrer per bettor at first bet
and never invalidated it. A user who registered with no referrer, then
later added one, would still be treated as having no referrer — referral
fees were lost.

Changes:
- Implement referral_registry contract (was empty) with credit() that
  checks Referrer storage directly on every call
- Remove HasReferrer cache from prediction_market entirely
- Remove DataKey::HasReferrer variant
- Always invoke referral contract to determine referrer status

The referral contract now handles the no-referrer case by returning the
fee to the bettor instead of sending it to the contract.

@Muyideen-js Muyideen-js 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.

@praizeD10, the PR addresses the cache invalidation issue by removing the HasReferrer cache and checking Referrer storage directly. However, there are critical issues: 1) In prediction_market, the XLM transfer to the referral contract is missing; only invoke_contract is called, so the referral fee is never sent. 2) In referral_registry's credit(), the caller (market contract) is not authenticated via require_auth, allowing unauthorized calls. 3) No tests were added to verify the new behavior. 4) CI status is missing; please provide CI results. Please fix these issues and add tests before merging.

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.

[CRITICAL] HasReferrer cache is never invalidated — referral fees permanently diverted to stale referrer

2 participants