Skip to content

[v2][contracts] Versioned storage schema and migration path for persistent structs #1227

Description

@Calebux

Context

SubscriptionData, EscrowAgreement, Card and PaymentChannel are stored directly as contracttype structs in persistent storage. Adding a field to any of them silently breaks deserialization of existing entries after an upgrade, and contract-upgrade has no story for migrating state — only for swapping WASM.

Scope

  • Add a schema_version: u32 field to every persisted struct and a StorageVersion instance key per contract.
  • Implement a migrate(from_version) entrypoint gated to admin/guardian, callable only once per version step.
  • Write read paths that accept the previous schema version and upgrade lazily on write where feasible.
  • Add tests that write v1 data, upgrade the contract, and read it back through v2 code.

Acceptance criteria

  • Every persisted struct carries a schema version.
  • Each contract exposes an admin-gated migrate() that is idempotent and rejects out-of-order versions.
  • A test creates v1 state, performs an upgrade, and asserts values survive intact.
  • contracts/DEPLOYMENT.md documents the migration procedure and the rollback constraint.

Files / areas

contracts/contracts/*/src/lib.rs, contracts/contracts/contract-upgrade/src/lib.rs, contracts/DEPLOYMENT.md


Part of the SYNCRO v2 rewrite. Epic: A — Contract foundation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarea:blockchainContracts and blockchain integrationscontractsSoroban smart contractspriority:p1High prioritysecuritySecurity vulnerability or concernv2-rewriteSYNCRO v2 rewrite program

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions