feat: preserve archived event states via metadata-only archiving - #1427
Merged
greatest0fallt1me merged 2 commits intoAug 29, 2026
Merged
Conversation
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>
|
@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! 🚀 |
greatest0fallt1me
merged commit Aug 29, 2026
129e21b
into
Predictify-org:master
2 of 3 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_eventoverwroteMarket.statewith theArchivedmarker, which silently destroyed the terminalResolved/Cancelledoutcome and made archived events undiscoverable by status. Now archiving (and restoring) is a metadata-only operation: amarket_id -> archived_atmarker plus a sorted index entry, with the market's ownstateleft intact.The archived market keeps its terminal
Resolved/Cancelledstate and therefore remains discoverable, while still being reported as archived viaarchived_atinEventHistoryEntryand through a new, dedicatedquery_archived_eventsview.Motivation
Market.stateconflated two concerns and forced irreversible state transitions.What changed
Core archive/restore semantics (
event_archive.rs,restore_archive.rs)archive_eventis now read-only on the market record — it records the archive marker and sorted-index entry, never setsMarket.state = Archived.is_archivedis now metadata-driven: a market is archived iff it has an archive record, with a backward-compat fallback that still treats legacy deployments whoseMarket.stateisArchivedas archived.EventArchive::unarchiveandremove_from_sorted_indexso restore removes only the metadata marker.restore_eventmirrors archiving: it validates viais_archived, callsunarchive, and no longer transitionsMarket.statetoRestored.validate_archive_consistencynow enforces capacity bounds and a corruption check for legacyArchivedmarkets that lost their archive record.New archived-event discovery
query_archived_events(reverse, cursor, limit)(inlib.rs) backed byEventArchive::query_archived_events, returning paginated entries ordered byarchived_at(ascending/descending).EventHistoryEntryso both views are coherent.Lifecycle validation (
lifecycle_validation.rs)is_archived/is_restored) instead ofMarket.state.InvalidState.State machine & exposure updates (
markets.rs,types.rs,extensions.rs,monitoring.rs,recovery.rs,lib.rs)Archived/Restoredare retained as legacy markers with no legal transitions in the state machine.extend_market) is never permitted on archived/restored markets.MarketStatusmapsArchived/RestoredtoClosed, andArchived/Restoredstringifications are added across status-reporting paths.Supporting changes
MarketIdGenerator::get_registry_entryadded to resolve a market's creation timestamp for history entries (fallback toend_timefor legacy/synthetic IDs).CannotRestoreFromStaterenumbered 444 → 447 because444was consumed byOperationWouldExceedBudget(duplicate discriminant); the off-chain error mapping gains a_ => 0catch-all.ClaimInfo::newsignature extended with the replay-safe claim nonce (0u64);gas.rscompares canonicalSymbols directly instead ofDisplay(unavailable on wasm); repaired corrupted syntax inforce_resolve.rsandstorage_tier_audit.rs;fees.rs/audit.rsminor correctness fixes.Tests
tests/archive_discoverability.rscovering:Resolvedstate and discoverability by status,query_archived_eventsordering + pagination,Files changed
contracts/predictify-hybrid/src/event_archive.rscontracts/predictify-hybrid/src/restore_archive.rscontracts/predictify-hybrid/src/lifecycle_validation.rscontracts/predictify-hybrid/src/lib.rscontracts/predictify-hybrid/src/markets.rscontracts/predictify-hybrid/src/types.rscontracts/predictify-hybrid/src/extensions.rscontracts/predictify-hybrid/src/monitoring.rscontracts/predictify-hybrid/src/recovery.rscontracts/predictify-hybrid/src/market_id_generator.rscontracts/predictify-hybrid/src/err.rscontracts/predictify-hybrid/src/force_resolve.rscontracts/predictify-hybrid/src/storage_tier_audit.rscontracts/predictify-hybrid/src/gas.rscontracts/predictify-hybrid/src/fees.rscontracts/predictify-hybrid/src/audit.rscontracts/predictify-hybrid/src/disputes.rscontracts/predictify-hybrid/tests/archive_discoverability.rs(new)