Skip to content

Commit 807dc3b

Browse files
bkonturactions-userfranciscoaguirre
authored andcommitted
Fix migrations for pallet-xcm (paritytech#6148)
Relates to: paritytech#4826 Relates to: paritytech#3214 ## Description `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. ## TODO - [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` ## Follow-ups - [ ] deploy on Westend chains before XCMv5 - [ ] paritytech#6188 --------- Co-authored-by: command-bot <> Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]>
1 parent 5482b6b commit 807dc3b

10 files changed

Lines changed: 610 additions & 14 deletions

File tree

polkadot/runtime/westend/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,8 @@ pub mod migrations {
18091809
>,
18101810
parachains_shared::migration::MigrateToV1<Runtime>,
18111811
parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
1812+
// permanent
1813+
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
18121814
);
18131815
}
18141816

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
@@ -2807,6 +2807,44 @@ impl<T: Config> Pallet<T> {
28072807
/// set.
28082808
#[cfg(any(feature = "try-runtime", test))]
28092809
pub fn do_try_state() -> Result<(), TryRuntimeError> {
2810+
use migration::data::NeedsMigration;
2811+
2812+
// Take the minimum version between `SafeXcmVersion` and `latest - 1` and ensure that the
2813+
// operational data is stored at least at that version, for example, to prevent issues when
2814+
// removing older XCM versions.
2815+
let minimal_allowed_xcm_version = if let Some(safe_xcm_version) = SafeXcmVersion::<T>::get()
2816+
{
2817+
XCM_VERSION.saturating_sub(1).min(safe_xcm_version)
2818+
} else {
2819+
XCM_VERSION.saturating_sub(1)
2820+
};
2821+
2822+
// check `Queries`
2823+
ensure!(
2824+
!Queries::<T>::iter_values()
2825+
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
2826+
TryRuntimeError::Other("`Queries` data should be migrated to the higher xcm version!")
2827+
);
2828+
2829+
// check `LockedFungibles`
2830+
ensure!(
2831+
!LockedFungibles::<T>::iter_values()
2832+
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
2833+
TryRuntimeError::Other(
2834+
"`LockedFungibles` data should be migrated to the higher xcm version!"
2835+
)
2836+
);
2837+
2838+
// check `RemoteLockedFungibles`
2839+
ensure!(
2840+
!RemoteLockedFungibles::<T>::iter()
2841+
.any(|(key, data)| key.needs_migration(minimal_allowed_xcm_version) ||
2842+
data.needs_migration(minimal_allowed_xcm_version)),
2843+
TryRuntimeError::Other(
2844+
"`RemoteLockedFungibles` data should be migrated to the higher xcm version!"
2845+
)
2846+
);
2847+
28102848
// if migration has been already scheduled, everything is ok and data will be eventually
28112849
// migrated
28122850
if CurrentMigration::<T>::exists() {
@@ -2887,7 +2925,7 @@ impl<T: Config> xcm_executor::traits::Enact for UnlockTicket<T> {
28872925
let mut maybe_remove_index = None;
28882926
let mut locked = BalanceOf::<T>::zero();
28892927
let mut found = false;
2890-
// We could just as well do with with an into_iter, filter_map and collect, however this way
2928+
// We could just as well do with an into_iter, filter_map and collect, however this way
28912929
// avoids making an allocation.
28922930
for (i, x) in locks.iter_mut().enumerate() {
28932931
if x.1.try_as::<_>().defensive() == Ok(&self.unlocker) {
@@ -3268,7 +3306,7 @@ impl<T: Config> OnResponse for Pallet<T> {
32683306
});
32693307
return Weight::zero()
32703308
}
3271-
return match maybe_notify {
3309+
match maybe_notify {
32723310
Some((pallet_index, call_index)) => {
32733311
// This is a bit horrible, but we happen to know that the `Call` will
32743312
// be built by `(pallet_index: u8, call_index: u8, QueryId, Response)`.

0 commit comments

Comments
 (0)