Summary
Implement the history migration subcommand that backfills protocol state changes within the retention window, converging with live ingestion via the shared history CAS cursor.
Scope
- CLI:
./wallet-backend protocol-migrate history --protocol-id SEP50 SEP41
- Phase 1 — Validate: Verify protocol exists,
classification_status = 'success'. Set history_migration_status = 'in_progress'. Read oldest_ledger_cursor. Initialize protocol_{ID}_history_cursor = oldest_ledger_cursor - 1.
- Phase 2 — Process batches to tip (loop): Read
latest_ledger_cursor as target. Split [cursor+1, target] into batches. Process batches sequentially (parallel comes in Task 6). Each batch commit: CAS-advance history cursor + write state changes. On CAS fail → handoff detected, exit loop. After all batches: re-read latest cursor, repeat if more ledgers; if caught up, block on RPC for next ledger (~5s).
- Phase 3 — Complete: Verify cursor at or past attempted ledger. Set
history_migration_status = 'success'. Clean up.
- Error handling: set
history_migration_status = 'failed', log error. On retry: resume from cursor + 1.
- All processed ledgers are within retention — no "process but discard" logic needed.
Dependencies
Reference
docs/feature-design/data-migrations.md (State Production section, line 619+)
Summary
Implement the history migration subcommand that backfills protocol state changes within the retention window, converging with live ingestion via the shared history CAS cursor.
Scope
./wallet-backend protocol-migrate history --protocol-id SEP50 SEP41classification_status = 'success'. Sethistory_migration_status = 'in_progress'. Readoldest_ledger_cursor. Initializeprotocol_{ID}_history_cursor = oldest_ledger_cursor - 1.latest_ledger_cursoras target. Split[cursor+1, target]into batches. Process batches sequentially (parallel comes in Task 6). Each batch commit: CAS-advance history cursor + write state changes. On CAS fail → handoff detected, exit loop. After all batches: re-read latest cursor, repeat if more ledgers; if caught up, block on RPC for next ledger (~5s).history_migration_status = 'success'. Clean up.history_migration_status = 'failed', log error. On retry: resume from cursor + 1.Dependencies
Reference
docs/feature-design/data-migrations.md(State Production section, line 619+)