Extend TTL for ReferralCount/ReferralEarnings (read + write bump) - #109
Open
Phantomcall wants to merge 1 commit into
Open
Extend TTL for ReferralCount/ReferralEarnings (read + write bump)#109Phantomcall wants to merge 1 commit into
Phantomcall wants to merge 1 commit into
Conversation
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.
Extend TTL for
ReferralCount/ReferralEarnings(read + write bump)Issue
Closes #73
Summary
register_referralwritesReferralCountandcreditwritesReferralEarningsto 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_earningswould return0).This PR applies the same storage-lifecycle strategy already used by the
leaderboardcontract: a write-bump on everysetand a read-bump onevery
get, keeping both counters alive for at leastTTL_BUMPledgers(~6 months) while they are still in use.
Changes
referral_registry/src/lib.rsleaderboard:register_referral: after incrementingReferralCount(referrer), callenv.storage().persistent().extend_ttl(&DataKey::ReferralCount(referrer), TTL_BUMP, TTL_HIGH).credit: after updatingReferralEarnings(referrer), callextend_ttl(&DataKey::ReferralEarnings(referrer), TTL_BUMP, TTL_HIGH).get_referral_count/get_earnings: after reading, callextend_ttlsomerely querying a referrer's stats keeps their entry alive (read-bump).
referral_registry/src/tests.rstest_referral_ttls_are_extendedwhich asserts thatReferralCountand
ReferralEarningshave a TTL>= TTL_BUMPafter the write path and aftera read, proving the bump happens.
test_snapshots/...fixtures.Pre-existing breakages fixed to make the suite runnable
While implementing this fix I found that
maindid not compile or run its ownreferral_registrytests. These were unrelated to #73 but had to be resolved toverify the change; they are called out here for transparency:
setup()calledleaderboard_client.set_token(...)— the leaderboardmethod was renamed to
set_token_contract(...). Fixed the test helper call.register_referralinvokedreward_bonus(...)on the leaderboard — thatentry point no longer exists; the leaderboard now exposes
add_bonus_pts( caller, user, pts)(points only; the welcome-bonus PULSE mint is handled bythe leaderboard's own reward path per "Lever G"). Updated the cross-contract
call accordingly and removed the now-unused
WELCOME_BONUS_TOKENSconstant.test_welcome_bonusasserted the referral contract minted 1 PULSE to theuser — 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/ReferralEarningsTTL lifecycle inreferral_registry/src/lib.rsand 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
ReferralCountandReferralEarningsno longer silently expire while inuse (TTL extended on every read and write).
cargo test -p referral_registrypasses (16/16).Verification
cargo test -p referral_registry— 16 passed; 0 failed.