Skip to content

perf: optimize Soroban persistent storage keys footprint - #614

Open
SINCEO2 wants to merge 2 commits into
Fundable-Protocol:mainfrom
SINCEO2:feat/issue-506-contract-optimize-soroban-persistent-storage
Open

perf: optimize Soroban persistent storage keys footprint#614
SINCEO2 wants to merge 2 commits into
Fundable-Protocol:mainfrom
SINCEO2:feat/issue-506-contract-optimize-soroban-persistent-storage

Conversation

@SINCEO2

@SINCEO2 SINCEO2 commented Aug 25, 2026

Copy link
Copy Markdown

Overview

This PR refactors the persistent storage key structures in the stream registry contract to minimize Soroban ledger footprint and reduce invocation gas fees. It introduces compact key encoding, explicit require_auth() checks, a dedicated Error enum, storage TTL management, and comprehensive Rust unit tests — following Soroban SDK best practices while preserving existing contract behavior.

Related Issue

Closes #

Changes

🔑 Storage Key Footprint Optimization

  • [MODIFY] contracts/distributor/src/lib.rs

    • Replaces verbose Symbol-only persistent storage keys with a compact StorageKey enum that uses Symbol + u32/u64 encoded components to reduce ledger entry footprint.
    • Centralizes storage key construction in StorageKey helpers and removes unnecessary allocations from key generation.
    • Adds explicit require_auth() checks on all mutating and admin functions.
    • Introduces an Error enum with Unauthorized, InvalidKey, KeyNotFound, and StorageError variants for precise failure handling.
    • Adds TTL management via extend_ttl on persistent read/write paths and a bump_contract_instance helper for contract instance storage.
    • Adds documentation comments to all public functions and storage helpers.
  • [ADD] #[cfg(test)] unit tests in contracts/distributor/src/lib.rs

    • Covers success paths, authorization failures, missing-key errors, TTL extension behavior, and key-encoding edge cases.

Verification Results

cargo build --target wasm32-unknown-unknown
✅ Build completed with zero warnings

cargo test
✅ All tests passed
Acceptance Criteria Status
Code compiles cleanly with zero warnings (cargo build --target wasm32-unknown-unknown) ✅ No warnings emitted
All unit tests pass (cargo test) ✅ All tests passed
Proper error codes defined in Error enum Unauthorized, InvalidKey, KeyNotFound, StorageError variants added
Complete documentation comments added to public functions ✅ All public functions and storage helpers documented

Closes #506

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ceca55d0-724c-4573-8fba-743dc7e77f65


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Utilitycoder

Copy link
Copy Markdown
Contributor

Thanks for the work. Please fix up the merge conflict and updated the PT. Kindly ensure you offramp with Fundable at https://stellar.fundable.finance/offramp

@Utilitycoder Utilitycoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix up the merge conflict and update your PR. Kindly ensure you offramp with Fundable at https://stellar.fundable.finance/offramp

@Utilitycoder Utilitycoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix up the merge conflict and update your PR. Kindly ensure you offramp with Fundable at https://stellar.fundable.finance/offramp

@Idrhas

Idrhas commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fix your conflicts to get PR merged, and don't forget to use https://stellar.fundable.finance for your offramps

1 similar comment
@Idrhas

Idrhas commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fix your conflicts to get PR merged, and don't forget to use https://stellar.fundable.finance for your offramps

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.

[Contract] Optimize Soroban Persistent Storage Keys Footprint

3 participants