Skip to content

feat: contract versioning, health check, session archival & batch archive#1

Open
gregemax wants to merge 5 commits into
mainfrom
feat/contract-versioning-migration
Open

feat: contract versioning, health check, session archival & batch archive#1
gregemax wants to merge 5 commits into
mainfrom
feat/contract-versioning-migration

Conversation

@gregemax
Copy link
Copy Markdown
Owner

Summary

Closes LightForgeHub#246, LightForgeHub#247, LightForgeHub#248, LightForgeHub#249


LightForgeHub#246 — Contract Versioning & Schema Migration Tooling

  • Added DataKey::ContractVersion to instance storage
  • Added migrate(new_version): admin-only, runs once per version bump, dispatches to migrations::run()
  • Added contracts/src/migrations.rs: SessionV1 struct + migrate_v1_to_v2 re-serialisation logic
  • Added contracts/src/admin.rs: admin helper re-exports
  • Unit tests: v1→v2 migration, same-version rejection

LightForgeHub#247 — Contract Health Check Endpoint

  • Added ContractStatus { version, admin, is_paused, total_sessions, active_sessions }
  • Added health_check(): read-only, no auth required
  • Added DataKey::ActiveSessionCount — incremented on start_session, decremented on all terminal transitions (Completed / Resolved)
  • Unit test: verifies all fields across session lifecycle

LightForgeHub#248 — Session Archival to Temporary Storage

  • Added contracts/src/storage.rs: write_archive / read_archive helpers with ARCHIVE_TTL_LEDGERS (~90 days at 5 s/ledger)
  • Added archive_session(session_id): admin-only, enforces 90-day post-completion delay, moves session from persistent → temporary storage, emits (session, archived) event
  • Added get_archived_session(session_id): read accessor for temporary storage
  • Unit tests: happy path, early-call rejection, active-session rejection

LightForgeHub#249 — Bulk Session Archival (Admin Batch Operation)

  • Added MAX_ARCHIVE_BATCH_SIZE = 50 constant
  • Added ArchiveSummary { archived: u32, skipped: u32 }
  • Added batch_archive_sessions(session_ids): admin-only, enforces batch cap, skips ineligible sessions without panicking, emits per-session archived events
  • Unit tests: full batch, mixed eligible/ineligible, oversized batch rejection

Testing

All 82 contract tests pass (cargo test).

gregemax added 4 commits May 31, 2026 09:33
…#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
@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented May 31, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

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.

Contract Versioning & Schema Migration Tooling

1 participant