Skip to content

Commit 07bf954

Browse files
bkonturactions-userfranciscoaguirre
committed
Fix migrations for pallet-xcm (#6148)
Relates to: #4826 Relates to: #3214 `pallet-xcm` stores some operational data that uses `Versioned*` XCM types. When we add a new XCM version (XV), we deprecate XV-2 and remove XV-3. Without proper migration, this can lead to issues with [undecodable storage](https://github.com/paritytech/polkadot-sdk/actions/runs/11381324568/job/31662577532?pr=6092), as was identified on the XCMv5 branch where XCMv2 was removed. This PR extends the existing `MigrateToLatestXcmVersion` to include migration for the `Queries`, `LockedFungibles`, and `RemoteLockedFungibles` storage types. Additionally, more checks were added to `try_state` for these types. - [x] create tracking issue for `polkadot-fellows` polkadot-fellows/runtimes#492 - [x] Add missing `MigrateToLatestXcmVersion` for westend - [x] fix pallet-xcm `Queries` - fails for Westend https://github.com/paritytech/polkadot-sdk/actions/runs/11381324568/job/31662577532?pr=6092 - `V2` was removed from `Versioned*` stuff, but we have a live data with V2 e.g. Queries - e.g. Kusama or Polkadot relay chains ``` VersionNotifier: { origin: { V2: { parents: 0 interior: { X1: { Parachain: 2,124 } } } } isActive: true } ``` ![image](https://github.com/user-attachments/assets/f59f761b-46a7-4def-8aea-45c4e41c0a00) - [x] fix also for `RemoteLockedFungibles` - [x] fix also for `LockedFungibles` - [ ] deploy on Westend chains before XCMv5 - [ ] #6188 --------- Co-authored-by: command-bot <> Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]> (cherry picked from commit efd6603)
1 parent fc62793 commit 07bf954

9 files changed

Lines changed: 609 additions & 13 deletions

File tree

polkadot/runtime/westend/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,8 @@ pub mod migrations {
17051705
MaxPoolsToMigrate,
17061706
>,
17071707
pallet_staking::migrations::v15::MigrateV14ToV15<Runtime>,
1708+
// permanent
1709+
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
17081710
);
17091711
}
17101712

polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl pallet_xcm::Config for Runtime {
168168
type UniversalLocation = UniversalLocation;
169169
// No version discovery needed
170170
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
171-
type AdvertisedXcmVersion = frame::traits::ConstU32<3>;
171+
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
172172
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
173173
// No locking
174174
type TrustedLockers = ();

polkadot/xcm/docs/src/cookbook/relay_token_transactor/relay_chain/xcm_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl pallet_xcm::Config for Runtime {
142142
type UniversalLocation = UniversalLocation;
143143
// No version discovery needed
144144
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
145-
type AdvertisedXcmVersion = frame::traits::ConstU32<3>;
145+
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
146146
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
147147
// No locking
148148
type TrustedLockers = ();

polkadot/xcm/pallet-xcm/src/lib.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,44 @@ impl<T: Config> Pallet<T> {
26922692
/// set.
26932693
#[cfg(any(feature = "try-runtime", test))]
26942694
pub fn do_try_state() -> Result<(), TryRuntimeError> {
2695+
use migration::data::NeedsMigration;
2696+
2697+
// Take the minimum version between `SafeXcmVersion` and `latest - 1` and ensure that the
2698+
// operational data is stored at least at that version, for example, to prevent issues when
2699+
// removing older XCM versions.
2700+
let minimal_allowed_xcm_version = if let Some(safe_xcm_version) = SafeXcmVersion::<T>::get()
2701+
{
2702+
XCM_VERSION.saturating_sub(1).min(safe_xcm_version)
2703+
} else {
2704+
XCM_VERSION.saturating_sub(1)
2705+
};
2706+
2707+
// check `Queries`
2708+
ensure!(
2709+
!Queries::<T>::iter_values()
2710+
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
2711+
TryRuntimeError::Other("`Queries` data should be migrated to the higher xcm version!")
2712+
);
2713+
2714+
// check `LockedFungibles`
2715+
ensure!(
2716+
!LockedFungibles::<T>::iter_values()
2717+
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
2718+
TryRuntimeError::Other(
2719+
"`LockedFungibles` data should be migrated to the higher xcm version!"
2720+
)
2721+
);
2722+
2723+
// check `RemoteLockedFungibles`
2724+
ensure!(
2725+
!RemoteLockedFungibles::<T>::iter()
2726+
.any(|(key, data)| key.needs_migration(minimal_allowed_xcm_version) ||
2727+
data.needs_migration(minimal_allowed_xcm_version)),
2728+
TryRuntimeError::Other(
2729+
"`RemoteLockedFungibles` data should be migrated to the higher xcm version!"
2730+
)
2731+
);
2732+
26952733
// if migration has been already scheduled, everything is ok and data will be eventually
26962734
// migrated
26972735
if CurrentMigration::<T>::exists() {
@@ -2772,7 +2810,7 @@ impl<T: Config> xcm_executor::traits::Enact for UnlockTicket<T> {
27722810
let mut maybe_remove_index = None;
27732811
let mut locked = BalanceOf::<T>::zero();
27742812
let mut found = false;
2775-
// We could just as well do with with an into_iter, filter_map and collect, however this way
2813+
// We could just as well do with an into_iter, filter_map and collect, however this way
27762814
// avoids making an allocation.
27772815
for (i, x) in locks.iter_mut().enumerate() {
27782816
if x.1.try_as::<_>().defensive() == Ok(&self.unlocker) {
@@ -3154,7 +3192,7 @@ impl<T: Config> OnResponse for Pallet<T> {
31543192
});
31553193
return Weight::zero()
31563194
}
3157-
return match maybe_notify {
3195+
match maybe_notify {
31583196
Some((pallet_index, call_index)) => {
31593197
// This is a bit horrible, but we happen to know that the `Call` will
31603198
// be built by `(pallet_index: u8, call_index: u8, QueryId, Response)`.

0 commit comments

Comments
 (0)