Skip to content

feat(emergency): bump storage TTL on hot read paths (#709) - #1030

Open
DeePrincipal-dev-lang wants to merge 2 commits into
CalloraOrg:mainfrom
DeePrincipal-dev-lang:issue-709-emergency-ttl-bump
Open

feat(emergency): bump storage TTL on hot read paths (#709)#1030
DeePrincipal-dev-lang wants to merge 2 commits into
CalloraOrg:mainfrom
DeePrincipal-dev-lang:issue-709-emergency-ttl-bump

Conversation

@DeePrincipal-dev-lang

Copy link
Copy Markdown

feat(emergency): bump storage TTL on hot read paths — Closes #709

Problem

The callora-emergency contract exposes several read-only entrypoints (capabilities,
get_current, version, is_upgrade_authorised) that are polled frequently by monitoring tools and
off-chain clients. On Stellar/Soroban, write operations automatically extend storage TTL but
read operations do not — so a contract queried often but written rarely will gradually approach
archival, at which point reads fail until a fee is paid to restore the entry.

Solution

Add env.storage().instance().extend_ttl(INSTANCE_BUMP_THRESHOLD, INSTANCE_BUMP_AMOUNT) to all
four hot read paths. The call is a no-op when TTL is already above the threshold (common case),
so the gas overhead is minimal.

Changes

contracts/emergency/src/migrate.rs

  • Added TTL constants: LEDGERS_PER_DAY, INSTANCE_BUMP_THRESHOLD (~30 days),
    INSTANCE_BUMP_AMOUNT (~60 days), PERSISTENT_BUMP_THRESHOLD, PERSISTENT_BUMP_AMOUNT
  • Bumps instance TTL in get_current(), version(), is_upgrade_authorised()

contracts/emergency/src/views.rs

  • Added the same TTL constants
  • Bumps instance TTL in capabilities()

contracts/emergency/src/lib.rs

  • Re-exports LEDGERS_PER_DAY, INSTANCE_BUMP_THRESHOLD, INSTANCE_BUMP_AMOUNT from crate root for
    external use
  • Updated capabilities() doc comment (previously incorrectly stated "no TTL bump")
  • Wires test_ttl_bump module

contracts/emergency/src/test_ttl_bump.rs (new)

  • 11 focused tests covering every bumped path
  • Each test advances the ledger to bring TTL below threshold, calls the view, then asserts TTL
    is restored to INSTANCE_BUMP_AMOUNT
  • Includes an end-to-end archival-prevention scenario: polling alone keeps the contract alive
    past the original write-path TTL window

docs/EMERGENCY_TTL_BUMP.md (new)

  • Documents new constants, changed entrypoints, security notes, and test coverage

Cargo.toml

  • Adds contracts/emergency to workspace members so cargo test -p callora-emergency resolves

Security

  • extend_ttl never reduces TTL — only extends it
  • No new storage keys, no new auth requirements, no arithmetic
  • All four entrypoints remain no-auth pure views — no breaking API change

Testing

cargo test -p callora-emergency
closes #709

Add extend_ttl calls to all read-only entrypoints in the emergency
contract so frequently-queried deployments do not archive due to
infrequent writes.

Changes:
- contracts/emergency/src/migrate.rs: add LEDGERS_PER_DAY,
  INSTANCE_BUMP_THRESHOLD, INSTANCE_BUMP_AMOUNT,
  PERSISTENT_BUMP_THRESHOLD, PERSISTENT_BUMP_AMOUNT constants;
  bump instance TTL in get_current(), version(), is_upgrade_authorised()
- contracts/emergency/src/views.rs: add TTL constants; bump instance
  TTL in capabilities()
- contracts/emergency/src/lib.rs: re-export TTL constants from crate
  root; update capabilities() doc comment; wire test_ttl_bump module
- contracts/emergency/src/test_ttl_bump.rs: 11 focused tests covering
  every bumped read path and an end-to-end archival-prevention scenario
- docs/EMERGENCY_TTL_BUMP.md: document new constants, changed
  entrypoints, security notes, and test coverage
- Cargo.toml: add contracts/emergency to workspace members

Closes CalloraOrg#709
@drips-wave

drips-wave Bot commented Aug 5, 2026

Copy link
Copy Markdown

@DeePrincipal-dev-lang Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add TTL bump on emergency storage reads

1 participant