Repository navigation
Conversation
|
@CathyZaks Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
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.
Header
mainfix/issue-1636-contract-define-a-ttl-policy-and-move-peProblem
In the YieldVault smart contract, no storage TTL was extended anywhere in the vault lifecycle, and all per-user state entries were stored in instance storage. Because instance storage entries share a single lifetime threshold and bump window across the entire contract, storing per-user keys (
ShareBalance,UserDeposit,LastDepositTime,PendingWithdrawal,WithdrawalQueueEntry,CheckpointTotals,UserCheckpoint, andUserBalanceAt) in instance storage introduces severe scalability and availability risks:Solution
docs/storage-ttl-policy.mddefining standard Soroban storage tiers, lifetime thresholds, bump amounts, and rationale.docs/storage-layout-reference.mdaligning contract storage documentation with the new classification.INSTANCE_LIFETIME_THRESHOLD = 17_280ledgers (~1 day),INSTANCE_BUMP_AMOUNT = 518_400ledgers (~30 days). Used strictly for core contract singleton state.PERSISTENT_LIFETIME_THRESHOLD = 120_960ledgers (~7 days),PERSISTENT_BUMP_AMOUNT = 518_400ledgers (~30 days). Used for unbounded per-user and historical checkpoint data.contracts/vault/src/lib.rs):ShareBalance(Address),UserDeposit(Address),LastDepositTime(Address),PendingWithdrawal(Address),WithdrawalQueueEntry(u64),CheckpointTotals(u32),UserCheckpoint(Address), andUserBalanceAt(UserBalanceKey).get_share_balance/set_share_balanceget_user_deposit/set_user_depositget_last_deposit_time/set_last_deposit_timeget_pending_withdrawal/set_pending_withdrawal/remove_pending_withdrawalget_withdrawal_queue_entry/set_withdrawal_queue_entry/remove_withdrawal_queue_entryget_checkpoint_totals/set_checkpoint_totalsget_user_checkpoint/set_user_checkpointget_user_balance_at/set_user_balance_atbump_instance_ttl(called during state-modifying operations)deposit,gasless_deposit,batch_deposit,withdraw,execute_withdrawal,do_withdraw,enqueue_withdrawal_for_liquidity,process_withdrawal_queue,create_checkpoint,snapshot_user_balance) to use the persistent helpers and bump instance TTL.migrate_storage):STORAGE_VERSIONfrom 3 to 4.run_storage_migrationmigrating queue entrieshead..tail, checkpoint totals1..=nonce, and staged migration users (mig_usr) from instance to persistent storage with TTL extension.stage_migration_usersandmigrate_user_storage.contracts/vault/src/proxy_tests.rs):test_ttl_policy_and_entries_survive_past_default_ttl: advances ledger sequence by 10,000 (well past default 4,096 TTL) and verifies user entries survive and read/write operations succeed with TTL renewed.test_migrate_storage_moves_instance_held_user_keys: seeds instance storage with legacy user keys, stages users, runsmigrate_storage(&4), and verifies all keys are migrated to persistent storage and deleted from instance storage.Changes by File
docs/storage-ttl-policy.mddocs/storage-layout-reference.mdcontracts/vault/src/lib.rsSTORAGE_VERSIONconstant from 3 to 4.INSTANCE_LIFETIME_THRESHOLD,INSTANCE_BUMP_AMOUNT,PERSISTENT_LIFETIME_THRESHOLD,PERSISTENT_BUMP_AMOUNT.extend_persistent_ttlcalls.pending_withdrawal,user_checkpoint,withdrawal_queue_entry,last_deposit_time.stage_migration_users,migrate_user_storage.bump_instance_ttl.run_storage_migrationto execute v4 migration of queue entries, checkpoint totals, and staged users from instance to persistent storage.contracts/vault/src/proxy_tests.rstest_storage_migration_version_guard,test_upgrade_storage_version_checkpoint,test_upgrade_storage_version_remains_monotonic_after_migration,test_migrate_storage_version_checkpoint, andtest_migrate_storage_downgrade_rejectedto storage version 4.test_ttl_policy_and_entries_survive_past_default_ttltesting ledger advance past default TTL and persistence survival.test_migrate_storage_moves_instance_held_user_keystesting thatmigrate_storagesuccessfully transfers legacy instance-held user keys to persistent storage and deletes them from instance storage.Regression Tests
test_proxy_initialization_guardcontracts/vault/src/proxy_tests.rstest_storage_migration_version_guardcontracts/vault/src/proxy_tests.rstest_upgrade_storage_version_checkpointcontracts/vault/src/proxy_tests.rstest_upgrade_storage_version_remains_monotonic_after_migrationcontracts/vault/src/proxy_tests.rstest_migrate_storage_version_checkpointcontracts/vault/src/proxy_tests.rstest_migrate_storage_downgrade_rejectedcontracts/vault/src/proxy_tests.rstest_ttl_policy_and_entries_survive_past_default_ttlcontracts/vault/src/proxy_tests.rstest_migrate_storage_moves_instance_held_user_keyscontracts/vault/src/proxy_tests.rsmigrate_storage(&4)Testing
Verification output from
git diff --stat:Verification of local commit:
Notes for Reviewers
persistent()storage with 30-day bump amounts (PERSISTENT_BUMP_AMOUNT = 518_400) and 7-day renewal thresholds (PERSISTENT_LIFETIME_THRESHOLD = 120_960).instance()storage with 30-day bump amount and 1-day threshold (INSTANCE_LIFETIME_THRESHOLD = 17_280), withbump_instance_ttlinvoked across all mutating transactions.main(incontracts/share-price-math/src/rounding.rs:8:1,contracts/vault/src/fuzz_math.rs,contracts/vault/src/timelock.rs,contracts/vault/src/strategy_registration.rs,contracts/vault/tests/operational_safety_tests.rs, andcontracts/vault/tests/reentrancy_cei_test.rs) have been documented inBLOCKED.mdand left untouched in accordance with strict scope discipline (Rule 54).Closes #1636