remitwise-common provides three helper functions that centralise the canonical TTL extension policy for all contracts. Using these helpers instead of calling extend_ttl directly prevents the common mistake of swapping the threshold and bump arguments.
/// Extend the instance storage entry TTL (active data).
pub fn bump_instance(env: &Env)
/// Extend a persistent storage entry TTL.
pub fn bump_persistent<K: IntoVal<Env, Val>>(env: &Env, key: &K)
/// Extend the instance storage entry TTL using the archive window.
pub fn bump_archive(env: &Env)| Helper | Threshold constant | Bump constant | Effective window |
|---|---|---|---|
bump_instance |
INSTANCE_LIFETIME_THRESHOLD = 1 day |
INSTANCE_BUMP_AMOUNT = 30 days |
Extends to 30 days when TTL ≤ 1 day |
bump_persistent |
PERSISTENT_LIFETIME_THRESHOLD = 15 days |
PERSISTENT_BUMP_AMOUNT = 60 days |
Extends to 60 days when TTL ≤ 15 days |
bump_archive |
ARCHIVE_LIFETIME_THRESHOLD = 1 day |
ARCHIVE_BUMP_AMOUNT = 150 days |
Extends to 150 days when TTL ≤ 1 day |
The invariant threshold < bump is asserted by constant tests in remitwise-common/src/lib.rs and by the helper unit tests.
Import the helpers from remitwise-common:
use remitwise_common::{bump_instance, bump_archive, bump_persistent};Call bump_instance on every state-changing operation:
pub fn my_mutating_fn(env: Env, ...) {
// ... auth checks ...
bump_instance(&env); // keep instance alive for 30 days
// ... write storage ...
}Call bump_archive after writing to an archive map:
pub fn archive_old_transactions(env: Env, ...) {
bump_instance(&env); // active window
// ... move rows to ARCH_TX ...
bump_archive(&env); // extend to 150-day archive window
}Call bump_persistent when writing to a persistent storage key:
pub fn write_persistent_data(env: Env, key: &DataKey, value: &MyType) {
env.storage().persistent().set(key, value);
bump_persistent(&env, key);
}Each contract previously called extend_ttl directly with its own local constants. This created two risks:
- Argument swap —
extend_ttl(bump, threshold)instead ofextend_ttl(threshold, bump)silently sets a very short TTL (threshold) as the target, causing data to expire almost immediately. - Drift — local constants could diverge from the canonical values in
remitwise-common, making the effective TTL policy inconsistent across contracts.
The helpers eliminate both risks by being the single source of truth.
The helpers are tested in remitwise-common/src/lib.rs:
bump_instance_extends_instance_ttl— verifies TTL ≥INSTANCE_BUMP_AMOUNTafter callbump_archive_extends_instance_ttl_to_archive_amount— verifies TTL ≥ARCHIVE_BUMP_AMOUNTafter callbump_instance_threshold_less_than_bump_invariant— constant ordering checkbump_persistent_threshold_less_than_bump_invariant— constant ordering checkbump_archive_threshold_less_than_bump_invariant— constant ordering check
remitwise-common/src/lib.rs— helper implementations and testsSTORAGE_LAYOUT.md— per-contract TTL strategy