feat: add schema versioning and automatic migrate() on upgrade across all contracts (#24)#31
Open
Iwayemi-Kehinde wants to merge 3 commits into
Open
feat: add schema versioning and automatic migrate() on upgrade across all contracts (#24)#31Iwayemi-Kehinde wants to merge 3 commits into
Iwayemi-Kehinde wants to merge 3 commits into
Conversation
…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
Member
|
fix ci issues |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'smigrate()is self-invoked to keep storage compatible with the new code.Changes
All 6 contracts
SchemaVersion/SCHEMA_Vstorage key withCURRENT_SCHEMA_VERSION = 1get_schema_version()/set_schema_version()storage helpersMigrationRequirederror variant to each error enumpub fn migrate(env)— reads stored version, applies per-version migration logic, writes current version. Idempotent (safe to call multiple times)pub fn upgrade(env, new_wasm_hash)to self-invokemigrate()after updating WASM, using the pattern:contracts/vendor-registry-contract
upgrade()function (was missing)set_admin()function (was missing)SchemaVersionvariant toDataKeyenumcontracts/vouching-contract
upgrade()function (was missing)set_admin()function (was missing)SchemaVersionvariant toDataKeyenumcontracts/parameters-contract
set_admin()function (was missing)Conflict Resolution
parameters-contract/src/errors.rsReentrancyDetected=5, Overflow=6, Underflow=7; addMigrationRequired=8parameters-contract/src/lib.rsupgrade(),set_admin(),update_parameters(); add self-invokemigrate()afterexit_non_reentrant()inupgrade()reputation-contract/src/errors.rsReentrancyDetected=7; addMigrationRequired=8reputation-contract/src/lib.rsset_admin(),set_updater(),upgrade(); add self-invokemigrate()afterexit_non_reentrant()inupgrade(); addmigrate()functionvendor-registry-contract/src/errors.rsReentrancyDetected=8, Underflow=9; addMigrationRequired=10vendor-registry-contract/src/types.rsLockedvariant; addSchemaVersionvariant (order:Admin, Locked, SchemaVersion, Vendor(Address), VendorCount)vouching-contract/src/errors.rsReentrancyDetected=10, Overflow=11, Underflow=12; addMigrationRequired=13Testing
migrate()is idempotent: calling it twice is a no-op