Skip to content

feat: add storage TTL bump to prevent persistent/instance data expiration (Closes #7) - #25

Open
ney9320 wants to merge 1 commit into
coopfinance:mainfrom
ney9320:feat/issue-7-storage-ttl-bump
Open

feat: add storage TTL bump to prevent persistent/instance data expiration (Closes #7)#25
ney9320 wants to merge 1 commit into
coopfinance:mainfrom
ney9320:feat/issue-7-storage-ttl-bump

Conversation

@ney9320

@ney9320 ney9320 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Add storage TTL bump calls to all 5 Soroban contracts to prevent persistent and instance storage from expiring on the Stellar network.

Closes #7

Changes

All 5 contracts (treasury, voting, loan, governance, dividend)

  • Add TTL constants: LEDGERS_PER_DAY, INSTANCE_TTL_THRESHOLD (30 days), INSTANCE_TTL_EXTEND_TO (180 days)
  • Add bump_instance() helper that calls env.storage().instance().extend_ttl()
  • Call bump_instance() at the start of every state-changing function

Treasury contract (has persistent storage)

  • Add extend_ttl() on DataKey::Contributions(member) after each persistent write in contribute()
  • Bump instance TTL in: initialize, add_member, contribute, withdraw

Voting contract (has persistent storage)

  • Add extend_ttl() on DataKey::Votes(proposal_id) after writes in create_proposal() and vote()
  • Bump instance TTL in: initialize, create_proposal, vote, finalize

Loan, Governance, Dividend (instance storage only)

  • Bump instance TTL in all state-changing functions

TTL Design Decisions

Parameter Value Rationale
Ledgers per day 17,280 ~5s ledger close time
Threshold 30 days Only extend when below this, avoids unnecessary writes
Extend to 180 days ~6 months, balances cost vs safety

Testing

All 21 existing treasury contract tests pass:

test result: ok. 21 passed; 0 failed; 0 ignored

No changes to test behavior — TTL calls are no-ops in the mock test environment (Env::default()).

…tion

Add bump_instance() to all 5 contracts (treasury, voting, loan, governance,
dividend) that extends instance storage TTL at the start of every
state-changing function.

For treasury and voting contracts which use persistent storage:
- Add extend_ttl() after contribution history writes in treasury::contribute()
- Add extend_ttl() after vote map writes in voting::create_proposal() and
  voting::vote()

TTL values (documented in-code):
- Instance: threshold 30 days, extend to 180 days
- Persistent: threshold 30 days, extend to 180 days
- Based on approx 5s ledger close time (~17,280 ledgers/day)

Closes coopfinance#7
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