Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrations for pallet-xcm #6148

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,8 @@ pub mod migrations {
>,
parachains_shared::migration::MigrateToV1<Runtime>,
parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl pallet_xcm::Config for Runtime {
type UniversalLocation = UniversalLocation;
// No version discovery needed
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
type AdvertisedXcmVersion = frame::traits::ConstU32<3>;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
// No locking
type TrustedLockers = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl pallet_xcm::Config for Runtime {
type UniversalLocation = UniversalLocation;
// No version discovery needed
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
type AdvertisedXcmVersion = frame::traits::ConstU32<3>;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
// No locking
type TrustedLockers = ();
Expand Down
42 changes: 40 additions & 2 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,44 @@ impl<T: Config> Pallet<T> {
/// set.
#[cfg(any(feature = "try-runtime", test))]
pub fn do_try_state() -> Result<(), TryRuntimeError> {
use migration::data::NeedsMigration;

// Take the minimum version between `SafeXcmVersion` and `latest - 1` and ensure that the
// operational data is stored at least at that version, for example, to prevent issues when
// removing older XCM versions.
let minimal_allowed_xcm_version = if let Some(safe_xcm_version) = SafeXcmVersion::<T>::get()
{
XCM_VERSION.saturating_sub(1).min(safe_xcm_version)
} else {
XCM_VERSION.saturating_sub(1)
};

// check `Queries`
ensure!(
!Queries::<T>::iter_values()
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
TryRuntimeError::Other("`Queries` data should be migrated to the higher xcm version!")
);

// check `LockedFungibles`
ensure!(
!LockedFungibles::<T>::iter_values()
.any(|data| data.needs_migration(minimal_allowed_xcm_version)),
TryRuntimeError::Other(
"`LockedFungibles` data should be migrated to the higher xcm version!"
)
);

// check `RemoteLockedFungibles`
ensure!(
!RemoteLockedFungibles::<T>::iter()
.any(|(key, data)| key.needs_migration(minimal_allowed_xcm_version) ||
data.needs_migration(minimal_allowed_xcm_version)),
TryRuntimeError::Other(
"`RemoteLockedFungibles` data should be migrated to the higher xcm version!"
)
);

// if migration has been already scheduled, everything is ok and data will be eventually
// migrated
if CurrentMigration::<T>::exists() {
Expand Down Expand Up @@ -2887,7 +2925,7 @@ impl<T: Config> xcm_executor::traits::Enact for UnlockTicket<T> {
let mut maybe_remove_index = None;
let mut locked = BalanceOf::<T>::zero();
let mut found = false;
// We could just as well do with with an into_iter, filter_map and collect, however this way
// We could just as well do with an into_iter, filter_map and collect, however this way
// avoids making an allocation.
for (i, x) in locks.iter_mut().enumerate() {
if x.1.try_as::<_>().defensive() == Ok(&self.unlocker) {
Expand Down Expand Up @@ -3268,7 +3306,7 @@ impl<T: Config> OnResponse for Pallet<T> {
});
return Weight::zero()
}
return match maybe_notify {
match maybe_notify {
Some((pallet_index, call_index)) => {
// This is a bit horrible, but we happen to know that the `Call` will
// be built by `(pallet_index: u8, call_index: u8, QueryId, Response)`.
Expand Down
Loading
Loading