Skip to content

feat: Implement Protocol State Snapshot & Rollback Framework (#227) - #232

Merged
rohan911438 merged 2 commits into
Stellar-Prex:mainfrom
Junman140:feature/state-snapshot-rollback
Jul 24, 2026
Merged

feat: Implement Protocol State Snapshot & Rollback Framework (#227)#232
rohan911438 merged 2 commits into
Stellar-Prex:mainfrom
Junman140:feature/state-snapshot-rollback

Conversation

@Junman140

Copy link
Copy Markdown
Contributor

Summary

Implements the Protocol State Snapshot & Rollback Framework as described in issue #227.

What was done

Soroban Smart Contract (\contracts/state-snapshot/)

  • New Soroban contract for on-chain snapshot management
  • Functions: \create_snapshot, \�erify_snapshot, \initiate_rollback, \list_snapshots, \get_latest_snapshot\
  • Admin-only operations with require_auth
  • SHA-256 integrity verification
  • Event emission for snapshot lifecycle (created, verified, restored)
  • Pause/unpause guard mechanism
  • Version-based snapshot ID generation (SNAP_1, SNAP_2, ...)
  • 9 comprehensive unit tests

Shared Types (\contracts/shared/src/lib.rs)

  • Added \SnapshotStatus\ enum (Created, Verified, Restored, Expired, Corrupted)
  • Added \SnapshotMetadata\ struct for versioned snapshot tracking
  • Added \SnapshotRegistryEntry\ for per-contract state hashes
  • Added event types: \SnapshotCreatedEvent, \SnapshotRestoredEvent, \SnapshotVerifiedEvent\
  • Extended \OrynError\ with 7 snapshot-specific error variants (60-66)
  • Added constants: \MAX_SNAPSHOTS, \SNAPSHOT_RETENTION_PERIOD, \SNAPSHOT_PREFIX\

Backend Model (\�ackend/src/models/StateSnapshot.js)

  • Mongoose schema for snapshot records with indexes
  • Tracks markets, liquidity pools, governance, oracle data, treasury state
  • Integrity check history and rollback history arrays
  • Contracts registry with per-contract state hashes
  • Static methods: \ indLatestVerified, \ indByVersionRange, \pruneExpired, \countByStatus\

Backend Service (\�ackend/src/services/stateSnapshotService.js)

  • \captureStateSnapshot()\ - aggregates protocol state across all modules
  • \�erifySnapshotIntegrity()\ - SHA-256 recomputation and comparison
  • \executeRollback()\ - orchestrated rollback with audit trail
  • \listSnapshots()\ - paginated listing with status/version filters
  • \getSnapshotStats()\ - dashboard statistics
  • \pruneExpiredSnapshots()\ - automatic retention cleanup
  • \startScheduledSnapshots()\ / \stopScheduledSnapshots()\ - configurable auto-scheduling

Backend Controller + Routes

  • \POST /api/snapshots\ - Capture new snapshot (admin)
  • \GET /api/snapshots\ - List snapshots with pagination
  • \GET /api/snapshots/stats\ - Snapshot statistics
  • \GET /api/snapshots/:id\ - Get snapshot by ID
  • \POST /api/snapshots/:id/verify\ - Verify integrity (admin)
  • \POST /api/snapshots/:id/rollback\ - Execute rollback (admin)
  • \POST /api/snapshots/scheduling/start|stop\ - Manage scheduling (admin)
  • \POST /api/snapshots/prune\ - Prune expired (admin)

Verification

  • Soroban contract compiles successfully for \wasm32-unknown-unknown\ target
  • Follows existing codebase patterns (Mongoose model style, service pattern, controller pattern, route pattern)
  • Model exported in \models/index.js, routes registered in \server.js\

Closes #227

…-Prex#227)

- Add SnapshotMetadata, SnapshotRegistryEntry, and snapshot events to shared types
- Create state-snapshot Soroban contract with create/verify/rollback operations
- Add StateSnapshot Mongoose model with versioning, integrity tracking, and rollback history
- Implement stateSnapshotService for orchestration across markets, liquidity, governance, oracle, treasury
- Add stateSnapshotController with REST API endpoints for CRUD, verify, rollback, scheduling
- Add stateSnapshots routes registered at /api/snapshots
- Support SHA-256 integrity verification and automated snapshot scheduling
Comment thread backend/src/services/stateSnapshotService.js
Comment thread backend/src/services/stateSnapshotService.js
data: result,
});
} catch (error) {
logger.error('Failed to verify snapshot', error);
Comment thread backend/src/controllers/stateSnapshotController.js
Comment thread backend/src/controllers/stateSnapshotController.js Fixed
Comment thread backend/src/controllers/stateSnapshotController.js Fixed
const results = {};

try {
const { Market, LiquidityPosition } = require('../models');
@rohan911438
rohan911438 merged commit f6246c1 into Stellar-Prex:main Jul 24, 2026
5 of 10 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.

Implement Protocol State Snapshot & Rollback Framework

3 participants