feat: add storage TTL bump-on-touch for all persistent keys (#19) - #67
Open
malaysiaonelove wants to merge 1 commit into
Open
feat: add storage TTL bump-on-touch for all persistent keys (#19)#67malaysiaonelove wants to merge 1 commit into
malaysiaonelove wants to merge 1 commit into
Conversation
- Add contracts/common crate with LEDGER_BUMP_PERSISTENT (535_000) and LEDGER_THRESHOLD_PERSISTENT (517_000) constants and bump_persistent() helper that wraps extend_ttl with a threshold guard to minimize fees - course-registry: bump DataKey::Course(u32) and DataKey::Progress(Address, u32) on every persistent read and write; has() guard on optional progress keys - badge-nft: bump DataKey::UserBadges(Address) on every read and write; get_badge_count and has_badge get the bump transitively via get_badges - reward-pool: bump DataKey::Spender(Address) after write in add_approved_spender and after authorized read in distribute_reward - stake-vault: bump DataKey::UserStake(Address) after read and write in stake; after read in unstake (key is then removed); has() guard in get_multiplier for non-stakers - governance: bump DataKey::Proposal(u32) and DataKey::UserVote(Address, u32) on every persistent read and write across get_proposal, cast_vote, cancel_proposal, and execute_proposal - quest-engine: bump DataKey::Quest(u32) and DataKey::Submission(Address, u32) on every persistent read and write; is_some() guard in get_quest and get_submission for missing-key paths - Add contracts/common/src/ttl_audit_test.rs with six audit tests (one per contract) that write a persistent key, advance the ledger 100,000 sequences, then assert the value is still readable (run: cargo test ttl_audit) - Update README.md with Storage TTL Semantics section documenting constants, bump-on-touch policy, covered keys table, audit test instructions, and fee considerations Closes Kqirox#19
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.
Summary
Implements Issue #19 — storage TTL handling and bump-on-touch for every persistent read/write site across all six Orivex contracts.
Changes
New:
contracts/commoncrateLEDGER_BUMP_PERSISTENT = 535_000(≈ 30 days at 5 s/ledger)LEDGER_THRESHOLD_PERSISTENT = 517_000(threshold guard to avoid redundant bumps on hot keys)bump_persistent(&env, &key)generic helper wrappingextend_ttlTTL bumps added to all 6 contracts
course-registryCourse(u32),Progress(Address, u32)create_course,update_metadata,enroll,set_course_status,is_course_finished,get_course,get_progress,transfer_ownership,complete_modulebadge-nftUserBadges(Address)mint_badge,revoke_badge,get_badges(transitively coversget_badge_count,has_badge)reward-poolSpender(Address)add_approved_spender,distribute_rewardstake-vaultUserStake(Address)stake,unstake,get_multipliergovernanceProposal(u32),UserVote(Address, u32)get_proposal,cast_vote,cancel_proposal,execute_proposalquest-engineQuest(u32),Submission(Address, u32)create_build_quest,create_explore_quest,get_quest,submit_proof,get_submission,review_submission,refund_quest,batch_review_submissions,verify_explore_questAudit test
contracts/common/src/ttl_audit_test.rs— 6 tests (one per contract) that:env.ledger().with_mut(|li| li.sequence_number += 100_000)Run with:
README
Full
Storage TTL Semanticssection added documenting constants, policy, code examples, covered-keys table, audit test instructions, and fee considerations.Fee impact
The threshold guard (
LEDGER_THRESHOLD_PERSISTENT = 517_000) means the host only writes a new TTL when the current one is genuinely close to expiry — roughly once every ≈ 25 hours on a continuously-touched key. Redundant calls are free.Closes #19