Reject Migration Downgrade (closes #877) - #922
Merged
abore9769 merged 3 commits intoSep 1, 2026
Merged
Conversation
) validate_migration() already rejects targets <= current_version with MigrationError::VersionNotAdvancing, but the contract dispatcher collapsed that into a generic ValidationError, so a downgrade request failed without clearly signalling what went wrong. Map VersionNotAdvancing to the existing unsupported-transition error (ErrorCode::IllegalTransition) so a lower (or equal) target fails clearly and never silently runs zero migration steps. Equal targets are likewise rejected (documented as a no-op request); forward targets remain available; no rollback mechanism is added. Tests (tests/migration_tests.rs): - migration_downgrade_fails_clearly_without_partial_state: after reaching V2, a downgrade to V1 is rejected and the stored schema version / migration count are left unchanged (no partial state). - Also unblocks the suite by importing ToXdr and alloc (pre-existing compile errors in the test file).
|
@harmondconsultant-png 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 #877.
Problem
validate_migration()already rejected targets<= current_versionwithMigrationError::VersionNotAdvancing, but the contract dispatcher collapsed that into a genericValidationError- so a downgrade request failed without clearly signalling the mistake, and operators could believe a rollback occurred.Fix
src/contract.rs: the dispatcher now mapsMigrationError::VersionNotAdvancingto the existing unsupported-transition error (ErrorCode::IllegalTransition). A lower (or equal) target fails clearly and never silently runs zero migration steps.Tests (
tests/migration_tests.rs)migration_downgrade_fails_clearly_without_partial_state- after reaching V2, a downgrade to V1 is rejected and the stored schema version + migration count are left unchanged (no partial state).ToXdrandextern crate alloc(pre-existing compile errors in the test file).Validation
cargo test --test migration_tests migration_downgrade? passed.#[should_panic]migration rejection tests (same version / lower version / zero) still pass.Note:
Cargo.lockis intentionally untracked in this repo; a fresh resolve may needcargo update -p ed25519-dalek --precise 2.2.0becausesoroban-env-host 21.2.1declaresed25519-dalek >=2.0.0and the resolver can otherwise pick v3, which is incompatible with itsrand 0.8usage.