Skip to content

feat(migration): add blue-green state migration - #479

Open
dedukpe wants to merge 6 commits into
TevaLabs:mainfrom
dedukpe:feat/366-blue-green-migration
Open

feat(migration): add blue-green state migration#479
dedukpe wants to merge 6 commits into
TevaLabs:mainfrom
dedukpe:feat/366-blue-green-migration

Conversation

@dedukpe

@dedukpe dedukpe commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Closes #366

Summary

Implements a blue/green contract migration path for safely moving canonical state from vN to vN+1.

What changed

  • Added canonical migration state serialization for balances, pending claims, and required configuration.
  • Added deterministic state commitment generation and on-chain commitment handling.
  • Added proof-based state import verification for the destination contract.
  • Added replay protection and once-only import handling.
  • Added claims-only drain/freeze behavior for the old contract.
  • Added off-chain witness/proof generation tooling.
  • Added simulated end-to-end migration tests.
  • Added docs/UPGRADE_BLUE_GREEN.md with the operator migration runbook.

Why

Soroban contract upgrades require a safe way to migrate persistent state without relying on unsafe or implicit storage compatibility. This provides an explicit, verifiable migration boundary between contract versions while preserving user balances and pending claims.

How verified

The migration test suite verifies:

  • Deterministic canonical state commitments.
  • Rejection of invalid and tampered proofs.
  • Replay protection.
  • Balance and pending-claim conservation.
  • Old-contract drain behavior.
  • Prevention of new rounds after freeze.
  • End-to-end source-to-destination migration.
  • Migration authorization and version checks.

Full verification:

cargo test --workspace --locked

Contract build and any required binding generation were also verified using the repository's documented workflow.

Risk & rollback

This is a security-sensitive migration feature affecting contract state and upgrade operations.

The implementation is isolated to migration/upgrade functionality and includes explicit authorization, commitment verification, replay protection, and claims-only drain behavior.

Rollback should be performed by reverting the migration implementation before deploying or activating the new migration flow. Once an on-chain migration has been finalized, operators must follow the documented migration/runbook procedures rather than attempting an ad-hoc rollback.

Screenshots

Not applicable — this change is contract, tooling, testing, and documentation focused.

dedukpe and others added 6 commits August 29, 2026 18:07
Run cargo fmt, add missing SPDX license headers, and fix clippy
warnings (-D warnings) across contracts and replay-engine crates.

Fixes:
- Format Check: reformat all Rust files with cargo fmt
- SPDX License Headers: add MIT header to 9 new test files
- Rust Tests / Code Coverage: fix clippy dead_code, unused imports,
  manual abs_diff, manual checked division, inconsistent digit grouping
- Contract Build: fix dead code and formatting in xelma-replay crate
- CI Success: gate check now passes

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Two root causes were still failing CI after the previous commit:

1. Contract Build: soroban-sdk needs the `alloc` feature to provide the
   global memory allocator for wasm32v1-none targets. Without it, the
   cdylib build fails with "no global memory allocator found".

2. Format Check: Three files (errors.rs, lib.rs, types.rs) were
   committed with CRLF line endings. The CI runs on Ubuntu where cargo
   fmt expects LF, causing a format mismatch. Fixed via
   `git add --renormalize`.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
…ailures

The merge from main (1fb35bb) introduced duplicate definitions that
broke compilation. This commit fixes:

1. errors.rs: Remove duplicate error variants that resulted from merging
   two branches' non-overlapping discriminant values. Keep the migration
   branch's clean numbering and add unique variants at new positions.
2. settlement.rs: Restore migration branch's version and remove
   duplicate void_round/finalize_round stubs from the bad merge.
3. tests/mod.rs: Remove duplicate `mod edge_cases` declaration.
4. tests/security.rs: Fix oracle heartbeat method names to match
   contract's short names (set_hb_strict_mode, arm_hb_override, etc.)
   and shorten symbol_short! strings to <= 9 chars.
5. Apply cargo fmt and fix all clippy warnings.
6. Add soroban-sdk `alloc` feature for wasm32v1-none global allocator.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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.

Upgradeability: blue/green contract migration with state export/import proofs

1 participant