From 1637992b4f3af72d8f53159d0dd2b1aea0895410 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 10 Oct 2023 11:44:22 +0300 Subject: [PATCH 01/14] XCMP Queue: cleanup QueueConfigData --- cumulus/pallets/xcmp-queue/src/lib.rs | 21 +- cumulus/pallets/xcmp-queue/src/migration.rs | 204 ++++++++++++++++---- 2 files changed, 172 insertions(+), 53 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index d687f83d8b3e..bf67b5f61bff 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -60,7 +60,7 @@ use cumulus_primitives_core::{ use frame_support::{ defensive, defensive_assert, traits::{EnqueueMessage, EnsureOrigin, Get, QueueFootprint, QueuePausedQuery}, - weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight, WeightMeter}, + weights::{Weight, WeightMeter}, BoundedVec, }; use pallet_message_queue::OnQueueChanged; @@ -387,18 +387,6 @@ pub struct QueueConfigData { /// The number of pages which the queue must be reduced to before it signals that /// message sending may recommence after it has been suspended. resume_threshold: u32, - /// UNUSED - The amount of remaining weight under which we stop processing messages. - #[deprecated(note = "Will be removed")] - threshold_weight: Weight, - /// UNUSED - The speed to which the available weight approaches the maximum weight. A lower - /// number results in a faster progression. A value of 1 makes the entire weight available - /// initially. - #[deprecated(note = "Will be removed")] - weight_restrict_decay: Weight, - /// UNUSED - The maximum amount of weight any individual message may consume. Messages above - /// this weight go into the overweight queue and may only be serviced explicitly. - #[deprecated(note = "Will be removed")] - xcmp_max_individual_weight: Weight, } impl Default for QueueConfigData { @@ -410,13 +398,6 @@ impl Default for QueueConfigData { drop_threshold: 48, // 64KiB * 48 = 3MiB suspend_threshold: 32, // 64KiB * 32 = 2MiB resume_threshold: 8, // 64KiB * 8 = 512KiB - // unused: - threshold_weight: Weight::from_parts(100_000, 0), - weight_restrict_decay: Weight::from_parts(2, 0), - xcmp_max_individual_weight: Weight::from_parts( - 20u64 * WEIGHT_REF_TIME_PER_MILLIS, - DEFAULT_POV_SIZE, - ), } } } diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 6d7f434b041a..22f89f875d3c 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -16,7 +16,9 @@ //! A module that is responsible for migration of storage. -use crate::{Config, OverweightIndex, Pallet, ParaId, QueueConfig, DEFAULT_POV_SIZE}; +use crate::{ + Config, OverweightIndex, Pallet, ParaId, QueueConfig, QueueConfigData, DEFAULT_POV_SIZE, +}; use cumulus_primitives_core::XcmpMessageFormat; use frame_support::{ pallet_prelude::*, @@ -48,6 +50,12 @@ impl OnRuntimeUpgrade for MigrationToV3 { weight.saturating_accrue(T::DbWeight::get().writes(1)); } + if StorageVersion::get::>() == 3 { + weight.saturating_accrue(migrate_to_v4::()); + StorageVersion::new(4).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } + weight } } @@ -56,6 +64,9 @@ mod v1 { use super::*; use codec::{Decode, Encode}; + #[frame_support::storage_alias] + pub(crate) type QueueConfig = StorageValue, QueueConfigData, ValueQuery>; + #[derive(Encode, Decode, Debug)] pub struct QueueConfigData { pub suspend_threshold: u32, @@ -80,6 +91,76 @@ mod v1 { } } +mod v2 { + use super::*; + + #[frame_support::storage_alias] + pub(crate) type QueueConfig = StorageValue, QueueConfigData, ValueQuery>; + + #[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] + pub struct QueueConfigData { + pub suspend_threshold: u32, + pub drop_threshold: u32, + pub resume_threshold: u32, + #[deprecated(note = "Will be removed")] + pub threshold_weight: Weight, + #[deprecated(note = "Will be removed")] + pub weight_restrict_decay: Weight, + #[deprecated(note = "Will be removed")] + pub xcmp_max_individual_weight: Weight, + } + + impl Default for QueueConfigData { + fn default() -> Self { + #![allow(deprecated)] + Self { + drop_threshold: 48, // 64KiB * 48 = 3MiB + suspend_threshold: 32, // 64KiB * 32 = 2MiB + resume_threshold: 8, // 64KiB * 8 = 512KiB + // unused: + threshold_weight: Weight::from_parts(100_000, 0), + weight_restrict_decay: Weight::from_parts(2, 0), + xcmp_max_individual_weight: Weight::from_parts( + 20u64 * WEIGHT_REF_TIME_PER_MILLIS, + DEFAULT_POV_SIZE, + ), + } + } + } +} + +/// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with +/// 2D weights). +/// +/// NOTE: Only use this function if you know what you're doing. Default to using +/// `migrate_to_latest`. +#[allow(deprecated)] +pub fn migrate_to_v2() -> Weight { + let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { + v2::QueueConfigData { + suspend_threshold: pre.suspend_threshold, + drop_threshold: pre.drop_threshold, + resume_threshold: pre.resume_threshold, + threshold_weight: Weight::from_parts(pre.threshold_weight, 0), + weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), + xcmp_max_individual_weight: Weight::from_parts( + pre.xcmp_max_individual_weight, + DEFAULT_POV_SIZE, + ), + } + }; + + if v2::QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: super::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v2" + ); + } + + T::DbWeight::get().reads_writes(1, 1) +} + pub mod v3 { use super::*; use crate::*; @@ -101,6 +182,10 @@ pub mod v3 { OptionQuery, >; + #[frame_support::storage_alias] + pub(crate) type QueueConfig = + StorageValue, v2::QueueConfigData, ValueQuery>; + #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] pub struct InboundChannelDetails { /// The `ParaId` of the parachain that this channel is connected with. @@ -123,37 +208,6 @@ pub mod v3 { } } -/// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with -/// 2D weights). -/// -/// NOTE: Only use this function if you know what you're doing. Default to using -/// `migrate_to_latest`. -#[allow(deprecated)] -pub fn migrate_to_v2() -> Weight { - let translate = |pre: v1::QueueConfigData| -> super::QueueConfigData { - super::QueueConfigData { - suspend_threshold: pre.suspend_threshold, - drop_threshold: pre.drop_threshold, - resume_threshold: pre.resume_threshold, - threshold_weight: Weight::from_parts(pre.threshold_weight, 0), - weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), - xcmp_max_individual_weight: Weight::from_parts( - pre.xcmp_max_individual_weight, - DEFAULT_POV_SIZE, - ), - } - }; - - if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { - log::error!( - target: super::LOG_TARGET, - "unexpected error when performing translation of the QueueConfig type during storage upgrade to v2" - ); - } - - T::DbWeight::get().reads_writes(1, 1) -} - pub fn migrate_to_v3() -> Weight { #[frame_support::storage_alias] type Overweight = @@ -212,6 +266,36 @@ pub fn lazy_migrate_inbound_queue() { v3::InboundXcmpStatus::::put(states); } +/// Migrates `QueueConfigData` from v2 to v4, removing deprecated fields and bumping page +/// thresholds to at least the default values. +/// +/// NOTE: Only use this function if you know what you're doing. Default to using +/// `migrate_to_latest`. +#[allow(deprecated)] +pub fn migrate_to_v4() -> Weight { + let translate = |pre: v2::QueueConfigData| -> QueueConfigData { + use std::cmp::max; + + let default = QueueConfigData::default(); + let post = QueueConfigData { + suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), + drop_threshold: max(pre.drop_threshold, default.drop_threshold), + resume_threshold: max(pre.resume_threshold, default.resume_threshold), + }; + post + }; + + if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: super::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v4" + ); + } + + T::DbWeight::get().reads_writes(1, 1) +} + #[cfg(test)] mod tests { use super::*; @@ -237,7 +321,7 @@ mod tests { migrate_to_v2::(); - let v2 = crate::QueueConfig::::get(); + let v2 = v2::QueueConfig::::get(); assert_eq!(v1.suspend_threshold, v2.suspend_threshold); assert_eq!(v1.drop_threshold, v2.drop_threshold); @@ -247,4 +331,58 @@ mod tests { assert_eq!(v1.xcmp_max_individual_weight, v2.xcmp_max_individual_weight.ref_time()); }); } + + #[test] + #[allow(deprecated)] + fn test_migration_to_v4() { + new_test_ext().execute_with(|| { + let v2 = v2::QueueConfigData { + drop_threshold: 5, + suspend_threshold: 2, + resume_threshold: 1, + ..Default::default() + }; + + frame_support::storage::unhashed::put_raw( + &crate::QueueConfig::::hashed_key(), + &v2.encode(), + ); + + migrate_to_v4::(); + + let v4 = QueueConfig::::get(); + + assert_eq!( + v4, + QueueConfigData { suspend_threshold: 32, drop_threshold: 48, resume_threshold: 8 } + ); + }); + + new_test_ext().execute_with(|| { + let v2 = v2::QueueConfigData { + drop_threshold: 100, + suspend_threshold: 50, + resume_threshold: 40, + ..Default::default() + }; + + frame_support::storage::unhashed::put_raw( + &crate::QueueConfig::::hashed_key(), + &v2.encode(), + ); + + migrate_to_v4::(); + + let v4 = QueueConfig::::get(); + + assert_eq!( + v4, + QueueConfigData { + suspend_threshold: 50, + drop_threshold: 100, + resume_threshold: 40 + } + ); + }); + } } From f5d8f2ea76be0528260ffc4c7328a89ae1b07826 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 6 Nov 2023 12:56:05 +0200 Subject: [PATCH 02/14] Address PR comments --- cumulus/pallets/xcmp-queue/src/migration.rs | 8 ++++---- .../runtimes/contracts/contracts-rococo/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 22f89f875d3c..0321f83b5a33 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -27,14 +27,14 @@ use frame_support::{ }; /// The current storage version. -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); pub const LOG: &str = "runtime::xcmp-queue-migration"; /// Migrates the pallet storage to the most recent version. -pub struct MigrationToV3(PhantomData); +pub struct MigrationToV4(PhantomData); -impl OnRuntimeUpgrade for MigrationToV3 { +impl OnRuntimeUpgrade for MigrationToV4 { fn on_runtime_upgrade() -> Weight { let mut weight = T::DbWeight::get().reads(1); @@ -266,7 +266,7 @@ pub fn lazy_migrate_inbound_queue() { v3::InboundXcmpStatus::::put(states); } -/// Migrates `QueueConfigData` from v2 to v4, removing deprecated fields and bumping page +/// Migrates `QueueConfigData` to v4, removing deprecated fields and bumping page /// thresholds to at least the default values. /// /// NOTE: Only use this function if you know what you're doing. Default to using diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index e41db7d92133..5fe2a38aac03 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,7 +100,7 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, - cumulus_pallet_xcmp_queue::migration::MigrationToV3, + cumulus_pallet_xcmp_queue::migration::MigrationToV4, pallet_contracts::Migration, // unreleased ); From 3d57443ccbe7a1f8a86318a3b27b3b61c8aff4c0 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 6 Nov 2023 13:18:44 +0200 Subject: [PATCH 03/14] fix --- cumulus/pallets/xcmp-queue/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 0321f83b5a33..29a300ae3535 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -274,7 +274,7 @@ pub fn lazy_migrate_inbound_queue() { #[allow(deprecated)] pub fn migrate_to_v4() -> Weight { let translate = |pre: v2::QueueConfigData| -> QueueConfigData { - use std::cmp::max; + use sp_std::cmp::max; let default = QueueConfigData::default(); let post = QueueConfigData { From 12ee88317bcc7009a08ab4b1f4511996d9db61cd Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 6 Nov 2023 13:35:09 +0200 Subject: [PATCH 04/14] use migration --- cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 + .../parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index f1a15265b90d..63a11ea5aa20 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -944,6 +944,7 @@ pub type Migrations = ( pallet_multisig::migrations::v1::MigrateToV1, // unreleased InitStorageVersions, + cumulus_pallet_xcmp_queue::migration::MigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index b533f7adc2a4..e6d8328e34f1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -141,6 +141,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, + cumulus_pallet_xcmp_queue::migration::MigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. From 2e2a59558e02bb14b35f8d5ebb1efad2c442342e Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 9 Nov 2023 15:04:30 +0200 Subject: [PATCH 05/14] use VersionedMigration --- cumulus/pallets/xcmp-queue/src/migration.rs | 191 ++++++++++-------- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- 3 files changed, 107 insertions(+), 88 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 29a300ae3535..ac2c3c59be49 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -31,35 +31,6 @@ pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); pub const LOG: &str = "runtime::xcmp-queue-migration"; -/// Migrates the pallet storage to the most recent version. -pub struct MigrationToV4(PhantomData); - -impl OnRuntimeUpgrade for MigrationToV4 { - fn on_runtime_upgrade() -> Weight { - let mut weight = T::DbWeight::get().reads(1); - - if StorageVersion::get::>() == 1 { - weight.saturating_accrue(migrate_to_v2::()); - StorageVersion::new(2).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } - - if StorageVersion::get::>() == 2 { - weight.saturating_accrue(migrate_to_v3::()); - StorageVersion::new(3).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } - - if StorageVersion::get::>() == 3 { - weight.saturating_accrue(migrate_to_v4::()); - StorageVersion::new(4).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } - - weight - } -} - mod v1 { use super::*; use codec::{Decode, Encode}; @@ -131,36 +102,48 @@ mod v2 { /// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with /// 2D weights). -/// -/// NOTE: Only use this function if you know what you're doing. Default to using -/// `migrate_to_latest`. -#[allow(deprecated)] -pub fn migrate_to_v2() -> Weight { - let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { - v2::QueueConfigData { - suspend_threshold: pre.suspend_threshold, - drop_threshold: pre.drop_threshold, - resume_threshold: pre.resume_threshold, - threshold_weight: Weight::from_parts(pre.threshold_weight, 0), - weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), - xcmp_max_individual_weight: Weight::from_parts( - pre.xcmp_max_individual_weight, - DEFAULT_POV_SIZE, - ), +pub struct MigrationToV2(PhantomData); + +impl OnRuntimeUpgrade for MigrationToV2 { + #[allow(deprecated)] + fn on_runtime_upgrade() -> Weight { + let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { + v2::QueueConfigData { + suspend_threshold: pre.suspend_threshold, + drop_threshold: pre.drop_threshold, + resume_threshold: pre.resume_threshold, + threshold_weight: Weight::from_parts(pre.threshold_weight, 0), + weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), + xcmp_max_individual_weight: Weight::from_parts( + pre.xcmp_max_individual_weight, + DEFAULT_POV_SIZE, + ), + } + }; + + if v2::QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: super::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v2" + ); } - }; - if v2::QueueConfig::::translate(|pre| pre.map(translate)).is_err() { - log::error!( - target: super::LOG_TARGET, - "unexpected error when performing translation of the QueueConfig type \ - during storage upgrade to v2" - ); + T::DbWeight::get().reads_writes(1, 1) } - - T::DbWeight::get().reads_writes(1, 1) } +/// [`MigrationToV2`] wrapped in a +/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the +/// migration is only performed when on-chain version is 1. +pub type VersionCheckedMigrationToV2 = frame_support::migrations::VersionedMigration< + 1, + 2, + MigrationToV2, + Pallet, + ::DbWeight, +>; + pub mod v3 { use super::*; use crate::*; @@ -208,15 +191,31 @@ pub mod v3 { } } -pub fn migrate_to_v3() -> Weight { - #[frame_support::storage_alias] - type Overweight = - CountedStorageMap, Twox64Concat, OverweightIndex, ParaId>; - let overweight_messages = Overweight::::initialize_counter() as u64; +/// Migrates the pallet storage to v3. +pub struct MigrationToV3(PhantomData); + +impl OnRuntimeUpgrade for MigrationToV3 { + fn on_runtime_upgrade() -> Weight { + #[frame_support::storage_alias] + type Overweight = + CountedStorageMap, Twox64Concat, OverweightIndex, ParaId>; + let overweight_messages = Overweight::::initialize_counter() as u64; - T::DbWeight::get().reads_writes(overweight_messages, 1) + T::DbWeight::get().reads_writes(overweight_messages, 1) + } } +/// [`MigrationToV3`] wrapped in a +/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the +/// migration is only performed when on-chain version is 2. +pub type VersionCheckedMigrationToV3 = frame_support::migrations::VersionedMigration< + 2, + 3, + MigrationToV3, + Pallet, + ::DbWeight, +>; + pub fn lazy_migrate_inbound_queue() { let Some(mut states) = v3::InboundXcmpStatus::::get() else { log::debug!(target: LOG, "Lazy migration finished: item gone"); @@ -268,34 +267,45 @@ pub fn lazy_migrate_inbound_queue() { /// Migrates `QueueConfigData` to v4, removing deprecated fields and bumping page /// thresholds to at least the default values. -/// -/// NOTE: Only use this function if you know what you're doing. Default to using -/// `migrate_to_latest`. -#[allow(deprecated)] -pub fn migrate_to_v4() -> Weight { - let translate = |pre: v2::QueueConfigData| -> QueueConfigData { - use sp_std::cmp::max; - - let default = QueueConfigData::default(); - let post = QueueConfigData { - suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), - drop_threshold: max(pre.drop_threshold, default.drop_threshold), - resume_threshold: max(pre.resume_threshold, default.resume_threshold), +pub struct MigrationToV4(PhantomData); + +impl OnRuntimeUpgrade for MigrationToV4 { + fn on_runtime_upgrade() -> Weight { + let translate = |pre: v2::QueueConfigData| -> QueueConfigData { + use sp_std::cmp::max; + + let default = QueueConfigData::default(); + let post = QueueConfigData { + suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), + drop_threshold: max(pre.drop_threshold, default.drop_threshold), + resume_threshold: max(pre.resume_threshold, default.resume_threshold), + }; + post }; - post - }; - if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { - log::error!( - target: super::LOG_TARGET, - "unexpected error when performing translation of the QueueConfig type \ - during storage upgrade to v4" - ); - } + if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: super::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v4" + ); + } - T::DbWeight::get().reads_writes(1, 1) + T::DbWeight::get().reads_writes(1, 1) + } } +/// [`MigrationToV4`] wrapped in a +/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the +/// migration is only performed when on-chain version is 3. +pub type VersionCheckedMigrationToV4 = frame_support::migrations::VersionedMigration< + 3, + 4, + MigrationToV4, + Pallet, + ::DbWeight, +>; + #[cfg(test)] mod tests { use super::*; @@ -314,12 +324,15 @@ mod tests { }; new_test_ext().execute_with(|| { + let storage_version = StorageVersion::new(1); + storage_version.put::>(); + frame_support::storage::unhashed::put_raw( &crate::QueueConfig::::hashed_key(), &v1.encode(), ); - migrate_to_v2::(); + VersionCheckedMigrationToV2::::on_runtime_upgrade(); let v2 = v2::QueueConfig::::get(); @@ -336,6 +349,9 @@ mod tests { #[allow(deprecated)] fn test_migration_to_v4() { new_test_ext().execute_with(|| { + let storage_version = StorageVersion::new(3); + storage_version.put::>(); + let v2 = v2::QueueConfigData { drop_threshold: 5, suspend_threshold: 2, @@ -348,7 +364,7 @@ mod tests { &v2.encode(), ); - migrate_to_v4::(); + VersionCheckedMigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); @@ -359,6 +375,9 @@ mod tests { }); new_test_ext().execute_with(|| { + let storage_version = StorageVersion::new(3); + storage_version.put::>(); + let v2 = v2::QueueConfigData { drop_threshold: 100, suspend_threshold: 50, @@ -371,7 +390,7 @@ mod tests { &v2.encode(), ); - migrate_to_v4::(); + VersionCheckedMigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 63a11ea5aa20..708d4c15ea91 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -944,7 +944,7 @@ pub type Migrations = ( pallet_multisig::migrations::v1::MigrateToV1, // unreleased InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::MigrationToV4, + cumulus_pallet_xcmp_queue::migration::VersionCheckedMigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index e6d8328e34f1..badc0e27965f 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -141,7 +141,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::MigrationToV4, + cumulus_pallet_xcmp_queue::migration::VersionCheckedMigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. From 24f48b4ff91478fcff12bffe2cbcafb6b6096300 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 9 Nov 2023 15:41:28 +0200 Subject: [PATCH 06/14] move migrations to mods --- cumulus/pallets/xcmp-queue/src/lib.rs | 2 +- cumulus/pallets/xcmp-queue/src/migration.rs | 289 +++++++++--------- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- .../contracts/contracts-rococo/src/lib.rs | 2 +- 5 files changed, 150 insertions(+), 147 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index bf67b5f61bff..c2e2156f432d 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -255,7 +255,7 @@ pub mod pallet { return meter.consumed() } - migration::lazy_migrate_inbound_queue::(); + migration::v3::lazy_migrate_inbound_queue::(); meter.consumed() } diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index ac2c3c59be49..85815e1ee5ac 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -16,9 +16,7 @@ //! A module that is responsible for migration of storage. -use crate::{ - Config, OverweightIndex, Pallet, ParaId, QueueConfig, QueueConfigData, DEFAULT_POV_SIZE, -}; +use crate::{Config, OverweightIndex, Pallet, QueueConfig, QueueConfigData, DEFAULT_POV_SIZE}; use cumulus_primitives_core::XcmpMessageFormat; use frame_support::{ pallet_prelude::*, @@ -98,51 +96,52 @@ mod v2 { } } } -} -/// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with -/// 2D weights). -pub struct MigrationToV2(PhantomData); + /// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with + /// 2D weights). + pub struct MigrationToV2(PhantomData); + + impl OnRuntimeUpgrade for MigrationToV2 { + #[allow(deprecated)] + fn on_runtime_upgrade() -> Weight { + let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { + v2::QueueConfigData { + suspend_threshold: pre.suspend_threshold, + drop_threshold: pre.drop_threshold, + resume_threshold: pre.resume_threshold, + threshold_weight: Weight::from_parts(pre.threshold_weight, 0), + weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), + xcmp_max_individual_weight: Weight::from_parts( + pre.xcmp_max_individual_weight, + DEFAULT_POV_SIZE, + ), + } + }; -impl OnRuntimeUpgrade for MigrationToV2 { - #[allow(deprecated)] - fn on_runtime_upgrade() -> Weight { - let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { - v2::QueueConfigData { - suspend_threshold: pre.suspend_threshold, - drop_threshold: pre.drop_threshold, - resume_threshold: pre.resume_threshold, - threshold_weight: Weight::from_parts(pre.threshold_weight, 0), - weight_restrict_decay: Weight::from_parts(pre.weight_restrict_decay, 0), - xcmp_max_individual_weight: Weight::from_parts( - pre.xcmp_max_individual_weight, - DEFAULT_POV_SIZE, - ), + if v2::QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: crate::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v2" + ); } - }; - if v2::QueueConfig::::translate(|pre| pre.map(translate)).is_err() { - log::error!( - target: super::LOG_TARGET, - "unexpected error when performing translation of the QueueConfig type \ - during storage upgrade to v2" - ); + T::DbWeight::get().reads_writes(1, 1) } - - T::DbWeight::get().reads_writes(1, 1) } -} -/// [`MigrationToV2`] wrapped in a -/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the -/// migration is only performed when on-chain version is 1. -pub type VersionCheckedMigrationToV2 = frame_support::migrations::VersionedMigration< - 1, - 2, - MigrationToV2, - Pallet, - ::DbWeight, ->; + /// [`MigrationToV2`] wrapped in a + /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the + /// migration is only performed when on-chain version is 1. + #[allow(dead_code)] + pub type VersionCheckedMigrationToV2 = frame_support::migrations::VersionedMigration< + 1, + 2, + MigrationToV2, + Pallet, + ::DbWeight, + >; +} pub mod v3 { use super::*; @@ -189,122 +188,126 @@ pub mod v3 { Ok, Suspended, } -} -/// Migrates the pallet storage to v3. -pub struct MigrationToV3(PhantomData); + /// Migrates the pallet storage to v3. + pub struct MigrationToV3(PhantomData); -impl OnRuntimeUpgrade for MigrationToV3 { - fn on_runtime_upgrade() -> Weight { - #[frame_support::storage_alias] - type Overweight = - CountedStorageMap, Twox64Concat, OverweightIndex, ParaId>; - let overweight_messages = Overweight::::initialize_counter() as u64; + impl OnRuntimeUpgrade for MigrationToV3 { + fn on_runtime_upgrade() -> Weight { + #[frame_support::storage_alias] + type Overweight = + CountedStorageMap, Twox64Concat, OverweightIndex, ParaId>; + let overweight_messages = Overweight::::initialize_counter() as u64; - T::DbWeight::get().reads_writes(overweight_messages, 1) + T::DbWeight::get().reads_writes(overweight_messages, 1) + } } -} -/// [`MigrationToV3`] wrapped in a -/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the -/// migration is only performed when on-chain version is 2. -pub type VersionCheckedMigrationToV3 = frame_support::migrations::VersionedMigration< - 2, - 3, - MigrationToV3, - Pallet, - ::DbWeight, ->; - -pub fn lazy_migrate_inbound_queue() { - let Some(mut states) = v3::InboundXcmpStatus::::get() else { - log::debug!(target: LOG, "Lazy migration finished: item gone"); - return - }; - let Some(ref mut next) = states.first_mut() else { - log::debug!(target: LOG, "Lazy migration finished: item empty"); - v3::InboundXcmpStatus::::kill(); - return - }; - log::debug!( - "Migrating inbound HRMP channel with sibling {:?}, msgs left {}.", - next.sender, - next.message_metadata.len() - ); - // We take the last element since the MQ is a FIFO and we want to keep the order. - let Some((block_number, format)) = next.message_metadata.pop() else { - states.remove(0); - v3::InboundXcmpStatus::::put(states); - return - }; - if format != XcmpMessageFormat::ConcatenatedVersionedXcm { - log::warn!(target: LOG, - "Dropping message with format {:?} (not ConcatenatedVersionedXcm)", - format + /// [`MigrationToV3`] wrapped in a + /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the + /// migration is only performed when on-chain version is 2. + pub type VersionCheckedMigrationToV3 = frame_support::migrations::VersionedMigration< + 2, + 3, + MigrationToV3, + Pallet, + ::DbWeight, + >; + + pub fn lazy_migrate_inbound_queue() { + let Some(mut states) = v3::InboundXcmpStatus::::get() else { + log::debug!(target: LOG, "Lazy migration finished: item gone"); + return + }; + let Some(ref mut next) = states.first_mut() else { + log::debug!(target: LOG, "Lazy migration finished: item empty"); + v3::InboundXcmpStatus::::kill(); + return + }; + log::debug!( + "Migrating inbound HRMP channel with sibling {:?}, msgs left {}.", + next.sender, + next.message_metadata.len() ); - v3::InboundXcmpMessages::::remove(&next.sender, &block_number); - v3::InboundXcmpStatus::::put(states); - return - } + // We take the last element since the MQ is a FIFO and we want to keep the order. + let Some((block_number, format)) = next.message_metadata.pop() else { + states.remove(0); + v3::InboundXcmpStatus::::put(states); + return + }; + if format != XcmpMessageFormat::ConcatenatedVersionedXcm { + log::warn!(target: LOG, + "Dropping message with format {:?} (not ConcatenatedVersionedXcm)", + format + ); + v3::InboundXcmpMessages::::remove(&next.sender, &block_number); + v3::InboundXcmpStatus::::put(states); + return + } - let Some(msg) = v3::InboundXcmpMessages::::take(&next.sender, &block_number) else { - defensive!("Storage corrupted: HRMP message missing:", (next.sender, block_number)); - v3::InboundXcmpStatus::::put(states); - return - }; + let Some(msg) = v3::InboundXcmpMessages::::take(&next.sender, &block_number) else { + defensive!("Storage corrupted: HRMP message missing:", (next.sender, block_number)); + v3::InboundXcmpStatus::::put(states); + return + }; - let Ok(msg): Result, _> = msg.try_into() else { - log::error!(target: LOG, "Message dropped: too big"); - v3::InboundXcmpStatus::::put(states); - return - }; + let Ok(msg): Result, _> = msg.try_into() else { + log::error!(target: LOG, "Message dropped: too big"); + v3::InboundXcmpStatus::::put(states); + return + }; - // Finally! We have a proper message. - T::XcmpQueue::enqueue_message(msg.as_bounded_slice(), next.sender); - log::debug!(target: LOG, "Migrated HRMP message to MQ: {:?}", (next.sender, block_number)); - v3::InboundXcmpStatus::::put(states); + // Finally! We have a proper message. + T::XcmpQueue::enqueue_message(msg.as_bounded_slice(), next.sender); + log::debug!(target: LOG, "Migrated HRMP message to MQ: {:?}", (next.sender, block_number)); + v3::InboundXcmpStatus::::put(states); + } } -/// Migrates `QueueConfigData` to v4, removing deprecated fields and bumping page -/// thresholds to at least the default values. -pub struct MigrationToV4(PhantomData); - -impl OnRuntimeUpgrade for MigrationToV4 { - fn on_runtime_upgrade() -> Weight { - let translate = |pre: v2::QueueConfigData| -> QueueConfigData { - use sp_std::cmp::max; +pub mod v4 { + use super::*; - let default = QueueConfigData::default(); - let post = QueueConfigData { - suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), - drop_threshold: max(pre.drop_threshold, default.drop_threshold), - resume_threshold: max(pre.resume_threshold, default.resume_threshold), + /// Migrates `QueueConfigData` to v4, removing deprecated fields and bumping page + /// thresholds to at least the default values. + pub struct MigrationToV4(PhantomData); + + impl OnRuntimeUpgrade for MigrationToV4 { + fn on_runtime_upgrade() -> Weight { + let translate = |pre: v2::QueueConfigData| -> QueueConfigData { + use sp_std::cmp::max; + + let default = QueueConfigData::default(); + let post = QueueConfigData { + suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), + drop_threshold: max(pre.drop_threshold, default.drop_threshold), + resume_threshold: max(pre.resume_threshold, default.resume_threshold), + }; + post }; - post - }; - if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { - log::error!( - target: super::LOG_TARGET, - "unexpected error when performing translation of the QueueConfig type \ - during storage upgrade to v4" - ); - } + if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { + log::error!( + target: crate::LOG_TARGET, + "unexpected error when performing translation of the QueueConfig type \ + during storage upgrade to v4" + ); + } - T::DbWeight::get().reads_writes(1, 1) + T::DbWeight::get().reads_writes(1, 1) + } } -} -/// [`MigrationToV4`] wrapped in a -/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the -/// migration is only performed when on-chain version is 3. -pub type VersionCheckedMigrationToV4 = frame_support::migrations::VersionedMigration< - 3, - 4, - MigrationToV4, - Pallet, - ::DbWeight, ->; + /// [`MigrationToV4`] wrapped in a + /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the + /// migration is only performed when on-chain version is 3. + pub type VersionCheckedMigrationToV4 = frame_support::migrations::VersionedMigration< + 3, + 4, + MigrationToV4, + Pallet, + ::DbWeight, + >; +} #[cfg(test)] mod tests { @@ -332,7 +335,7 @@ mod tests { &v1.encode(), ); - VersionCheckedMigrationToV2::::on_runtime_upgrade(); + v2::VersionCheckedMigrationToV2::::on_runtime_upgrade(); let v2 = v2::QueueConfig::::get(); @@ -364,7 +367,7 @@ mod tests { &v2.encode(), ); - VersionCheckedMigrationToV4::::on_runtime_upgrade(); + v4::VersionCheckedMigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); @@ -390,7 +393,7 @@ mod tests { &v2.encode(), ); - VersionCheckedMigrationToV4::::on_runtime_upgrade(); + v4::VersionCheckedMigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 708d4c15ea91..c0988e51738c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -944,7 +944,7 @@ pub type Migrations = ( pallet_multisig::migrations::v1::MigrateToV1, // unreleased InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::VersionCheckedMigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index badc0e27965f..01cdc662c379 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -141,7 +141,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::VersionCheckedMigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 5fe2a38aac03..e959ec2ab6ef 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,7 +100,7 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, - cumulus_pallet_xcmp_queue::migration::MigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, pallet_contracts::Migration, // unreleased ); From 3eb441903a63c50a130c15db54e14755eaf3aea9 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 10 Nov 2023 10:00:29 +0200 Subject: [PATCH 07/14] Renamings --- cumulus/pallets/xcmp-queue/src/migration.rs | 36 +++++++++---------- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- .../contracts/contracts-rococo/src/lib.rs | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 85815e1ee5ac..22b64f9ae916 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -99,9 +99,9 @@ mod v2 { /// Migrates `QueueConfigData` from v1 (using only reference time weights) to v2 (with /// 2D weights). - pub struct MigrationToV2(PhantomData); + pub struct UncheckedMigrationToV2(PhantomData); - impl OnRuntimeUpgrade for MigrationToV2 { + impl OnRuntimeUpgrade for UncheckedMigrationToV2 { #[allow(deprecated)] fn on_runtime_upgrade() -> Weight { let translate = |pre: v1::QueueConfigData| -> v2::QueueConfigData { @@ -130,14 +130,14 @@ mod v2 { } } - /// [`MigrationToV2`] wrapped in a + /// [`UncheckedMigrationToV2`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the /// migration is only performed when on-chain version is 1. #[allow(dead_code)] - pub type VersionCheckedMigrationToV2 = frame_support::migrations::VersionedMigration< + pub type MigrationToV2 = frame_support::migrations::VersionedMigration< 1, 2, - MigrationToV2, + UncheckedMigrationToV2, Pallet, ::DbWeight, >; @@ -190,9 +190,9 @@ pub mod v3 { } /// Migrates the pallet storage to v3. - pub struct MigrationToV3(PhantomData); + pub struct UncheckedMigrationToV3(PhantomData); - impl OnRuntimeUpgrade for MigrationToV3 { + impl OnRuntimeUpgrade for UncheckedMigrationToV3 { fn on_runtime_upgrade() -> Weight { #[frame_support::storage_alias] type Overweight = @@ -203,13 +203,13 @@ pub mod v3 { } } - /// [`MigrationToV3`] wrapped in a + /// [`UncheckedMigrationToV3`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the /// migration is only performed when on-chain version is 2. - pub type VersionCheckedMigrationToV3 = frame_support::migrations::VersionedMigration< + pub type MigrationToV3 = frame_support::migrations::VersionedMigration< 2, 3, - MigrationToV3, + UncheckedMigrationToV3, Pallet, ::DbWeight, >; @@ -269,9 +269,9 @@ pub mod v4 { /// Migrates `QueueConfigData` to v4, removing deprecated fields and bumping page /// thresholds to at least the default values. - pub struct MigrationToV4(PhantomData); + pub struct UncheckedMigrationToV4(PhantomData); - impl OnRuntimeUpgrade for MigrationToV4 { + impl OnRuntimeUpgrade for UncheckedMigrationToV4 { fn on_runtime_upgrade() -> Weight { let translate = |pre: v2::QueueConfigData| -> QueueConfigData { use sp_std::cmp::max; @@ -297,13 +297,13 @@ pub mod v4 { } } - /// [`MigrationToV4`] wrapped in a + /// [`UncheckedMigrationToV4`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the /// migration is only performed when on-chain version is 3. - pub type VersionCheckedMigrationToV4 = frame_support::migrations::VersionedMigration< + pub type MigrationToV4 = frame_support::migrations::VersionedMigration< 3, 4, - MigrationToV4, + UncheckedMigrationToV4, Pallet, ::DbWeight, >; @@ -335,7 +335,7 @@ mod tests { &v1.encode(), ); - v2::VersionCheckedMigrationToV2::::on_runtime_upgrade(); + v2::MigrationToV2::::on_runtime_upgrade(); let v2 = v2::QueueConfig::::get(); @@ -367,7 +367,7 @@ mod tests { &v2.encode(), ); - v4::VersionCheckedMigrationToV4::::on_runtime_upgrade(); + v4::MigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); @@ -393,7 +393,7 @@ mod tests { &v2.encode(), ); - v4::VersionCheckedMigrationToV4::::on_runtime_upgrade(); + v4::MigrationToV4::::on_runtime_upgrade(); let v4 = QueueConfig::::get(); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index c0988e51738c..e2e263b33e76 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -944,7 +944,7 @@ pub type Migrations = ( pallet_multisig::migrations::v1::MigrateToV1, // unreleased InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 01cdc662c379..b9da36b97cc0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -141,7 +141,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, - cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index e959ec2ab6ef..6b6c55d4a997 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,7 +100,7 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, - cumulus_pallet_xcmp_queue::migration::v4::VersionCheckedMigrationToV4, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, pallet_contracts::Migration, // unreleased ); From 4fc2cf0b90188ef072085a86127190bbf3044923 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 13 Nov 2023 17:27:57 +0200 Subject: [PATCH 08/14] Fixes --- cumulus/pallets/xcmp-queue/src/lib.rs | 1 - cumulus/pallets/xcmp-queue/src/migration.rs | 49 ++++++++++++------- .../contracts/contracts-rococo/src/lib.rs | 4 +- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index c2e2156f432d..d3443163d086 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -393,7 +393,6 @@ impl Default for QueueConfigData { fn default() -> Self { // NOTE that these default values are only used on genesis. They should give a rough idea of // what to set these values to, but is in no way a requirement. - #![allow(deprecated)] Self { drop_threshold: 48, // 64KiB * 48 = 3MiB suspend_threshold: 32, // 64KiB * 32 = 2MiB diff --git a/cumulus/pallets/xcmp-queue/src/migration.rs b/cumulus/pallets/xcmp-queue/src/migration.rs index 22b64f9ae916..6c86c3011d23 100644 --- a/cumulus/pallets/xcmp-queue/src/migration.rs +++ b/cumulus/pallets/xcmp-queue/src/migration.rs @@ -60,7 +60,7 @@ mod v1 { } } -mod v2 { +pub mod v2 { use super::*; #[frame_support::storage_alias] @@ -71,22 +71,17 @@ mod v2 { pub suspend_threshold: u32, pub drop_threshold: u32, pub resume_threshold: u32, - #[deprecated(note = "Will be removed")] pub threshold_weight: Weight, - #[deprecated(note = "Will be removed")] pub weight_restrict_decay: Weight, - #[deprecated(note = "Will be removed")] pub xcmp_max_individual_weight: Weight, } impl Default for QueueConfigData { fn default() -> Self { - #![allow(deprecated)] Self { - drop_threshold: 48, // 64KiB * 48 = 3MiB - suspend_threshold: 32, // 64KiB * 32 = 2MiB - resume_threshold: 8, // 64KiB * 8 = 512KiB - // unused: + suspend_threshold: 2, + drop_threshold: 5, + resume_threshold: 1, threshold_weight: Weight::from_parts(100_000, 0), weight_restrict_decay: Weight::from_parts(2, 0), xcmp_max_individual_weight: Weight::from_parts( @@ -274,15 +269,22 @@ pub mod v4 { impl OnRuntimeUpgrade for UncheckedMigrationToV4 { fn on_runtime_upgrade() -> Weight { let translate = |pre: v2::QueueConfigData| -> QueueConfigData { - use sp_std::cmp::max; - - let default = QueueConfigData::default(); - let post = QueueConfigData { - suspend_threshold: max(pre.suspend_threshold, default.suspend_threshold), - drop_threshold: max(pre.drop_threshold, default.drop_threshold), - resume_threshold: max(pre.resume_threshold, default.resume_threshold), - }; - post + let pre_default = v2::QueueConfigData::default(); + // If the previous values are the default ones, let's replace them with the new + // default. + if pre.suspend_threshold == pre_default.suspend_threshold && + pre.drop_threshold == pre_default.drop_threshold && + pre.resume_threshold == pre_default.resume_threshold + { + return QueueConfigData::default() + } + + // If the previous values are not the default ones, let's leave them as they are. + QueueConfigData { + suspend_threshold: pre.suspend_threshold, + drop_threshold: pre.drop_threshold, + resume_threshold: pre.resume_threshold, + } }; if QueueConfig::::translate(|pre| pre.map(translate)).is_err() { @@ -309,7 +311,7 @@ pub mod v4 { >; } -#[cfg(test)] +#[cfg(all(feature = "try-runtime", test))] mod tests { use super::*; use crate::mock::{new_test_ext, Test}; @@ -335,7 +337,10 @@ mod tests { &v1.encode(), ); + let bytes = v2::MigrationToV2::::pre_upgrade(); + assert!(bytes.is_ok()); v2::MigrationToV2::::on_runtime_upgrade(); + assert!(v2::MigrationToV2::::post_upgrade(bytes.unwrap()).is_ok()); let v2 = v2::QueueConfig::::get(); @@ -367,7 +372,10 @@ mod tests { &v2.encode(), ); + let bytes = v4::MigrationToV4::::pre_upgrade(); + assert!(bytes.is_ok()); v4::MigrationToV4::::on_runtime_upgrade(); + assert!(v4::MigrationToV4::::post_upgrade(bytes.unwrap()).is_ok()); let v4 = QueueConfig::::get(); @@ -393,7 +401,10 @@ mod tests { &v2.encode(), ); + let bytes = v4::MigrationToV4::::pre_upgrade(); + assert!(bytes.is_ok()); v4::MigrationToV4::::on_runtime_upgrade(); + assert!(v4::MigrationToV4::::post_upgrade(bytes.unwrap()).is_ok()); let v4 = QueueConfig::::get(); diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 6b6c55d4a997..d9561758e9f0 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,9 +100,11 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + cumulus_pallet_xcmp_queue::migration::v2::MigrationToV2, + cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3, pallet_contracts::Migration, // unreleased + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); type EventRecord = frame_system::EventRecord< From c03926b02d8db712790a0bb78640b792b4b2d6b2 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 13 Nov 2023 19:05:01 +0200 Subject: [PATCH 09/14] contracts-rococo migration fix --- .../parachains/runtimes/contracts/contracts-rococo/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 266f2ce0660c..ad4d9255162e 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,8 +100,6 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, - cumulus_pallet_xcmp_queue::migration::v2::MigrationToV2, - cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3, pallet_contracts::Migration, // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, From 1e122bce17fe5d5edcf4e70dc974278399576d97 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 16 Nov 2023 11:20:57 +0200 Subject: [PATCH 10/14] Revert "contracts-rococo migration fix" This reverts commit c03926b02d8db712790a0bb78640b792b4b2d6b2. --- .../parachains/runtimes/contracts/contracts-rococo/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index ad4d9255162e..266f2ce0660c 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -100,6 +100,8 @@ pub type UncheckedExtrinsic = /// Migrations to apply on runtime upgrade. pub type Migrations = ( cumulus_pallet_parachain_system::migration::Migration, + cumulus_pallet_xcmp_queue::migration::v2::MigrationToV2, + cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3, pallet_contracts::Migration, // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, From 05841753d8a7b98565c642ca94b4d8d4a578fef2 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 16 Nov 2023 11:35:16 +0200 Subject: [PATCH 11/14] clippy --- cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 8c7c5d18168b..e20dd52239bd 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -948,7 +948,7 @@ pub type Migrations = ( InitStorageVersions, // unreleased DeleteUndecodableStorage, - // unreleased + // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); From 3f11193d43733822c45bb1790c11590e707558dc Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 4 Dec 2023 10:57:23 +0100 Subject: [PATCH 12/14] Apply migration to more runtimes --- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 7 +++++-- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 1 + .../runtimes/collectives/collectives-westend/src/lib.rs | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index c6c9735ecb1e..015877cfbf32 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -954,8 +954,11 @@ pub type SignedExtra = ( pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = - (pallet_collator_selection::migration::v1::MigrateToV1, InitStorageVersions); +pub type Migrations = ( + pallet_collator_selection::migration::v1::MigrateToV1, + InitStorageVersions, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, +); /// Migration to initialize storage versions for pallets added after genesis. /// diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 7b8ea1b7734e..79c2a95cddc9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -118,6 +118,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); /// Migration to initialize storage versions for pallets added after genesis. diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 1017ac30499b..82d45c67375d 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -707,6 +707,7 @@ pub type UncheckedExtrinsic = type Migrations = ( // unreleased pallet_collator_selection::migration::v1::MigrateToV1, + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); /// Executive: handles dispatch to the various modules. From 2586413f8d109cc33694933eafeeec4d501519af Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 4 Dec 2023 11:15:00 +0100 Subject: [PATCH 13/14] Add prdoc --- prdoc/pr_2142.prdoc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 prdoc/pr_2142.prdoc diff --git a/prdoc/pr_2142.prdoc b/prdoc/pr_2142.prdoc new file mode 100644 index 000000000000..b0170dce1841 --- /dev/null +++ b/prdoc/pr_2142.prdoc @@ -0,0 +1,15 @@ +title: Cleanup XCMP `QueueConfigData` + +doc: + - audience: Parachain Dev + description: Removes obsolete fields from the `QueueConfigData` structure. For the remaining fields, if they use the old defaults, we replace them with the new defaults. + +migrations: + runtime: + - + pallet: "cumulus_pallet_xcmp_queue" + description: "v4: Removes obsolete fields from the `QueueConfigData` structure. For the remaining fields, if they use the old defaults, we replace them with the new defaults." + +crates: [] + +host_functions: [] From a01ae23a9bff3341d819a6b773a5d140df80b81f Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 4 Dec 2023 11:41:49 +0100 Subject: [PATCH 14/14] small docs fixes --- cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 1 + .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 1 + .../runtimes/collectives/collectives-westend/src/lib.rs | 1 + prdoc/pr_2142.prdoc | 3 +-- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 015877cfbf32..6b1948e7125b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -957,6 +957,7 @@ pub type UncheckedExtrinsic = pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, InitStorageVersions, + // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 79c2a95cddc9..121aa5f0e863 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -118,6 +118,7 @@ pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, pallet_multisig::migrations::v1::MigrateToV1, InitStorageVersions, + // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 82d45c67375d..be82cf32fbb2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -707,6 +707,7 @@ pub type UncheckedExtrinsic = type Migrations = ( // unreleased pallet_collator_selection::migration::v1::MigrateToV1, + // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); diff --git a/prdoc/pr_2142.prdoc b/prdoc/pr_2142.prdoc index b0170dce1841..ae2ac3db9ddc 100644 --- a/prdoc/pr_2142.prdoc +++ b/prdoc/pr_2142.prdoc @@ -6,8 +6,7 @@ doc: migrations: runtime: - - - pallet: "cumulus_pallet_xcmp_queue" + - pallet: "cumulus_pallet_xcmp_queue" description: "v4: Removes obsolete fields from the `QueueConfigData` structure. For the remaining fields, if they use the old defaults, we replace them with the new defaults." crates: []