Skip to content

Reduce instance-storage growth by moving per-vault records to persistent storage with TTL bumps #236

@1nonlypiece

Description

@1nonlypiece

📌 Description

Every DataKey::Vault(id) record in src/lib.rs is written to
env.storage().instance(). Because instance storage is loaded and re-serialized
in full on every contract invocation, storing an unbounded, ever-growing set of
vaults there makes each call progressively more expensive and risks hitting
instance-size limits as vault_count grows.

Goal: move per-vault records to persistent storage keyed by id (keeping
only small counters like VaultCount in instance storage), and bump the
entries' TTL on access so active vaults are not archived.

🎯 Requirements and Context

  • Must be tested and documented; no behavioural change to entrypoint results.
  • Migrate DataKey::Vault(id) reads/writes from instance() to persistent().
  • Add extend_ttl bumps on read/write so long-lived vaults survive state expiry.
  • Keep VaultCount (and any future admin/pause flags) in instance storage.
  • Preserve get_vault_state / vault_count semantics exactly.

🛠️ Suggested Execution

1. Fork the repo and create a branch

git checkout -b feature/persistent-vault-storage

2. Implement changes

  • Contract: update all DataKey::Vault access in src/lib.rs to persistent
    storage with TTL extension; document chosen TTL constants.
  • Tests: extend tests/lifecycle.rs to assert state survives ledger advancement
    and that reads/writes still return correct vaults.
  • Docs: add docs/STORAGE_MODEL.md explaining instance vs persistent choices and
    the gas/size rationale; cross-link from README.md.
  • Add NatSpec-style /// comments on the storage helpers.

3. Test and commit

  • Run cargo test.
  • Cover edge cases: many vaults created, read after large ledger jumps, TTL bump
    on each lifecycle transition, get_vault_state for missing id still None.

Example commit message

perf: move vault records to persistent storage with TTL extension

✅ Guidelines

  • Minimum 95% test coverage on the migrated storage paths.
  • Clear documentation of the storage model and TTL rationale.
  • No regressions on existing lifecycle and read semantics.
  • Timeframe: 96 hours.

🏷️ Labels

type-performance · area-contracts · type-refactor · MAYBE REWARDED ·
GRANTFOX OSS · OFFICIAL CAMPAIGN

💬 Community & Support

  • Join the Disciplr contributor Discord to coordinate, ask questions, and get
    unblocked fast: https://discord.gg/xvNAvMJf
  • Please introduce yourself before you start so we can avoid duplicate work,
    pair you with a reviewer, and merge your PR quickly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions