Skip to content

Reject Migration Downgrade (closes #877) - #922

Merged
abore9769 merged 3 commits into
abore9769:mainfrom
harmondconsultant-png:feat/877-reject-migration-downgrade
Sep 1, 2026
Merged

Reject Migration Downgrade (closes #877)#922
abore9769 merged 3 commits into
abore9769:mainfrom
harmondconsultant-png:feat/877-reject-migration-downgrade

Conversation

@harmondconsultant-png

@harmondconsultant-png harmondconsultant-png commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Closes #877.

Problem

validate_migration() already rejected targets <= current_version with MigrationError::VersionNotAdvancing, but the contract dispatcher collapsed that into a generic ValidationError - so a downgrade request failed without clearly signalling the mistake, and operators could believe a rollback occurred.

Fix

  • src/contract.rs: the dispatcher now maps MigrationError::VersionNotAdvancing to the existing unsupported-transition error (ErrorCode::IllegalTransition). A lower (or equal) target fails clearly and never silently runs zero migration steps.
  • Equal targets are likewise rejected (no-op re-requests are rejected, not silently accepted); 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 extern crate alloc (pre-existing compile errors in the test file).

Validation

  • cargo test --test migration_tests migration_downgrade ? passed.
  • Existing #[should_panic] migration rejection tests (same version / lower version / zero) still pass.

Note: Cargo.lock is intentionally untracked in this repo; a fresh resolve may need cargo update -p ed25519-dalek --precise 2.2.0 because soroban-env-host 21.2.1 declares ed25519-dalek >=2.0.0 and the resolver can otherwise pick v3, which is incompatible with its rand 0.8 usage.

)

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).
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@abore9769
abore9769 merged commit 689a3d2 into abore9769:main Sep 1, 2026
0 of 12 checks passed
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.

122. Reject Migration Downgrade

2 participants