Skip to content

Conversation

@Krayt78
Copy link
Contributor

@Krayt78 Krayt78 commented Dec 19, 2025

Summary

This PR migrates pallet-referenda from the deprecated Currency trait with anonymous reserves to the modern fungible traits with typed holds, bumping the storage version from v1 to v2. This is part of the umbrella task #226.

Changes

Config Updates

  • Replaced Currency with NativeBalance using the new fungible traits:
    • fungible::Inspect
    • fungible::Mutate
    • fungible::Balanced
    • fungible::InspectHold
    • fungible::MutateHold
  • Added HoldReason::DecisionDeposit composite enum for tracking deposit holds with a specific reason

Storage Migration (v1 → v2)

Added MigrateV1ToV2<T, I, OldCurrency> migration that:

  1. Iterates through all existing referenda (Ongoing, Approved, Rejected, Cancelled, TimedOut)
  2. For each deposit (submission and decision deposits):
    • Unreserves the old anonymous reserved balance using the legacy ReservableCurrency trait
    • Places a new hold with HoldReason::DecisionDeposit using the new MutateHold trait
  3. Updates storage version from 1 to 2

The migration gracefully handles edge cases:

  • Skips execution if not on version 1
  • Logs warnings if unreserve is incomplete
  • Logs errors if hold placement fails
  • Properly handles Killed referenda (no deposits to migrate)
  • Includes try-runtime hooks for pre/post upgrade verification

Runtime Integration

To use this migration in your runtime:

pub type Migrations = (
    pallet_referenda::migration::v2::MigrateV1ToV2<Runtime, (), Balances>,
);

Testing

Added comprehensive test coverage:

  • migration_v1_to_v2_works - Tests full migration flow with multiple referendum types (Ongoing, Approved, TimedOut)
  • migration_v1_to_v2_skips_if_not_v1 - Verifies migration is skipped when not on version 1
  • migration_v1_to_v2_handles_killed_referendum - Tests handling of killed referenda with no deposits

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
    • External contributors: Use /cmd label <label-name> to add labels
    • Maintainers can also add labels manually
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@Krayt78 Krayt78 requested a review from a team as a code owner December 19, 2025 15:47
@Krayt78
Copy link
Contributor Author

Krayt78 commented Dec 19, 2025

/cmd label T2-pallets

@paritytech-cmd-bot-polkadot-sdk paritytech-cmd-bot-polkadot-sdk bot added the T2-pallets This PR/Issue is related to a particular pallet. label Dec 19, 2025
@Krayt78
Copy link
Contributor Author

Krayt78 commented Dec 19, 2025

There is a runtime type mismatch now
The Slash type now expects OnUnbalanced<DebtOf<Self, I>> where DebtOf is a fungible Debt (not the old NegativeImbalance).

This means we need to migrate treasury first to use Fungible before this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T2-pallets This PR/Issue is related to a particular pallet.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant