Skip to content

Fix balance() reads never extending the Balance entry's TTL #120

Description

@Jagadeeshftw

📌 Description

storage.rs's module doc comment states "All persistent entries use the persistent storage with a TTL that is extended on every read/write," but get_balance in src/storage.rs only performs a plain .get() with no extend(env, &key) call — only set_balance extends. A provider whose balance is read-only for a long stretch (no provide_liquidity/withdraw_liquidity calls) could have their Balance(provider, asset) entry approach TTL expiry purely because balance()/anchor_balances() reads do not bump it, contradicting the documented policy.

🧩 Requirements and context

  • Add an extend(env, &key) call to get_balance in src/storage.rs, mirroring get_pool's read-side extend pattern.
  • Confirm anchor_balances, which calls get_balance in a loop, benefits automatically once the fix lands.
  • Add a regression test simulating a long read-only gap and asserting the entry's TTL was bumped by a balance() call.

🛠️ Suggested execution

  • Update get_balance in src/storage.rs to extend the entry's TTL on every successful read, not just on set_balance.
  • Add a src/test.rs case using the test harness's TTL/ledger-inspection utilities to assert the bump occurred after a read-only balance() call.
  • Cross-check get_min_liquidity, get_max_settlement_amount, get_asset_fee, is_fee_waived, and get_fees_accrued for the same gap (tracked in separate issues).

✅ Acceptance criteria

  • get_balance extends the Balance(provider, asset) entry's TTL on every read, matching the documented policy.
  • A regression test proves the TTL is bumped by a read-only balance()/anchor_balances() call, not just by writes.
  • Existing balance values and semantics are unchanged.

🔒 Security notes

A balance entry archived due to TTL expiry despite active read traffic is a silent data-availability risk on a fund-accounting field; fixing the read path closes the gap between the documented TTL policy and the actual implementation.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebugSomething isn't workingsecuritySecurity hardening / audit

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions