Skip to content

feat: preserve archived event states via metadata-only archiving - #1427

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
olu-cmd:Preserve_archived_event
Aug 29, 2026
Merged

feat: preserve archived event states via metadata-only archiving#1427
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
olu-cmd:Preserve_archived_event

Conversation

@olu-cmd

@olu-cmd olu-cmd commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Close #1404

Preserve Archived Event States — Non-Destructive / Metadata-Only Archiving

Summary

Changes the archived-event lifecycle so that archiving no longer mutates the stored market record. Previously archive_event overwrote Market.state with the Archived marker, which silently destroyed the terminal Resolved/Cancelled outcome and made archived events undiscoverable by status. Now archiving (and restoring) is a metadata-only operation: a market_id -> archived_at marker plus a sorted index entry, with the market's own state left intact.

The archived market keeps its terminal Resolved/Cancelled state and therefore remains discoverable, while still being reported as archived via archived_at in EventHistoryEntry and through a new, dedicated query_archived_events view.

Motivation

  • No silent data loss: archiving previously overwrote the real terminal outcome; a pruned or re-archived entry could corrupt the market's resolved state.
  • Discoverability: archived events could no longer be found by resolution status, breaking analytics/UI flows.
  • Consistency: archive/restore are lifecycle flags, not market states — carrying them on Market.state conflated two concerns and forced irreversible state transitions.

What changed

Core archive/restore semantics (event_archive.rs, restore_archive.rs)

  • archive_event is now read-only on the market record — it records the archive marker and sorted-index entry, never sets Market.state = Archived.
  • is_archived is now metadata-driven: a market is archived iff it has an archive record, with a backward-compat fallback that still treats legacy deployments whose Market.state is Archived as archived.
  • Added EventArchive::unarchive and remove_from_sorted_index so restore removes only the metadata marker.
  • restore_event mirrors archiving: it validates via is_archived, calls unarchive, and no longer transitions Market.state to Restored.
  • validate_archive_consistency now enforces capacity bounds and a corruption check for legacy Archived markets that lost their archive record.

New archived-event discovery

  • New public entrypoint query_archived_events(reverse, cursor, limit) (in lib.rs) backed by EventArchive::query_archived_events, returning paginated entries ordered by archived_at (ascending/descending).
  • Restore metadata and archive markers land on EventHistoryEntry so both views are coherent.

Lifecycle validation (lifecycle_validation.rs)

  • Validation now dispatches on the metadata flags (is_archived / is_restored) instead of Market.state.
  • Detects the corrupted "both archived and restored" state and reports it as InvalidState.
  • Dropped the now-incoherent "orphaned metadata since state isn't Archived" check.

State machine & exposure updates (markets.rs, types.rs, extensions.rs, monitoring.rs, recovery.rs, lib.rs)

  • Archived/Restored are retained as legacy markers with no legal transitions in the state machine.
  • Extension (extend_market) is never permitted on archived/restored markets.
  • MarketStatus maps Archived/Restored to Closed, and Archived/Restored stringifications are added across status-reporting paths.

Supporting changes

  • MarketIdGenerator::get_registry_entry added to resolve a market's creation timestamp for history entries (fallback to end_time for legacy/synthetic IDs).
  • Error code hygiene: CannotRestoreFromState renumbered 444 → 447 because 444 was consumed by OperationWouldExceedBudget (duplicate discriminant); the off-chain error mapping gains a _ => 0 catch-all.
  • Build/compat fixes: ClaimInfo::new signature extended with the replay-safe claim nonce (0u64); gas.rs compares canonical Symbols directly instead of Display (unavailable on wasm); repaired corrupted syntax in force_resolve.rs and storage_tier_audit.rs; fees.rs/audit.rs minor correctness fixes.

Tests

  • New integration suite tests/archive_discoverability.rs covering:
    • archiving preserves Resolved state and discoverability by status,
    • rejection of archiving non-terminal and already-archived markets (idempotency),
    • query_archived_events ordering + pagination,
    • deterministic, capacity-bounded pruning.

Files changed

  • contracts/predictify-hybrid/src/event_archive.rs
  • contracts/predictify-hybrid/src/restore_archive.rs
  • contracts/predictify-hybrid/src/lifecycle_validation.rs
  • contracts/predictify-hybrid/src/lib.rs
  • contracts/predictify-hybrid/src/markets.rs
  • contracts/predictify-hybrid/src/types.rs
  • contracts/predictify-hybrid/src/extensions.rs
  • contracts/predictify-hybrid/src/monitoring.rs
  • contracts/predictify-hybrid/src/recovery.rs
  • contracts/predictify-hybrid/src/market_id_generator.rs
  • contracts/predictify-hybrid/src/err.rs
  • contracts/predictify-hybrid/src/force_resolve.rs
  • contracts/predictify-hybrid/src/storage_tier_audit.rs
  • contracts/predictify-hybrid/src/gas.rs
  • contracts/predictify-hybrid/src/fees.rs
  • contracts/predictify-hybrid/src/audit.rs
  • contracts/predictify-hybrid/src/disputes.rs
  • contracts/predictify-hybrid/tests/archive_discoverability.rs (new)

Archiving and restoring are now non-destructive metadata operations that
leave Market.state untouched, so archived events keep their terminal
Resolved/Cancelled state and remain discoverable by status. Adds a new
query_archived_events view, metadata-driven is_archived/unarchive with
legacy back-compat, reworked lifecycle validation, and an error-code fix
(CannotRestoreFromState 444 -> 447). Includes archive discoverability
integration tests.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@olu-cmd 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 129e21b into Predictify-org:master Aug 29, 2026
2 of 3 checks passed
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.

[Quality-2][High] Preserve archived event discoverability without mutation

2 participants