Skip to content

feat(contracts): add storage TTL bump calls to prevent expired persistent & instance entries (closes #7) - #23

Open
Vyacheslav-Tomashevskiy wants to merge 1 commit into
coopfinance:mainfrom
Vyacheslav-Tomashevskiy:fix/storage-ttl-bumps
Open

feat(contracts): add storage TTL bump calls to prevent expired persistent & instance entries (closes #7)#23
Vyacheslav-Tomashevskiy wants to merge 1 commit into
coopfinance:mainfrom
Vyacheslav-Tomashevskiy:fix/storage-ttl-bumps

Conversation

@Vyacheslav-Tomashevskiy

Copy link
Copy Markdown

What

Adds Soroban storage TTL bump calls across all five contracts so contribution history, vote maps and every contract's instance state are not silently evicted by the network. Closes #7.

Why

Persistent and instance storage entries in Soroban carry a time-to-live (TTL) and are deleted once it elapses unless explicitly extended. Today no extend_ttl calls exist, so on an inactive group the TreasuryContract contribution history and VotingContract vote maps — plus every contract's admin/config — can disappear.

Changes

  • bump_instance() helper in all 5 contracts (treasury, voting, loan, governance, dividend), called at the start of every state-changing entrypoint. Read-only getters intentionally do not bump — that keeps them cheap, read-only calls and avoids turning a dashboard read into a state write; any mutating call keeps instance storage alive, so an active group never loses config.
  • extend_ttl on persistent storage after every write:
    • treasury::contribute → per-member Contributions(member) history
    • voting::create_proposal and voting::vote → per-proposal Votes(id) map
  • Documented ledger counts (code comments). Stellar closes a ledger ~every 5s, so 1 day ≈ 17_280 ledgers:
    • Instance config: ~30 days (INSTANCE_BUMP_LEDGERS)
    • Persistent history / vote maps: ~90 days (PERSISTENT_BUMP_LEDGERS)
    • Threshold is set one day below the target, so a bump only pays rent when the entry is within a day of expiry rather than on every call.
  • dividend: added missing String to the imports. The crate did not compile before this PR (error[E0425]: cannot find type String), which blocked cargo test on the whole workspace; the fix was required to add bump_instance there and to satisfy the "all existing tests pass" criterion.

Acceptance criteria

  • extend_ttl called after every persistent storage write (treasury.contribute, voting.create_proposal, voting.vote)
  • Instance storage bumped at the start of every mutating #[contractimpl] method (getters excluded by design, documented)
  • Chosen ledger counts documented in comments
  • All existing tests still pass — cargo test --workspace: 21 passed, 0 failed

/claim #7

…tent & instance entries (closes coopfinance#7)

Soroban charges rent on stored entries and evicts them once their TTL
elapses unless explicitly bumped. Treasury contribution history and
voting vote maps live in persistent storage; every contract keeps its
config/state in instance storage. Without TTL bumps these are silently
deleted on an inactive group.

- Add a bump_instance() helper to all five contracts, called at the start
  of every state-changing entrypoint (read-only getters intentionally do
  not bump, keeping them cheap and write-free).
- extend_ttl on persistent storage after every write: treasury.contribute
  (per-member history) and voting.create_proposal / voting.vote (vote maps).
- Document chosen ledger counts: instance ~30d, persistent ~90d, at
  ~17280 ledgers/day (5s/ledger), threshold one day below target.
- dividend: add missing `String` to imports so the crate compiles (it did
  not build before, which blocked the whole workspace).

All existing tests pass (cargo test --workspace: 21 passed, 0 failed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

[Contracts] Add storage TTL bump calls to prevent expired persistent storage

1 participant