The escrow contract stores a schema version constant (SCHEMA_VERSION) that is written to storage under DataKey::Version during init. This version is the single source of truth for upgrade decisions and is exposed via LiquifactEscrow::get_version.
- Never rename or delete an existing
DataKeyvariant. - Never renumber
EscrowErrordiscriminants; error codes are append‑only. - Adding new
DataKeyvariants or new contract‑type structs is safe if they are read with.get(...).unwrap_or(default)so older deployments treat missing keys as unset. - Changing the layout or XDR shape of an existing stored type (e.g., adding a required field to
InvoiceEscrow) requires either a migration path inmigrateor a full redeploy.
The migrate(from_version) entrypoint validates the stored version and returns typed errors:
| Condition | Typed error (code) |
|---|---|
stored != from_version |
MigrationVersionMismatch (90) |
from_version >= SCHEMA_VERSION |
AlreadyCurrentSchemaVersion (91) |
from_version < SCHEMA_VERSION with no path |
NoMigrationPath (92) |
When a new schema change that cannot be handled additively is introduced, implement the transformation inside migrate before returning the appropriate error and bump DataKey::Version.
upgrade is an admin‑only call that deploys a new contract WASM. After upgrading, operators must:
- Verify the stored
SCHEMA_VERSIONmatches the new contract. - If the version increased and a migration path is required, call
migratewith the previous version. - If only additive storage changes were made, no migration call is needed.
- Add new
DataKeyvariants only; never rename/delete existing ones. - Ensure all new reads use
.unwrap_or(default)for backward compatibility. - If modifying an existing stored struct, either:
- Add a migration path in
migrateand bumpSCHEMA_VERSION, or - Document that a redeploy is required.
- Add a migration path in
- Never change
EscrowErrordiscriminant values; append new errors. - Update
docs/escrow-schema-versioning.mdwith any new version details. - Add or update migration tests asserting the correct typed errors.
For a full overview see the README schema version section.