feat: contract versioning, health check, session archival & batch archive#1
Open
gregemax wants to merge 5 commits into
Open
feat: contract versioning, health check, session archival & batch archive#1gregemax wants to merge 5 commits into
gregemax wants to merge 5 commits into
Conversation
…#246) - Add DataKey::ContractVersion to instance storage - Add migrate(new_version) public function (admin-guarded, once-per-version) - Add migrations.rs with SessionV1 struct and migrate_v1_to_v2 logic - Add admin.rs with admin helper re-exports - Add unit tests: test_migrate_v1_to_v2 and test_migrate_same_version_is_rejected
…Hub#247) - Add ContractStatus struct { version, admin, is_paused, total_sessions, active_sessions } - Add health_check() read-only function (no auth required) - Add DataKey::ActiveSessionCount to instance storage - Increment on start_session, decrement on all terminal transitions - Add test_health_check_returns_correct_status unit test
- Add contracts/src/storage.rs with write_archive/read_archive helpers and ARCHIVE_TTL_LEDGERS (~90 days at 5s/ledger) - Add ARCHIVE_DELAY_SECS (90 days) constant to lib.rs - Add archive_session(session_id): admin-only, enforces 90-day delay, moves session from persistent to temporary storage, removes persistent entry - Add get_archived_session(session_id): reads from temporary storage - Emit (session, archived) event with session_id and archived_at timestamp - Add 3 unit tests covering happy path, early-call rejection, active-session rejection
- Add MAX_ARCHIVE_BATCH_SIZE = 50 constant
- Add ArchiveSummary { archived, skipped } contracttype struct
- Add batch_archive_sessions(session_ids): admin-only, enforces batch cap,
skips non-existent / active / too-recent sessions without panicking,
emits (session, archived) per archived session
- Add 3 unit tests: happy path, skip ineligible, oversized batch rejection
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
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.
Summary
Closes LightForgeHub#246, LightForgeHub#247, LightForgeHub#248, LightForgeHub#249
LightForgeHub#246 — Contract Versioning & Schema Migration Tooling
DataKey::ContractVersionto instance storagemigrate(new_version): admin-only, runs once per version bump, dispatches tomigrations::run()contracts/src/migrations.rs:SessionV1struct +migrate_v1_to_v2re-serialisation logiccontracts/src/admin.rs: admin helper re-exportsLightForgeHub#247 — Contract Health Check Endpoint
ContractStatus { version, admin, is_paused, total_sessions, active_sessions }health_check(): read-only, no auth requiredDataKey::ActiveSessionCount— incremented onstart_session, decremented on all terminal transitions (Completed / Resolved)LightForgeHub#248 — Session Archival to Temporary Storage
contracts/src/storage.rs:write_archive/read_archivehelpers withARCHIVE_TTL_LEDGERS(~90 days at 5 s/ledger)archive_session(session_id): admin-only, enforces 90-day post-completion delay, moves session from persistent → temporary storage, emits(session, archived)eventget_archived_session(session_id): read accessor for temporary storageLightForgeHub#249 — Bulk Session Archival (Admin Batch Operation)
MAX_ARCHIVE_BATCH_SIZE = 50constantArchiveSummary { archived: u32, skipped: u32 }batch_archive_sessions(session_ids): admin-only, enforces batch cap, skips ineligible sessions without panicking, emits per-session archived eventsTesting
All 82 contract tests pass (
cargo test).