Skip to content

feat: add schema versioning and automatic migrate() on upgrade across all contracts (#24)#31

Open
Iwayemi-Kehinde wants to merge 3 commits into
StepFi-app:mainfrom
Iwayemi-Kehinde:main
Open

feat: add schema versioning and automatic migrate() on upgrade across all contracts (#24)#31
Iwayemi-Kehinde wants to merge 3 commits into
StepFi-app:mainfrom
Iwayemi-Kehinde:main

Conversation

@Iwayemi-Kehinde

Copy link
Copy Markdown

Summary

Closes #24

Adds an on-chain schema versioning system and automatic migration to all 6 Soroban contracts. When a contract is upgraded via upgrade(), the new WASM's migrate() is self-invoked to keep storage compatible with the new code.

Changes

All 6 contracts

  • Added SchemaVersion / SCHEMA_V storage key with CURRENT_SCHEMA_VERSION = 1
  • Added get_schema_version() / set_schema_version() storage helpers
  • Added MigrationRequired error variant to each error enum
  • Added pub fn migrate(env) — reads stored version, applies per-version migration logic, writes current version. Idempotent (safe to call multiple times)
  • Modified pub fn upgrade(env, new_wasm_hash) to self-invoke migrate() after updating WASM, using the pattern:

contracts/vendor-registry-contract

  • Added upgrade() function (was missing)
  • Added set_admin() function (was missing)
  • Added SchemaVersion variant to DataKey enum

contracts/vouching-contract

  • Added upgrade() function (was missing)
  • Added set_admin() function (was missing)
  • Added SchemaVersion variant to DataKey enum

contracts/parameters-contract

  • Added set_admin() function (was missing)

Conflict Resolution

File Resolution
parameters-contract/src/errors.rs Keep upstream's ReentrancyDetected=5, Overflow=6, Underflow=7; add MigrationRequired=8
parameters-contract/src/lib.rs Keep upstream's reentrancy guards in upgrade(), set_admin(), update_parameters(); add self-invoke migrate() after exit_non_reentrant() in upgrade()
reputation-contract/src/errors.rs Keep upstream's ReentrancyDetected=7; add MigrationRequired=8
reputation-contract/src/lib.rs Keep upstream's reentrancy guards in set_admin(), set_updater(), upgrade(); add self-invoke migrate() after exit_non_reentrant() in upgrade(); add migrate() function
vendor-registry-contract/src/errors.rs Keep upstream's ReentrancyDetected=8, Underflow=9; add MigrationRequired=10
vendor-registry-contract/src/types.rs Keep upstream's Locked variant; add SchemaVersion variant (order: Admin, Locked, SchemaVersion, Vendor(Address), VendorCount)
vouching-contract/src/errors.rs Keep upstream's ReentrancyDetected=10, Overflow=11, Underflow=12; add MigrationRequired=13

Testing

Iwayemi-Kehinde and others added 3 commits June 19, 2026 04:43
…migration in upgrade() across all 6 Soroban contracts
…rade-all-contracts

feat: add schema_version storage, migrate() functions, and automatic migration in upgrade() across all 6 Soroban contracts
@EmeditWeb

Copy link
Copy Markdown
Member

fix ci issues

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.

core: add contract storage migration utilities

2 participants