feat(contracts): add storage bump helper for recipient position looku… - #1596
Open
timiturn3r wants to merge 3 commits into
Open
timiturn3r wants to merge 3 commits into
timiturn3r wants to merge 3 commits into
Conversation
…ps (LabsCrypt#1519) - Add `bump_position_ttl(env: &Env, key: &StorageKey)` helper in `storage.rs` - Introduce `StorageKey` alias for `DataKey` in `types.rs` - Automatically extend TTL to contract max (518,400 ledgers) whenever stream positions are loaded via `try_load_stream` - Add `bump_stream_ttl` entrypoint on `StreamContract` for explicit stream TTL renewals - Add unit and integration tests verifying TTL bumps on read-only queries with mock ledger increments
…workspace dependencies
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.
Description
Soroban persistent storage entries require active TTL bumps to prevent archival into dead storage. In long-term streaming setups (e.g. 4-year vesting schedules), stream recipients and secondary position keys may remain dormant without invoking state-modifying actions like withdrawals for extended periods.
This PR adds the
bump_position_ttl(env: &Env, key: &StorageKey)storage helper incontracts/stream_contract/src/storage.rsand integrates it intotry_load_stream, ensuring that every read-only query (such as querying stream metadata, claimable balances, vesting schedules, or completion status) automatically extends the entry's persistent TTL to the contract maximum (518,400 ledgers) whenever remaining TTL falls below the renewal threshold (120,960 ledgers). It also adds a publicbump_stream_ttlentrypoint toStreamContractfor explicit on-chain renewals.Type of Change
Related Issues
Closes #1519
Changes Made
contracts/stream_contract/src/storage.rs):bump_position_ttl(env: &Env, key: &StorageKey)to extend persistent storage TTL toPERSISTENT_BUMP_AMOUNT(518,400 ledgers) withPERSISTENT_LIFETIME_THRESHOLD(120,960 ledgers).bump_position_ttlintotry_load_streamso any read-only query automatically extends TTL for existing stream positions.save_streamto usebump_position_ttl(env, &key)as the single source of truth for persistent stream TTL renewals.contracts/stream_contract/src/types.rs):pub type StorageKey = DataKey;type alias for storage keys.Streamstruct fields with the 16-field persistent storage schema.contracts/stream_contract/src/lib.rs):bump_stream_ttl(env: Env, stream_id: u64) -> Result<(), StreamError>allowing callers to explicitly bump a stream's persistent TTL.errors,events,storage,types) and importedbump_position_ttl.contracts/stream_contract/src/errors.rs):ArithmeticOverflow = 34,StreamStillActive = 35,StreamNotActive = 36.contracts/stream_contract/src/test.rs):test_querying_stream_metadata_automatically_extends_ttlwith mock ledger increments (400,000 ledgers) verifyingget_streamrestores TTL to contract max.test_all_read_only_position_queries_extend_ttlverifying TTL extensions acrossget_claimable_amount,get_vesting_schedule,get_projected_end_time, andis_stream_completed.test_bump_position_ttl_helper_directlyverifying direct helper execution, non-existent key safety, and thebump_stream_ttlcontract entrypoint.Testing
Test Coverage
Test Steps
cargo testincontracts/stream_contractto execute all 226 contract unit, integration, and property tests:cargo test