Skip to content

Add automated archival of resolved markets with storage-tier TTL management #590

@greatest0fallt1me

Description

@greatest0fallt1me

Description

Archival is manual and disconnected from the storage-tier framework. contracts/predictify-hybrid/src/event_archive.rs exposes archive_event and prune_archive (capped by MAX_ARCHIVE_SIZE), but archiving is admin-triggered per market and does not adjust storage TTLs. Meanwhile contracts/predictify-hybrid/src/storage.rs defines per-type TTL tiers (MARKET_TTL_LEDGERS, EVENT_TTL_LEDGERS, ARCHIVE_TTL_LEDGERS, a StorageTtlTier enum) and a CompressedMarket framework. This issue connects archival to the tiered TTL/compression model so resolved markets are demoted to a cheaper tier automatically.

Requirements and context

  • Archival API: EventArchiveManager::archive_event (event_archive.rs:59), prune_archive (event_archive.rs:119), MAX_ARCHIVE_SIZE, and Error::ArchiveFull.
  • Storage tiers/compression: StorageTtlTier and the TTL constants in storage.rs:10-16, plus CompressedMarket/compression config (storage.rs:46+).
  • On archival, apply the ARCHIVE_TTL_LEDGERS tier (extend/bump TTL appropriately) instead of leaving the data on the hot MARKET_TTL_LEDGERS tier; optionally trigger compression for eligible aged markets.
  • Add an admin-callable sweep that archives all markets resolved beyond a configurable age, respecting MAX_ARCHIVE_SIZE and emitting events.
  • Non-functional: bound the sweep per call (no unbounded iteration), keep idempotency (re-archiving returns the existing AlreadyClaimed/already-archived guard), and preserve historical query access.

Acceptance criteria

  • Archiving a market moves its storage to the archive TTL tier (and/or compresses it) rather than leaving it on the active tier.
  • A bounded admin sweep archives resolved markets older than a configurable threshold and stops at MAX_ARCHIVE_SIZE with Error::ArchiveFull.
  • Re-archiving an already-archived market is a no-op with the existing guard.
  • Historical queries for archived markets continue to function.
  • Tests cover tier transition, the bounded sweep, the archive-full boundary, and idempotency.
  • cargo fmt, cargo clippy, and cargo test pass.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/auto-archival-tiers.
2. Implement changescontracts/predictify-hybrid/src/event_archive.rs and contracts/predictify-hybrid/src/storage.rs; admin sweep entrypoint in contracts/predictify-hybrid/src/lib.rs.
3. Write/extend tests — extend contracts/predictify-hybrid/src/storage_layout_tests.rs and the archive tests.
4. Test and commit

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test -p predictify-hybrid
stellar contract build --verbose

Example commit message

improvement: auto-archive resolved markets into archive TTL tier

Guidelines

≥90% coverage on tier/sweep paths. Add doc-comments and update docs/contracts/EVENT_ARCHIVE.md, docs/contracts/STORAGE_LAYOUT.md, and ARCHIVE_BOUNDS_IMPLEMENTATION.md. Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GRANTFOX OSSGrantFox OSS programMAYBE REWARDEDGrantFox — potentially rewardedOFFICIAL CAMPAIGNGrantFox official campaignadvancedHigh complexity / deep contextimprovementRefactor, performance, or tech-debtperformancePerformancesmart-contractSoroban / Rust contract work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions