Skip to content

Extend TTL for ReferralCount/ReferralEarnings (read + write bump) - #109

Open
Phantomcall wants to merge 1 commit into
SPulse-Org:mainfrom
Phantomcall:fix/issue-73
Open

Extend TTL for ReferralCount/ReferralEarnings (read + write bump)#109
Phantomcall wants to merge 1 commit into
SPulse-Org:mainfrom
Phantomcall:fix/issue-73

Conversation

@Phantomcall

Copy link
Copy Markdown

Extend TTL for ReferralCount/ReferralEarnings (read + write bump)

Issue

Closes #73

Summary

register_referral writes ReferralCount and credit writes ReferralEarnings
to persistent storage, but neither entry ever had its TTL extended. If a
referrer was inactive for the TTL window, both entries expired and were deleted,
silently losing the referrer's historical referral record (get_referral_count
/ get_earnings would return 0).

This PR applies the same storage-lifecycle strategy already used by the
leaderboard contract: a write-bump on every set and a read-bump on
every get, keeping both counters alive for at least TTL_BUMP ledgers
(~6 months) while they are still in use.

Changes

referral_registry/src/lib.rs

  • Added the TTL constants already used by leaderboard:
    const TTL_BUMP: u32 = 3_153_600;   // ~6 months of ledgers
    const TTL_HIGH: u32 = 6_307_200;   // ~1 year of ledgers
  • register_referral: after incrementing ReferralCount(referrer), call
    env.storage().persistent().extend_ttl(&DataKey::ReferralCount(referrer), TTL_BUMP, TTL_HIGH).
  • credit: after updating ReferralEarnings(referrer), call
    extend_ttl(&DataKey::ReferralEarnings(referrer), TTL_BUMP, TTL_HIGH).
  • get_referral_count / get_earnings: after reading, call extend_ttl so
    merely querying a referrer's stats keeps their entry alive (read-bump).

referral_registry/src/tests.rs

  • Added test_referral_ttls_are_extended which asserts that ReferralCount
    and ReferralEarnings have a TTL >= TTL_BUMP after the write path and after
    a read, proving the bump happens.
  • Regenerated test_snapshots/... fixtures.

Pre-existing breakages fixed to make the suite runnable

While implementing this fix I found that main did not compile or run its own
referral_registry tests. These were unrelated to #73 but had to be resolved to
verify the change; they are called out here for transparency:

  1. setup() called leaderboard_client.set_token(...) — the leaderboard
    method was renamed to set_token_contract(...). Fixed the test helper call.
  2. register_referral invoked reward_bonus(...) on the leaderboard — that
    entry point no longer exists; the leaderboard now exposes add_bonus_pts( caller, user, pts) (points only; the welcome-bonus PULSE mint is handled by
    the leaderboard's own reward path per "Lever G"). Updated the cross-contract
    call accordingly and removed the now-unused WELCOME_BONUS_TOKENS constant.
  3. test_welcome_bonus asserted the referral contract minted 1 PULSE to the
    user
    — under the current leaderboard design the referral contract no longer
    transfers tokens on registration, so the token assertion was removed (points
    assertion retained).

Scope

In scope: ReferralCount / ReferralEarnings TTL lifecycle in
referral_registry/src/lib.rs and the accompanying test.
Out of scope: a full storage-rental/keeper redesign (tracked separately as
issue #9) — the read/write bump keeps active referrers' history alive, which is
the pragmatic fix requested here.

Acceptance Criteria

  • ReferralCount and ReferralEarnings no longer silently expire while in
    use (TTL extended on every read and write).
  • New TTL test added and passing.
  • cargo test -p referral_registry passes (16/16).

Verification

  • cargo test -p referral_registry — 16 passed; 0 failed.

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.

[MEDIUM] ReferralCount/ReferralEarnings TTLs are never extended — referral history can silently vanish

1 participant