Skip to content

fix(leaderboard): manage instance storage TTL lifecycle - #111

Open
MJ-RWA wants to merge 3 commits into
SPulse-Org:mainfrom
MJ-RWA:fix/leaderboard-instance-ttl
Open

fix(leaderboard): manage instance storage TTL lifecycle#111
MJ-RWA wants to merge 3 commits into
SPulse-Org:mainfrom
MJ-RWA:fix/leaderboard-instance-ttl

Conversation

@MJ-RWA

@MJ-RWA MJ-RWA commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Fix the leaderboard's instance-storage TTL lifecycle so cached state such as MinPoints and MinSlot does not silently expire without an appropriate refresh strategy.

The leaderboard currently stores core state in Soroban instance storage without explicitly managing its TTL. After prolonged inactivity, this can cause cached values to expire and potentially leave subsequent leaderboard updates operating with missing/default state.

Problem

MinPoints and MinSlot are stored in instance storage, but their TTL lifecycle was not being managed.

When the instance-storage TTL expires, the cached minimum can be lost. A subsequent leaderboard update may then observe the missing value as the default u64::MAX and trigger the minimum-recomputation path unexpectedly.

Because this state participates in leaderboard insertion and displacement decisions, TTL expiration can become a latent trigger for incorrect leaderboard behavior.

The same lifecycle concern also applies to other relevant instance-storage entries, so the fix addresses the storage lifecycle consistently rather than adding a narrowly scoped workaround for MinPoints alone.

What Changed

  • Added appropriate TTL lifecycle management for the leaderboard's relevant instance-storage state.
  • Ensured MinPoints and MinSlot are covered by the storage lifecycle strategy.
  • Evaluated other instance-storage keys and handled them consistently where required.
  • Reused the repository's existing storage/TTL patterns where applicable.
  • Added or updated regression coverage for the affected storage lifecycle.
  • Preserved existing leaderboard ranking and mutation behavior.
  • Avoided unrelated refactoring and changes outside the issue scope.

Root Cause

The leaderboard relied on instance-storage values without explicitly managing their TTL lifecycle.

Soroban instance storage is subject to TTL expiration, meaning contract inactivity can cause cached instance state to disappear. The leaderboard's subsequent fallback behavior can then operate on missing cache state and trigger incorrect minimum handling.

The fix addresses the underlying TTL lifecycle rather than treating the resulting MinPoints value as an isolated cache bug.

Testing & Verification

The implementation was verified against the repository's applicable quality checks, including:

  • Targeted leaderboard tests
  • Relevant contract tests
  • Regression coverage for instance-storage TTL behavior
  • Formatting checks
  • Clippy/lint checks
  • Build/type checks where applicable
  • Repository CI-equivalent checks where available
  • Final Git diff review

Acceptance Criteria

  • Instance-storage TTL lifecycle is explicitly addressed.
  • MinPoints is protected from unintended TTL expiration.
  • MinSlot is protected from unintended TTL expiration.
  • Other relevant instance-storage keys were evaluated.
  • The solution follows the repository's existing architecture and conventions.
  • Regression tests cover the affected behavior.
  • Existing leaderboard behavior remains unchanged.
  • No unrelated refactoring was introduced.
  • Final changes were reviewed for accidental or unrelated modifications.
  • The implementation is ready for maintainer review.

Scope

This PR is intentionally limited to the leaderboard instance-storage TTL lifecycle issue. It does not attempt to redesign the leaderboard's ranking algorithm or address unrelated leaderboard issues.

Review Notes

The implementation should be reviewed with particular attention to:

  1. The selected instance-storage TTL refresh strategy.
  2. Coverage of all relevant leaderboard instance-storage keys.
  3. TTL/gas implications.
  4. Regression coverage for expired or near-expiry storage.
  5. Compatibility with the existing Soroban storage architecture.

Closes: #66

@MJ-RWA

MJ-RWA commented Aug 18, 2026

Copy link
Copy Markdown
Author

@Muyideen-js PR ready

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.

[MEDIUM] MinPoints/MinSlot are stored in instance storage with no TTL extension — the leaderboard's core cache can expire

1 participant