feat: enforce semver forward-only contract upgrades#488
Open
yunus-dev-codecrafter wants to merge 1 commit into
Open
feat: enforce semver forward-only contract upgrades#488yunus-dev-codecrafter wants to merge 1 commit into
yunus-dev-codecrafter wants to merge 1 commit into
Conversation
|
@yunus-dev-codecrafter Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
closes #483
feat: enforce semver forward-only contract upgrades
Summary
Replace the flat
CONTRACT_VERSION: u32with a semver(MAJOR, MINOR, PATCH)triple and add amigrate_storageentrypoint that rejects downgrades and no-op migrations.Motivation
Previously there was no programmatic check that an upgrade does not regress major (or minor/patch) version. A deployer could accidentally migrate to an older version, corrupting storage compatibility expectations.
Changes
src/lib.rsCONTRACT_VERSION(line 368):u32 = 23→(u32, u32, u32) = (1, 0, 23). The triple avoids string parsing and makes semver ordering trivial (lexicographic tuple comparison).assert_semver_forward(from, to)(line 384): Pure helper that returns:Err(AlreadyAtTargetVersion)when versions are equalErr(MigrationDowngradeNotAllowed)when any component regressesOk(())for valid forward upgradesmigrate_storage(line 5274): New admin-only entrypoint that:DeployedVersion(defaults toCONTRACT_VERSIONif absent)assert_semver_forward(stored, target)(symbol_short!("migrate"), (from, to))eventget_version(line 5256): Return type changed to(u32, u32, u32).src/test_storage_layout_version.rsAdded 20 new tests covering:
assert_semver_forwardunit testsmigrate_storageintegrationsrc/structured_error_tests.rsUpdated the const assertion for the new triple format (
CONTRACT_VERSION.0 >= 1).Removed
src/test_security_doc_sync.rs— orphan test file referencing a nonexistentget_security_doc_syncfunction (never compiled).Error reuse
No new wire-level error discriminants were added. The helper reuses:
to == fromAlreadyAtTargetVersion(32)to < fromMigrationDowngradeNotAllowed(33)Security
migrate_storagerequiresadmin.require_auth()via Soroban host authrequire_not_frozencheck prevents migration on a frozen contractTesting
assert_semver_forwardis tested as a pure function with all 6 branch outcomesmigrate_storageis integration-tested with scenarios covering initialization state, auth, frozen state, and every upgrade/downgrade directionget_versionandstorage_layout_versiontests continue to pass