Skip to content

feat: bound recovery history and add admin prune#567

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Dopezapha:feature/recovery-history-bounds
May 27, 2026
Merged

feat: bound recovery history and add admin prune#567
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Dopezapha:feature/recovery-history-bounds

Conversation

@Dopezapha
Copy link
Copy Markdown
Contributor

Closes #556

Summary

This PR addresses Issue #556 by introducing an upper bound on retained recovery history records per market and providing an admin-gated prune entrypoint in the Predictify Hybrid Soroban contract. These improvements bound persistent storage growth and prevent high ledger rent costs over time from repeated emergency recovery actions.

Requirements & Solutions Implemented

  1. Cap Retained History: Restricted completed recovery records to a hard limit of MAX_RECOVERY_HISTORY_PER_MARKET = 100. History is automatically capped and trimmed when a resolved state is saved.
  2. Separate Active & Completed States: Split legacy combined recovery maps into separate active and history maps under recovery_records and recovery_history respectively. An automatic migration (ensure_migrated) was introduced for backward compatibility.
  3. Admin-Gated Prune Entrypoint: Added prune_recovery_history exposed in lib.rs and executed via RecoveryStorage::prune_history. It enforces administrative authorization (admin.require_auth()) and restricts batch operations to MAX_RECOVERY_PRUNE_BATCH = 30 for gas safety.
  4. Preserve Active State: Active unresolved recovery states are preserved under the active map and are never deleted by pruning actions.

Core Changes

  • contracts/predictify-hybrid/src/recovery.rs:
    • Defined bounds configurations (MAX_RECOVERY_HISTORY_PER_MARKET, MAX_RECOVERY_PRUNE_BATCH).
    • Implemented ensure_migrated for seamless backward compatibility.
    • Updated save() to store completed/resolved entries in the bounded history map and unresolved items in the active map.
    • Added the prune_history function containing authority and batch bounds logic.
    • Added comprehensive unit tests covering all required edge cases.
  • contracts/predictify-hybrid/src/lib.rs:
    • Exposed prune_recovery_history as a public admin entrypoint.

Verification & Testing

Added isolated unit tests to fully validate functionality:

  • test_recovery_history_capped_per_market: Confirms completed history truncates to exactly 100 entries.
  • test_prune_preserves_active_recovery: Assures that active unresolved recovery records remain intact after completed history pruning.
  • test_prune_count_greater_than_stored: Validates safe degradation when requested prune count exceeds stored history length.
  • test_prune_requires_admin: Confirms that unauthorized or non-admin attempts are rejected with Error::Unauthorized.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@Dopezapha 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

@greatest0fallt1me greatest0fallt1me merged commit 59e978b into Predictify-org:master May 27, 2026
1 check failed
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.

Bound recovery.rs RecoveryStorage history growth and add prune entrypoint

2 participants