diff --git a/polkadot/runtime/common/src/lib.rs b/polkadot/runtime/common/src/lib.rs index ea525132b7..61968e4883 100644 --- a/polkadot/runtime/common/src/lib.rs +++ b/polkadot/runtime/common/src/lib.rs @@ -27,7 +27,6 @@ pub mod impls; pub mod paras_registrar; pub mod paras_sudo_wrapper; pub mod purchase; -pub mod session; pub mod slot_range; pub mod slots; pub mod traits; diff --git a/polkadot/runtime/common/src/session/migration.rs b/polkadot/runtime/common/src/session/migration.rs deleted file mode 100644 index 604499b66d..0000000000 --- a/polkadot/runtime/common/src/session/migration.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -use frame_support::{ - storage::storage_prefix, - traits::{Get, OnRuntimeUpgrade}, - weights::Weight, -}; -use pallet_session::Config; -use sp_io::{storage::clear_prefix, KillStorageResult}; -#[cfg(feature = "try-runtime")] -use sp_std::vec::Vec; - -/// This migration clears everything under `Session::HistoricalSessions` -/// and `Session::StoredRange` that were not cleared when -/// the pallet was moved to its new prefix (`Historical`) -pub struct ClearOldSessionStorage(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade for ClearOldSessionStorage { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - Ok(Vec::new()) - } - - fn on_runtime_upgrade() -> Weight { - let prefix = storage_prefix(b"Session", b"StoredRange"); - let keys_removed_stored_range = match clear_prefix(&prefix, None) { - KillStorageResult::AllRemoved(value) => value, - KillStorageResult::SomeRemaining(value) => { - log::error!( - "`clear_prefix` failed to remove all keys. THIS SHOULD NEVER HAPPEN! ๐Ÿšจ", - ); - value - }, - } as u64; - - let prefix = storage_prefix(b"Session", b"HistoricalSessions"); - let keys_removed_historical_sessions = match clear_prefix(&prefix, None) { - KillStorageResult::AllRemoved(value) => value, - KillStorageResult::SomeRemaining(value) => { - log::error!( - "`clear_prefix` failed to remove all keys. THIS SHOULD NEVER HAPPEN! ๐Ÿšจ", - ); - value - }, - } as u64; - - let keys_removed = keys_removed_stored_range + keys_removed_historical_sessions; - log::info!("Removed {} keys ๐Ÿงน", keys_removed); - - T::DbWeight::get().reads_writes(keys_removed, keys_removed) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { - Ok(()) - } -} diff --git a/polkadot/runtime/common/src/session/mod.rs b/polkadot/runtime/common/src/session/mod.rs deleted file mode 100644 index 5f99cba0eb..0000000000 --- a/polkadot/runtime/common/src/session/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -pub mod migration; diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index c8e858b468..1e47f6c834 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1521,40 +1521,12 @@ impl Get for NominationPoolsMigrationV4OldPallet { /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. -pub type Migrations = ( - migrations::V0940, - migrations::V0941, - migrations::V0942, - migrations::V0943, - migrations::Unreleased, -); +pub type Migrations = (migrations::Unreleased,); /// The runtime migrations per release. #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; - use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; - - pub type V0940 = ( - pallet_nomination_pools::migration::v4::MigrateToV4< - Runtime, - NominationPoolsMigrationV4OldPallet, - >, - pallet_nomination_pools::migration::v5::MigrateToV5, - ); - pub type V0941 = (); // Node only release - no migrations. - pub type V0942 = ( - parachains_configuration::migration::v5::MigrateToV5, - pallet_offences::migration::v1::MigrateToV1, - runtime_common::session::migration::ClearOldSessionStorage, - ); - - pub type V0943 = ( - SetStorageVersions, - // Remove UMP dispatch queue - parachains_configuration::migration::v6::MigrateToV6, - ump_migrations::UpdateUmpLimits, - ); /// Unreleased migrations. Add new ones here: pub type Unreleased = ( @@ -1567,46 +1539,6 @@ pub mod migrations { pallet_im_online::migration::v1::Migration, parachains_configuration::migration::v7::MigrateToV7, ); - - /// Migrations that set `StorageVersion`s we missed to set. - pub struct SetStorageVersions; - - impl OnRuntimeUpgrade for SetStorageVersions { - fn on_runtime_upgrade() -> Weight { - // The `NisCounterpartBalances` pallet was added to the chain after/with the migration. - // So, the migration never needed to be executed, but we also did not set the proper `StorageVersion`. - let storage_version = NisCounterpartBalances::on_chain_storage_version(); - if storage_version < 1 { - StorageVersion::new(1).put::(); - } - - // Was missed as part of: `runtime_common::session::migration::ClearOldSessionStorage`. - let storage_version = Historical::on_chain_storage_version(); - if storage_version < 1 { - StorageVersion::new(1).put::(); - } - - RocksDbWeight::get().reads_writes(2, 2) - } - } -} - -/// Helpers to configure the ump migrations. -pub mod ump_migrations { - use runtime_parachains::configuration::migration_ump; - - pub const MAX_UPWARD_QUEUE_SIZE: u32 = 4 * 1024 * 1024; - pub const MAX_UPWARD_QUEUE_COUNT: u32 = 699050; - pub const MAX_UPWARD_MESSAGE_SIZE: u32 = (1 << 16) - 5; // Checked in test `max_upward_message_size`. - pub const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32 = 128; - - pub type UpdateUmpLimits = migration_ump::latest::ScheduleConfigUpdate< - super::Runtime, - MAX_UPWARD_QUEUE_SIZE, - MAX_UPWARD_QUEUE_COUNT, - MAX_UPWARD_MESSAGE_SIZE, - MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE, - >; } /// Unchecked extrinsic type as expected by this runtime. diff --git a/polkadot/runtime/kusama/src/tests.rs b/polkadot/runtime/kusama/src/tests.rs index f126185ded..4b071ec387 100644 --- a/polkadot/runtime/kusama/src/tests.rs +++ b/polkadot/runtime/kusama/src/tests.rs @@ -146,11 +146,3 @@ fn nominator_limit() { fn call_size() { RuntimeCall::assert_size_under(230); } - -#[test] -fn max_upward_message_size() { - assert_eq!( - ump_migrations::MAX_UPWARD_MESSAGE_SIZE, - pallet_message_queue::MaxMessageLenOf::::get() - ); -} diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 5b85d2a105..8999ffb0da 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -37,7 +37,6 @@ mod tests; mod benchmarking; pub mod migration; -pub mod migration_ump; pub use pallet::*; diff --git a/polkadot/runtime/parachains/src/configuration/migration.rs b/polkadot/runtime/parachains/src/configuration/migration.rs index d36e32be65..ae035abac5 100644 --- a/polkadot/runtime/parachains/src/configuration/migration.rs +++ b/polkadot/runtime/parachains/src/configuration/migration.rs @@ -16,8 +16,5 @@ //! A module that is responsible for migration of storage. -use primitives::ExecutorParams; - -pub mod v5; pub mod v6; pub mod v7; diff --git a/polkadot/runtime/parachains/src/configuration/migration/v5.rs b/polkadot/runtime/parachains/src/configuration/migration/v5.rs deleted file mode 100644 index 9262d33fb5..0000000000 --- a/polkadot/runtime/parachains/src/configuration/migration/v5.rs +++ /dev/null @@ -1,511 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -//! A module that is responsible for migration of storage. - -use crate::configuration::{self, Config, Pallet, MAX_POV_SIZE}; -use frame_support::{ - pallet_prelude::*, - traits::{Defensive, StorageVersion}, - weights::Weight, -}; -use frame_system::pallet_prelude::BlockNumberFor; -use primitives::vstaging::AsyncBackingParams; -use sp_std::vec::Vec; - -use super::*; -use frame_support::{traits::OnRuntimeUpgrade, weights::constants::WEIGHT_REF_TIME_PER_MILLIS}; -use primitives::{Balance, SessionIndex}; -#[cfg(feature = "try-runtime")] -use sp_std::prelude::*; - -// Copied over from configuration.rs @ de9e147695b9f1be8bd44e07861a31e483c8343a and removed -// all the comments, and changed the Weight struct to OldWeight -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, Clone)] -pub struct V4HostConfiguration { - pub max_code_size: u32, - pub max_head_data_size: u32, - pub max_upward_queue_count: u32, - pub max_upward_queue_size: u32, - pub max_upward_message_size: u32, - pub max_upward_message_num_per_candidate: u32, - pub hrmp_max_message_num_per_candidate: u32, - pub validation_upgrade_cooldown: BlockNumber, - pub validation_upgrade_delay: BlockNumber, - pub max_pov_size: u32, - pub max_downward_message_size: u32, - pub ump_service_total_weight: Weight, - pub hrmp_max_parachain_outbound_channels: u32, - pub hrmp_max_parathread_outbound_channels: u32, - pub hrmp_sender_deposit: Balance, - pub hrmp_recipient_deposit: Balance, - pub hrmp_channel_max_capacity: u32, - pub hrmp_channel_max_total_size: u32, - pub hrmp_max_parachain_inbound_channels: u32, - pub hrmp_max_parathread_inbound_channels: u32, - pub hrmp_channel_max_message_size: u32, - pub code_retention_period: BlockNumber, - pub parathread_cores: u32, - pub parathread_retries: u32, - pub group_rotation_frequency: BlockNumber, - pub chain_availability_period: BlockNumber, - pub thread_availability_period: BlockNumber, - pub scheduling_lookahead: u32, - pub max_validators_per_core: Option, - pub max_validators: Option, - pub dispute_period: SessionIndex, - pub dispute_post_conclusion_acceptance_period: BlockNumber, - pub dispute_conclusion_by_time_out_period: BlockNumber, - pub no_show_slots: u32, - pub n_delay_tranches: u32, - pub zeroth_delay_tranche_width: u32, - pub needed_approvals: u32, - pub relay_vrf_modulo_samples: u32, - pub ump_max_individual_weight: Weight, - pub pvf_checking_enabled: bool, - pub pvf_voting_ttl: SessionIndex, - pub minimum_validation_upgrade_delay: BlockNumber, -} - -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, Clone)] -pub struct V5HostConfiguration { - pub max_code_size: u32, - pub max_head_data_size: u32, - pub max_upward_queue_count: u32, - pub max_upward_queue_size: u32, - pub max_upward_message_size: u32, - pub max_upward_message_num_per_candidate: u32, - pub hrmp_max_message_num_per_candidate: u32, - pub validation_upgrade_cooldown: BlockNumber, - pub validation_upgrade_delay: BlockNumber, - pub async_backing_params: AsyncBackingParams, - pub max_pov_size: u32, - pub max_downward_message_size: u32, - pub ump_service_total_weight: Weight, - pub hrmp_max_parachain_outbound_channels: u32, - pub hrmp_max_parathread_outbound_channels: u32, - pub hrmp_sender_deposit: Balance, - pub hrmp_recipient_deposit: Balance, - pub hrmp_channel_max_capacity: u32, - pub hrmp_channel_max_total_size: u32, - pub hrmp_max_parachain_inbound_channels: u32, - pub hrmp_max_parathread_inbound_channels: u32, - pub hrmp_channel_max_message_size: u32, - pub executor_params: ExecutorParams, - pub code_retention_period: BlockNumber, - pub parathread_cores: u32, - pub parathread_retries: u32, - pub group_rotation_frequency: BlockNumber, - pub chain_availability_period: BlockNumber, - pub thread_availability_period: BlockNumber, - pub scheduling_lookahead: u32, - pub max_validators_per_core: Option, - pub max_validators: Option, - pub dispute_period: SessionIndex, - pub dispute_post_conclusion_acceptance_period: BlockNumber, - pub no_show_slots: u32, - pub n_delay_tranches: u32, - pub zeroth_delay_tranche_width: u32, - pub needed_approvals: u32, - pub relay_vrf_modulo_samples: u32, - pub ump_max_individual_weight: Weight, - pub pvf_checking_enabled: bool, - pub pvf_voting_ttl: SessionIndex, - pub minimum_validation_upgrade_delay: BlockNumber, -} - -mod v4 { - use super::*; - - #[frame_support::storage_alias] - pub(crate) type ActiveConfig = - StorageValue, V4HostConfiguration>, OptionQuery>; - - #[frame_support::storage_alias] - pub(crate) type PendingConfigs = StorageValue< - Pallet, - Vec<(SessionIndex, V4HostConfiguration>)>, - OptionQuery, - >; -} - -mod v5 { - use super::*; - - #[frame_support::storage_alias] - pub(crate) type ActiveConfig = - StorageValue, V5HostConfiguration>, OptionQuery>; - - #[frame_support::storage_alias] - pub(crate) type PendingConfigs = StorageValue< - Pallet, - Vec<(SessionIndex, V5HostConfiguration>)>, - OptionQuery, - >; -} - -impl> Default for V4HostConfiguration { - fn default() -> Self { - Self { - group_rotation_frequency: 1u32.into(), - chain_availability_period: 1u32.into(), - thread_availability_period: 1u32.into(), - no_show_slots: 1u32.into(), - validation_upgrade_cooldown: Default::default(), - validation_upgrade_delay: Default::default(), - code_retention_period: Default::default(), - max_code_size: Default::default(), - max_pov_size: Default::default(), - max_head_data_size: Default::default(), - parathread_cores: Default::default(), - parathread_retries: Default::default(), - scheduling_lookahead: Default::default(), - max_validators_per_core: Default::default(), - max_validators: None, - dispute_period: 6, - dispute_post_conclusion_acceptance_period: 100.into(), - dispute_conclusion_by_time_out_period: 200.into(), - n_delay_tranches: Default::default(), - zeroth_delay_tranche_width: Default::default(), - needed_approvals: Default::default(), - relay_vrf_modulo_samples: Default::default(), - max_upward_queue_count: Default::default(), - max_upward_queue_size: Default::default(), - max_downward_message_size: Default::default(), - ump_service_total_weight: Default::default(), - max_upward_message_size: Default::default(), - max_upward_message_num_per_candidate: Default::default(), - hrmp_sender_deposit: Default::default(), - hrmp_recipient_deposit: Default::default(), - hrmp_channel_max_capacity: Default::default(), - hrmp_channel_max_total_size: Default::default(), - hrmp_max_parachain_inbound_channels: Default::default(), - hrmp_max_parathread_inbound_channels: Default::default(), - hrmp_channel_max_message_size: Default::default(), - hrmp_max_parachain_outbound_channels: Default::default(), - hrmp_max_parathread_outbound_channels: Default::default(), - hrmp_max_message_num_per_candidate: Default::default(), - ump_max_individual_weight: Weight::from_parts( - 20u64 * WEIGHT_REF_TIME_PER_MILLIS, - MAX_POV_SIZE as u64, - ), - pvf_checking_enabled: false, - pvf_voting_ttl: 2u32.into(), - minimum_validation_upgrade_delay: 2.into(), - } - } -} - -impl> Default for V5HostConfiguration { - fn default() -> Self { - Self { - group_rotation_frequency: 1u32.into(), - chain_availability_period: 1u32.into(), - thread_availability_period: 1u32.into(), - no_show_slots: 1u32.into(), - validation_upgrade_cooldown: Default::default(), - validation_upgrade_delay: Default::default(), - code_retention_period: Default::default(), - max_code_size: Default::default(), - max_pov_size: Default::default(), - max_head_data_size: Default::default(), - parathread_cores: Default::default(), - parathread_retries: Default::default(), - scheduling_lookahead: Default::default(), - max_validators_per_core: Default::default(), - max_validators: None, - dispute_period: 6, - dispute_post_conclusion_acceptance_period: 100.into(), - n_delay_tranches: Default::default(), - zeroth_delay_tranche_width: Default::default(), - needed_approvals: Default::default(), - relay_vrf_modulo_samples: Default::default(), - max_upward_queue_count: Default::default(), - max_upward_queue_size: Default::default(), - max_downward_message_size: Default::default(), - ump_service_total_weight: Default::default(), - max_upward_message_size: Default::default(), - max_upward_message_num_per_candidate: Default::default(), - hrmp_sender_deposit: Default::default(), - hrmp_recipient_deposit: Default::default(), - hrmp_channel_max_capacity: Default::default(), - hrmp_channel_max_total_size: Default::default(), - hrmp_max_parachain_inbound_channels: Default::default(), - hrmp_max_parathread_inbound_channels: Default::default(), - hrmp_channel_max_message_size: Default::default(), - hrmp_max_parachain_outbound_channels: Default::default(), - hrmp_max_parathread_outbound_channels: Default::default(), - hrmp_max_message_num_per_candidate: Default::default(), - ump_max_individual_weight: Weight::from_parts( - 20u64 * WEIGHT_REF_TIME_PER_MILLIS, - MAX_POV_SIZE as u64, - ), - pvf_checking_enabled: false, - pvf_voting_ttl: 2u32.into(), - minimum_validation_upgrade_delay: 2.into(), - async_backing_params: AsyncBackingParams { - max_candidate_depth: 0, - allowed_ancestry_len: 0, - }, - executor_params: Default::default(), - } - } -} - -pub struct MigrateToV5(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade for MigrateToV5 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); - Ok(Vec::new()) - } - - fn on_runtime_upgrade() -> Weight { - log::info!(target: configuration::LOG_TARGET, "MigrateToV5 started"); - if StorageVersion::get::>() == 4 { - let weight_consumed = migrate_to_v5::(); - - log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully"); - StorageVersion::new(5).put::>(); - - weight_consumed - } else { - log::warn!(target: configuration::LOG_TARGET, "MigrateToV5 should be removed."); - T::DbWeight::get().reads(1) - } - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { - log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); - ensure!( - StorageVersion::get::>() >= 5, - "Storage version should be greater or equal to 5 after the migration" - ); - - Ok(()) - } -} - -fn migrate_to_v5() -> Weight { - // Unusual formatting is justified: - // - make it easier to verify that fields assign what they supposed to assign. - // - this code is transient and will be removed after all migrations are done. - // - this code is important enough to optimize for legibility sacrificing consistency. - #[rustfmt::skip] - let translate = - |pre: V4HostConfiguration>| -> - V5HostConfiguration> - { - V5HostConfiguration { -max_code_size : pre.max_code_size, -max_head_data_size : pre.max_head_data_size, -max_upward_queue_count : pre.max_upward_queue_count, -max_upward_queue_size : pre.max_upward_queue_size, -max_upward_message_size : pre.max_upward_message_size, -max_upward_message_num_per_candidate : pre.max_upward_message_num_per_candidate, -hrmp_max_message_num_per_candidate : pre.hrmp_max_message_num_per_candidate, -validation_upgrade_cooldown : pre.validation_upgrade_cooldown, -validation_upgrade_delay : pre.validation_upgrade_delay, -max_pov_size : pre.max_pov_size, -max_downward_message_size : pre.max_downward_message_size, -ump_service_total_weight : pre.ump_service_total_weight, -hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels, -hrmp_max_parathread_outbound_channels : pre.hrmp_max_parathread_outbound_channels, -hrmp_sender_deposit : pre.hrmp_sender_deposit, -hrmp_recipient_deposit : pre.hrmp_recipient_deposit, -hrmp_channel_max_capacity : pre.hrmp_channel_max_capacity, -hrmp_channel_max_total_size : pre.hrmp_channel_max_total_size, -hrmp_max_parachain_inbound_channels : pre.hrmp_max_parachain_inbound_channels, -hrmp_max_parathread_inbound_channels : pre.hrmp_max_parathread_inbound_channels, -hrmp_channel_max_message_size : pre.hrmp_channel_max_message_size, -code_retention_period : pre.code_retention_period, -parathread_cores : pre.parathread_cores, -parathread_retries : pre.parathread_retries, -group_rotation_frequency : pre.group_rotation_frequency, -chain_availability_period : pre.chain_availability_period, -thread_availability_period : pre.thread_availability_period, -scheduling_lookahead : pre.scheduling_lookahead, -max_validators_per_core : pre.max_validators_per_core, -max_validators : pre.max_validators, -dispute_period : pre.dispute_period, -dispute_post_conclusion_acceptance_period: pre.dispute_post_conclusion_acceptance_period, -no_show_slots : pre.no_show_slots, -n_delay_tranches : pre.n_delay_tranches, -zeroth_delay_tranche_width : pre.zeroth_delay_tranche_width, -needed_approvals : pre.needed_approvals, -relay_vrf_modulo_samples : pre.relay_vrf_modulo_samples, -ump_max_individual_weight : pre.ump_max_individual_weight, -pvf_checking_enabled : pre.pvf_checking_enabled, -pvf_voting_ttl : pre.pvf_voting_ttl, -minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay, - -// Default values are zeroes, thus it's ensured allowed ancestry never crosses the upgrade block. -async_backing_params : AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: 0 }, - -// Default executor parameters set is empty -executor_params : Default::default(), - } - }; - - let v4 = v4::ActiveConfig::::get() - .defensive_proof("Could not decode old config") - .unwrap_or_default(); - let v5 = translate(v4); - v5::ActiveConfig::::set(Some(v5)); - - let pending_v4 = v4::PendingConfigs::::get() - .defensive_proof("Could not decode old pending") - .unwrap_or_default(); - let mut pending_v5 = Vec::new(); - - for (session, v4) in pending_v4.into_iter() { - let v5 = translate(v4); - pending_v5.push((session, v5)); - } - v5::PendingConfigs::::set(Some(pending_v5.clone())); - - let num_configs = (pending_v5.len() + 1) as u64; - T::DbWeight::get().reads_writes(num_configs, num_configs) -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::mock::{new_test_ext, Test}; - use primitives::ExecutorParams; - - #[test] - fn v4_deserialized_from_actual_data() { - // Example how to get new `raw_config`: - // We'll obtain the raw_config at a specified a block - // Steps: - // 1. Go to Polkadot.js -> Developer -> Chain state -> Storage: https://polkadot.js.org/apps/#/chainstate - // 2. Set these parameters: - // 2.1. selected state query: configuration; activeConfig(): PolkadotRuntimeParachainsConfigurationHostConfiguration - // 2.2. blockhash to query at: 0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53 (the hash of the block) - // 2.3. Note the value of encoded storage key -> 0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385 for the referenced block. - // 2.4. You'll also need the decoded values to update the test. - // 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage - // 3.1 Enter the encoded storage key and you get the raw config. - - // This exceeds the maximal line width length, but that's fine, since this is not code and - // doesn't need to be read and also leaving it as one line allows to easily copy it. - let raw_config = hex_literal::hex!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c80000000600000058020000580200000200000059000000000000001e000000280000000700c817a80402004001010200000014000000"]; - - let v4 = - V4HostConfiguration::::decode(&mut &raw_config[..]).unwrap(); - - // We check only a sample of the values here. If we missed any fields or messed up data types - // that would skew all the fields coming after. - assert_eq!(v4.max_code_size, 10_485_760); - assert_eq!(v4.validation_upgrade_cooldown, 3600); - assert_eq!(v4.max_pov_size, 5_242_880); - assert_eq!(v4.hrmp_channel_max_message_size, 102_400); - assert_eq!(v4.n_delay_tranches, 89); - assert_eq!(v4.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880)); - assert_eq!(v4.minimum_validation_upgrade_delay, 20); - } - - #[test] - fn test_migrate_to_v5() { - // Host configuration has lots of fields. However, in this migration we only remove one field. - // The most important part to check are a couple of the last fields. We also pick - // extra fields to check arbitrarily, e.g. depending on their position (i.e. the middle) and - // also their type. - // - // We specify only the picked fields and the rest should be provided by the `Default` - // implementation. That implementation is copied over between the two types and should work - // fine. - let v4 = V4HostConfiguration:: { - ump_max_individual_weight: Weight::from_parts(0x71616e6f6e0au64, 0x71616e6f6e0au64), - needed_approvals: 69, - thread_availability_period: 55, - hrmp_recipient_deposit: 1337, - max_pov_size: 1111, - chain_availability_period: 33, - minimum_validation_upgrade_delay: 20, - ..Default::default() - }; - - let mut pending_configs = Vec::new(); - pending_configs.push((100, v4.clone())); - pending_configs.push((300, v4.clone())); - - new_test_ext(Default::default()).execute_with(|| { - // Implant the v4 version in the state. - v4::ActiveConfig::::set(Some(v4)); - v4::PendingConfigs::::set(Some(pending_configs)); - - migrate_to_v5::(); - - let v5 = v5::ActiveConfig::::get().unwrap(); - let mut configs_to_check = v5::PendingConfigs::::get().unwrap(); - configs_to_check.push((0, v5.clone())); - - for (_, v4) in configs_to_check { - #[rustfmt::skip] - { - assert_eq!(v4.max_code_size , v5.max_code_size); - assert_eq!(v4.max_head_data_size , v5.max_head_data_size); - assert_eq!(v4.max_upward_queue_count , v5.max_upward_queue_count); - assert_eq!(v4.max_upward_queue_size , v5.max_upward_queue_size); - assert_eq!(v4.max_upward_message_size , v5.max_upward_message_size); - assert_eq!(v4.max_upward_message_num_per_candidate , v5.max_upward_message_num_per_candidate); - assert_eq!(v4.hrmp_max_message_num_per_candidate , v5.hrmp_max_message_num_per_candidate); - assert_eq!(v4.validation_upgrade_cooldown , v5.validation_upgrade_cooldown); - assert_eq!(v4.validation_upgrade_delay , v5.validation_upgrade_delay); - assert_eq!(v4.max_pov_size , v5.max_pov_size); - assert_eq!(v4.max_downward_message_size , v5.max_downward_message_size); - assert_eq!(v4.ump_service_total_weight , v5.ump_service_total_weight); - assert_eq!(v4.hrmp_max_parachain_outbound_channels , v5.hrmp_max_parachain_outbound_channels); - assert_eq!(v4.hrmp_max_parathread_outbound_channels , v5.hrmp_max_parathread_outbound_channels); - assert_eq!(v4.hrmp_sender_deposit , v5.hrmp_sender_deposit); - assert_eq!(v4.hrmp_recipient_deposit , v5.hrmp_recipient_deposit); - assert_eq!(v4.hrmp_channel_max_capacity , v5.hrmp_channel_max_capacity); - assert_eq!(v4.hrmp_channel_max_total_size , v5.hrmp_channel_max_total_size); - assert_eq!(v4.hrmp_max_parachain_inbound_channels , v5.hrmp_max_parachain_inbound_channels); - assert_eq!(v4.hrmp_max_parathread_inbound_channels , v5.hrmp_max_parathread_inbound_channels); - assert_eq!(v4.hrmp_channel_max_message_size , v5.hrmp_channel_max_message_size); - assert_eq!(v4.code_retention_period , v5.code_retention_period); - assert_eq!(v4.parathread_cores , v5.parathread_cores); - assert_eq!(v4.parathread_retries , v5.parathread_retries); - assert_eq!(v4.group_rotation_frequency , v5.group_rotation_frequency); - assert_eq!(v4.chain_availability_period , v5.chain_availability_period); - assert_eq!(v4.thread_availability_period , v5.thread_availability_period); - assert_eq!(v4.scheduling_lookahead , v5.scheduling_lookahead); - assert_eq!(v4.max_validators_per_core , v5.max_validators_per_core); - assert_eq!(v4.max_validators , v5.max_validators); - assert_eq!(v4.dispute_period , v5.dispute_period); - assert_eq!(v4.no_show_slots , v5.no_show_slots); - assert_eq!(v4.n_delay_tranches , v5.n_delay_tranches); - assert_eq!(v4.zeroth_delay_tranche_width , v5.zeroth_delay_tranche_width); - assert_eq!(v4.needed_approvals , v5.needed_approvals); - assert_eq!(v4.relay_vrf_modulo_samples , v5.relay_vrf_modulo_samples); - assert_eq!(v4.ump_max_individual_weight , v5.ump_max_individual_weight); - assert_eq!(v4.pvf_checking_enabled , v5.pvf_checking_enabled); - assert_eq!(v4.pvf_voting_ttl , v5.pvf_voting_ttl); - assert_eq!(v4.minimum_validation_upgrade_delay , v5.minimum_validation_upgrade_delay); - }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. - - // additional checks for async backing. - assert_eq!(v5.async_backing_params.allowed_ancestry_len, 0); - assert_eq!(v5.async_backing_params.max_candidate_depth, 0); - assert_eq!(v5.executor_params, ExecutorParams::new()); - } - }); - } -} diff --git a/polkadot/runtime/parachains/src/configuration/migration/v6.rs b/polkadot/runtime/parachains/src/configuration/migration/v6.rs index da08d9cd76..beed54deaf 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v6.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v6.rs @@ -14,24 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! A module that is responsible for migration of storage. +//! Contains the V6 storage definition of the host configuration. -use crate::configuration::{self, Config, Pallet}; -use frame_support::{ - pallet_prelude::*, - traits::{Defensive, StorageVersion}, - weights::Weight, -}; +use crate::configuration::{Config, Pallet}; +use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::BlockNumberFor; use sp_std::vec::Vec; -use frame_support::traits::OnRuntimeUpgrade; use primitives::{vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex}; #[cfg(feature = "try-runtime")] use sp_std::prelude::*; -use super::v5::V5HostConfiguration; - #[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, Clone)] pub struct V6HostConfiguration { pub max_code_size: u32, @@ -128,21 +121,6 @@ impl> Default for V6HostConfiguration = - StorageValue, V5HostConfiguration>, OptionQuery>; - - #[frame_support::storage_alias] - pub(crate) type PendingConfigs = StorageValue< - Pallet, - Vec<(SessionIndex, V5HostConfiguration>)>, - OptionQuery, - >; -} - mod v6 { use super::*; @@ -157,238 +135,3 @@ mod v6 { OptionQuery, >; } - -pub struct MigrateToV6(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade for MigrateToV6 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); - Ok(Vec::new()) - } - - fn on_runtime_upgrade() -> Weight { - log::info!(target: configuration::LOG_TARGET, "MigrateToV6 started"); - if StorageVersion::get::>() == 5 { - let weight_consumed = migrate_to_v6::(); - - log::info!(target: configuration::LOG_TARGET, "MigrateToV6 executed successfully"); - StorageVersion::new(6).put::>(); - - weight_consumed - } else { - log::warn!(target: configuration::LOG_TARGET, "MigrateToV6 should be removed."); - T::DbWeight::get().reads(1) - } - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { - log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); - ensure!( - StorageVersion::get::>() >= 6, - "Storage version should be >= 6 after the migration" - ); - - Ok(()) - } -} - -fn migrate_to_v6() -> Weight { - // Unusual formatting is justified: - // - make it easier to verify that fields assign what they supposed to assign. - // - this code is transient and will be removed after all migrations are done. - // - this code is important enough to optimize for legibility sacrificing consistency. - #[rustfmt::skip] - let translate = - |pre: V5HostConfiguration>| -> - V6HostConfiguration> - { - V6HostConfiguration { -max_code_size : pre.max_code_size, -max_head_data_size : pre.max_head_data_size, -max_upward_queue_count : pre.max_upward_queue_count, -max_upward_queue_size : pre.max_upward_queue_size, -max_upward_message_size : pre.max_upward_message_size, -max_upward_message_num_per_candidate : pre.max_upward_message_num_per_candidate, -hrmp_max_message_num_per_candidate : pre.hrmp_max_message_num_per_candidate, -validation_upgrade_cooldown : pre.validation_upgrade_cooldown, -validation_upgrade_delay : pre.validation_upgrade_delay, -max_pov_size : pre.max_pov_size, -max_downward_message_size : pre.max_downward_message_size, -hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels, -hrmp_max_parathread_outbound_channels : pre.hrmp_max_parathread_outbound_channels, -hrmp_sender_deposit : pre.hrmp_sender_deposit, -hrmp_recipient_deposit : pre.hrmp_recipient_deposit, -hrmp_channel_max_capacity : pre.hrmp_channel_max_capacity, -hrmp_channel_max_total_size : pre.hrmp_channel_max_total_size, -hrmp_max_parachain_inbound_channels : pre.hrmp_max_parachain_inbound_channels, -hrmp_max_parathread_inbound_channels : pre.hrmp_max_parathread_inbound_channels, -hrmp_channel_max_message_size : pre.hrmp_channel_max_message_size, -code_retention_period : pre.code_retention_period, -parathread_cores : pre.parathread_cores, -parathread_retries : pre.parathread_retries, -group_rotation_frequency : pre.group_rotation_frequency, -chain_availability_period : pre.chain_availability_period, -thread_availability_period : pre.thread_availability_period, -scheduling_lookahead : pre.scheduling_lookahead, -max_validators_per_core : pre.max_validators_per_core, -max_validators : pre.max_validators, -dispute_period : pre.dispute_period, -dispute_post_conclusion_acceptance_period: pre.dispute_post_conclusion_acceptance_period, -no_show_slots : pre.no_show_slots, -n_delay_tranches : pre.n_delay_tranches, -zeroth_delay_tranche_width : pre.zeroth_delay_tranche_width, -needed_approvals : pre.needed_approvals, -relay_vrf_modulo_samples : pre.relay_vrf_modulo_samples, -pvf_checking_enabled : pre.pvf_checking_enabled, -pvf_voting_ttl : pre.pvf_voting_ttl, -minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay, -async_backing_params : pre.async_backing_params, -executor_params : pre.executor_params, - } - }; - - let v5 = v5::ActiveConfig::::get() - .defensive_proof("Could not decode old config") - .unwrap_or_default(); - let v6 = translate(v5); - v6::ActiveConfig::::set(Some(v6)); - - let pending_v5 = v5::PendingConfigs::::get() - .defensive_proof("Could not decode old pending") - .unwrap_or_default(); - let mut pending_v6 = Vec::new(); - - for (session, v5) in pending_v5.into_iter() { - let v6 = translate(v5); - pending_v6.push((session, v6)); - } - v6::PendingConfigs::::set(Some(pending_v6.clone())); - - let num_configs = (pending_v6.len() + 1) as u64; - T::DbWeight::get().reads_writes(num_configs, num_configs) -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::mock::{new_test_ext, Test}; - - #[test] - fn v5_deserialized_from_actual_data() { - // Example how to get new `raw_config`: - // We'll obtain the raw_config at a specified a block - // Steps: - // 1. Go to Polkadot.js -> Developer -> Chain state -> Storage: https://polkadot.js.org/apps/#/chainstate - // 2. Set these parameters: - // 2.1. selected state query: configuration; activeConfig(): PolkadotRuntimeParachainsConfigurationHostConfiguration - // 2.2. blockhash to query at: 0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53 (the hash of the block) - // 2.3. Note the value of encoded storage key -> 0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385 for the referenced block. - // 2.4. You'll also need the decoded values to update the test. - // 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage - // 3.1 Enter the encoded storage key and you get the raw config. - - // This exceeds the maximal line width length, but that's fine, since this is not code and - // doesn't need to be read and also leaving it as one line allows to easily copy it. - let raw_config = hex_literal::hex!["00005000005000000a00000000c8000000c800000a0000000a000000c80000006400000000000000000000000000500000c800000700e8764817020040010a0000000000000000c0220fca950300000000000000000000c0220fca9503000000000000000000e8030000009001000a0000000000000000900100008070000000000000000000000a000000050000000500000001000000010500000001c8000000060000005802000002000000280000000000000002000000010000000700c817a8040200400101020000000f000000"]; - - let v5 = - V5HostConfiguration::::decode(&mut &raw_config[..]).unwrap(); - - // We check only a sample of the values here. If we missed any fields or messed up data types - // that would skew all the fields coming after. - assert_eq!(v5.max_code_size, 5242880); - assert_eq!(v5.validation_upgrade_cooldown, 200); - assert_eq!(v5.max_pov_size, 5_242_880); - assert_eq!(v5.hrmp_channel_max_message_size, 102_400); - assert_eq!(v5.n_delay_tranches, 40); - assert_eq!(v5.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880)); - assert_eq!(v5.minimum_validation_upgrade_delay, 15); // This is the last field in the struct. - assert_eq!(v5.group_rotation_frequency, 10); - } - - #[test] - fn test_migrate_to_v6() { - // Host configuration has lots of fields. However, in this migration we only remove one field. - // The most important part to check are a couple of the last fields. We also pick - // extra fields to check arbitrarily, e.g. depending on their position (i.e. the middle) and - // also their type. - // - // We specify only the picked fields and the rest should be provided by the `Default` - // implementation. That implementation is copied over between the two types and should work - // fine. - let v5 = V5HostConfiguration:: { - ump_max_individual_weight: Weight::from_parts(0x71616e6f6e0au64, 0x71616e6f6e0au64), - needed_approvals: 69, - thread_availability_period: 55, - hrmp_recipient_deposit: 1337, - max_pov_size: 1111, - chain_availability_period: 33, - minimum_validation_upgrade_delay: 20, - ..Default::default() - }; - - let mut pending_configs = Vec::new(); - pending_configs.push((100, v5.clone())); - pending_configs.push((300, v5.clone())); - - new_test_ext(Default::default()).execute_with(|| { - // Implant the v5 version in the state. - v5::ActiveConfig::::set(Some(v5)); - v5::PendingConfigs::::set(Some(pending_configs)); - - migrate_to_v6::(); - - let v6 = v6::ActiveConfig::::get().unwrap(); - let mut configs_to_check = v6::PendingConfigs::::get().unwrap(); - configs_to_check.push((0, v6.clone())); - - for (_, v5) in configs_to_check { - #[rustfmt::skip] - { - assert_eq!(v5.max_code_size , v6.max_code_size); - assert_eq!(v5.max_head_data_size , v6.max_head_data_size); - assert_eq!(v5.max_upward_queue_count , v6.max_upward_queue_count); - assert_eq!(v5.max_upward_queue_size , v6.max_upward_queue_size); - assert_eq!(v5.max_upward_message_size , v6.max_upward_message_size); - assert_eq!(v5.max_upward_message_num_per_candidate , v6.max_upward_message_num_per_candidate); - assert_eq!(v5.hrmp_max_message_num_per_candidate , v6.hrmp_max_message_num_per_candidate); - assert_eq!(v5.validation_upgrade_cooldown , v6.validation_upgrade_cooldown); - assert_eq!(v5.validation_upgrade_delay , v6.validation_upgrade_delay); - assert_eq!(v5.max_pov_size , v6.max_pov_size); - assert_eq!(v5.max_downward_message_size , v6.max_downward_message_size); - assert_eq!(v5.hrmp_max_parachain_outbound_channels , v6.hrmp_max_parachain_outbound_channels); - assert_eq!(v5.hrmp_max_parathread_outbound_channels , v6.hrmp_max_parathread_outbound_channels); - assert_eq!(v5.hrmp_sender_deposit , v6.hrmp_sender_deposit); - assert_eq!(v5.hrmp_recipient_deposit , v6.hrmp_recipient_deposit); - assert_eq!(v5.hrmp_channel_max_capacity , v6.hrmp_channel_max_capacity); - assert_eq!(v5.hrmp_channel_max_total_size , v6.hrmp_channel_max_total_size); - assert_eq!(v5.hrmp_max_parachain_inbound_channels , v6.hrmp_max_parachain_inbound_channels); - assert_eq!(v5.hrmp_max_parathread_inbound_channels , v6.hrmp_max_parathread_inbound_channels); - assert_eq!(v5.hrmp_channel_max_message_size , v6.hrmp_channel_max_message_size); - assert_eq!(v5.code_retention_period , v6.code_retention_period); - assert_eq!(v5.parathread_cores , v6.parathread_cores); - assert_eq!(v5.parathread_retries , v6.parathread_retries); - assert_eq!(v5.group_rotation_frequency , v6.group_rotation_frequency); - assert_eq!(v5.chain_availability_period , v6.chain_availability_period); - assert_eq!(v5.thread_availability_period , v6.thread_availability_period); - assert_eq!(v5.scheduling_lookahead , v6.scheduling_lookahead); - assert_eq!(v5.max_validators_per_core , v6.max_validators_per_core); - assert_eq!(v5.max_validators , v6.max_validators); - assert_eq!(v5.dispute_period , v6.dispute_period); - assert_eq!(v5.no_show_slots , v6.no_show_slots); - assert_eq!(v5.n_delay_tranches , v6.n_delay_tranches); - assert_eq!(v5.zeroth_delay_tranche_width , v6.zeroth_delay_tranche_width); - assert_eq!(v5.needed_approvals , v6.needed_approvals); - assert_eq!(v5.relay_vrf_modulo_samples , v6.relay_vrf_modulo_samples); - assert_eq!(v5.pvf_checking_enabled , v6.pvf_checking_enabled); - assert_eq!(v5.pvf_voting_ttl , v6.pvf_voting_ttl); - assert_eq!(v5.minimum_validation_upgrade_delay , v6.minimum_validation_upgrade_delay); - assert_eq!(v5.async_backing_params.allowed_ancestry_len, v6.async_backing_params.allowed_ancestry_len); - assert_eq!(v5.async_backing_params.max_candidate_depth , v6.async_backing_params.max_candidate_depth); - assert_eq!(v5.executor_params , v6.executor_params); - }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. - } - }); - } -} diff --git a/polkadot/runtime/parachains/src/configuration/migration_ump.rs b/polkadot/runtime/parachains/src/configuration/migration_ump.rs deleted file mode 100644 index 008a93142e..0000000000 --- a/polkadot/runtime/parachains/src/configuration/migration_ump.rs +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -//! A module that is responsible for migration of UMP storage. - -#![allow(unused_imports)] // Since we use features. - -use crate::configuration::{self, ActiveConfig, Config, PendingConfigs, WeightInfo, LOG_TARGET}; -use parity_scale_codec::{Decode, Encode}; - -pub mod latest { - use super::*; - use frame_support::{ensure, pallet_prelude::Weight, traits::OnRuntimeUpgrade}; - - /// Force update the UMP limits in the parachain host config. - // NOTE: `OnRuntimeUpgrade` does not have a `self`, so everything must be compile time. - pub struct ScheduleConfigUpdate< - T, - const MAX_UPWARD_QUEUE_SIZE: u32, - const MAX_UPWARD_QUEUE_COUNT: u32, - const MAX_UPWARD_MESSAGE_SIZE: u32, - const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32, - >(core::marker::PhantomData); - - impl< - T: Config, - const MAX_UPWARD_QUEUE_SIZE: u32, - const MAX_UPWARD_QUEUE_COUNT: u32, - const MAX_UPWARD_MESSAGE_SIZE: u32, - const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32, - > OnRuntimeUpgrade - for ScheduleConfigUpdate< - T, - MAX_UPWARD_QUEUE_SIZE, - MAX_UPWARD_QUEUE_COUNT, - MAX_UPWARD_MESSAGE_SIZE, - MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE, - > - { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - log::info!(target: LOG_TARGET, "pre_upgrade"); - let mut pending = PendingConfigs::::get(); - pending.sort_by_key(|(s, _)| *s); - - log::info!( - target: LOG_TARGET, - "Active HostConfig:\n\n{:#?}\n", - ActiveConfig::::get() - ); - log::info!( - target: LOG_TARGET, - "Last pending HostConfig upgrade:\n\n{:#?}\n", - pending.last() - ); - - Ok((pending.len() as u32).encode()) - } - - fn on_runtime_upgrade() -> Weight { - if let Err(e) = configuration::Pallet::::schedule_config_update(|cfg| { - cfg.max_upward_queue_size = MAX_UPWARD_QUEUE_SIZE; - cfg.max_upward_queue_count = MAX_UPWARD_QUEUE_COUNT; - cfg.max_upward_message_size = MAX_UPWARD_MESSAGE_SIZE; - cfg.max_upward_message_num_per_candidate = MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE; - }) { - log::error!( - target: LOG_TARGET, - "\n!!!!!!!!!!!!!!!!!!!!!!!!\nFailed to schedule HostConfig upgrade: {:?}\n!!!!!!!!!!!!!!!!!!!!!!!!\n", - e, - ); - } - - T::WeightInfo::set_config_with_block_number() - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(state: sp_std::vec::Vec) -> Result<(), sp_runtime::TryRuntimeError> { - log::info!(target: LOG_TARGET, "post_upgrade"); - let old_pending: u32 = Decode::decode(&mut &state[..]).expect("Known good"); - let mut pending = PendingConfigs::::get(); - pending.sort_by_key(|(s, _)| *s); - - log::info!( - target: LOG_TARGET, - "Last pending HostConfig upgrade:\n\n{:#?}\n", - pending.last() - ); - let Some(last) = pending.last() else { - return Err("There must be a new pending upgrade enqueued".into()); - }; - ensure!( - pending.len() == old_pending as usize + 1, - "There must be exactly one new pending upgrade enqueued" - ); - if let Err(err) = last.1.check_consistency() { - log::error!(target: LOG_TARGET, "Last PendingConfig is invalidity {:?}", err,); - - return Err("Pending upgrade must be sane but was not".into()) - } - if let Err(err) = ActiveConfig::::get().check_consistency() { - log::error!(target: LOG_TARGET, "ActiveConfig is invalid: {:?}", err,); - - return Err("Active upgrade must be sane but was not".into()) - } - - Ok(()) - } - } -} diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 0623c186ad..aecb1c6923 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -1482,14 +1482,7 @@ impl Get for NominationPoolsMigrationV4OldPallet { /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. -pub type Migrations = ( - migrations::V0938, - migrations::V0940, - migrations::V0941, - migrations::V0942, - migrations::V0943, - migrations::Unreleased, -); +pub type Migrations = migrations::Unreleased; /// The runtime migrations per release. #[allow(deprecated, missing_docs)] @@ -1497,32 +1490,6 @@ pub mod migrations { use super::*; use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; - pub type V0938 = ( - pallet_xcm::migration::v1::VersionCheckedMigrateToV1, - // The UMP pallet got deleted in - // parachains_ump::migration::v1::MigrateToV1, - ); - - pub type V0940 = ( - pallet_nomination_pools::migration::v4::MigrateToV4< - Runtime, - NominationPoolsMigrationV4OldPallet, - >, - pallet_nomination_pools::migration::v5::MigrateToV5, - ); - pub type V0941 = (); // Node only release - no migrations. - pub type V0942 = ( - parachains_configuration::migration::v5::MigrateToV5, - pallet_offences::migration::v1::MigrateToV1, - runtime_common::session::migration::ClearOldSessionStorage, - ); - pub type V0943 = ( - SetStorageVersions, - // Remove UMP dispatch queue - parachains_configuration::migration::v6::MigrateToV6, - ump_migrations::UpdateUmpLimits, - ); - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_im_online::migration::v1::Migration, @@ -1552,24 +1519,6 @@ pub mod migrations { } } -/// Helpers to configure all migrations. -pub mod ump_migrations { - use runtime_parachains::configuration::migration_ump; - - pub const MAX_UPWARD_QUEUE_SIZE: u32 = 1 * 1024 * 1024; - pub const MAX_UPWARD_QUEUE_COUNT: u32 = 174762; - pub const MAX_UPWARD_MESSAGE_SIZE: u32 = (1 << 16) - 5; // Checked in test `max_upward_message_size`. - pub const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32 = 16; - - pub type UpdateUmpLimits = migration_ump::latest::ScheduleConfigUpdate< - super::Runtime, - MAX_UPWARD_QUEUE_SIZE, - MAX_UPWARD_QUEUE_COUNT, - MAX_UPWARD_MESSAGE_SIZE, - MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE, - >; -} - /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -2354,14 +2303,6 @@ mod test { If the limit is too strong, maybe consider increase the limit", ); } - - #[test] - fn max_upward_message_size() { - assert_eq!( - ump_migrations::MAX_UPWARD_MESSAGE_SIZE, - pallet_message_queue::MaxMessageLenOf::::get() - ); - } } #[cfg(test)] diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 35c6cb21c4..b4f568a260 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1514,114 +1514,12 @@ pub type UncheckedExtrinsic = /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. -pub type Migrations = ( - migrations::V0940, - migrations::V0941, - migrations::V0942, - migrations::V0943, - migrations::Unreleased, -); +pub type Migrations = migrations::Unreleased; /// The runtime migrations per release. #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; - use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; - - pub type V0940 = (); - pub type V0941 = (); // Node only release - no migrations. - pub type V0942 = ( - parachains_configuration::migration::v5::MigrateToV5, - pallet_offences::migration::v1::MigrateToV1, - ); - pub type V0943 = ( - SetStorageVersions, - // Remove UMP dispatch queue - parachains_configuration::migration::v6::MigrateToV6, - ump_migrations::UpdateUmpLimits, - ); - - /// Migrations that set `StorageVersion`s we missed to set. - /// - /// It's *possible* that these pallets have not in fact been migrated to the versions being set, - /// which we should keep in mind in the future if we notice any strange behavior. - /// We opted to not check exactly what on-chain versions each pallet is at, since it would be - /// an involved effort, this is testnet, and no one has complained - /// (https://github.com/paritytech/polkadot/issues/6657#issuecomment-1552956439). - pub struct SetStorageVersions; - - impl OnRuntimeUpgrade for SetStorageVersions { - fn on_runtime_upgrade() -> Weight { - let mut writes = 0; - let mut reads = 0; - - // Council - if Council::on_chain_storage_version() < 4 { - // Safe to assume Council was created with V4 pallet. - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // Technical Committee - if TechnicalCommittee::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // PhragmenElection - if PhragmenElection::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // TechnicalMembership - if TechnicalMembership::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // Scheduler - if Scheduler::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // Bounties - if Bounties::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // Tips - if Tips::on_chain_storage_version() < 4 { - StorageVersion::new(4).put::(); - writes += 1; - } - reads += 1; - - // NisCounterpartBalances - if NisCounterpartBalances::on_chain_storage_version() < 1 { - StorageVersion::new(1).put::(); - writes += 1; - } - reads += 1; - - // Crowdloan - if Crowdloan::on_chain_storage_version() < 2 { - StorageVersion::new(2).put::(); - writes += 1; - } - reads += 1; - - RocksDbWeight::get().reads_writes(reads, writes) - } - } /// Unreleased migrations. Add new ones here: pub type Unreleased = ( @@ -1631,24 +1529,6 @@ pub mod migrations { ); } -/// Helpers to configure all migrations. -pub mod ump_migrations { - use runtime_parachains::configuration::migration_ump; - - pub const MAX_UPWARD_QUEUE_SIZE: u32 = 8 * 1024 * 1024; - pub const MAX_UPWARD_QUEUE_COUNT: u32 = 1398101; - pub const MAX_UPWARD_MESSAGE_SIZE: u32 = (1 << 15) - 5; // Checked in test `max_upward_message_size`. - pub const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32 = 1024; - - pub type UpdateUmpLimits = migration_ump::latest::ScheduleConfigUpdate< - super::Runtime, - MAX_UPWARD_QUEUE_SIZE, - MAX_UPWARD_QUEUE_COUNT, - MAX_UPWARD_MESSAGE_SIZE, - MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE, - >; -} - /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -2340,20 +2220,6 @@ mod encoding_tests { } } -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn max_upward_message_size() { - use sp_core::Get; - assert_eq!( - ump_migrations::MAX_UPWARD_MESSAGE_SIZE, - pallet_message_queue::MaxMessageLenOf::::get() - ); - } -} - #[cfg(all(test, feature = "try-runtime"))] mod remote_tests { use super::*; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index d57dc685eb..692a17091f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1275,55 +1275,13 @@ impl Get for NominationPoolsMigrationV4OldPallet { /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. -pub type Migrations = ( - migrations::V0940, - migrations::V0941, - migrations::V0942, - migrations::V0943, - migrations::Unreleased, -); +pub type Migrations = migrations::Unreleased; /// The runtime migrations per release. #[allow(deprecated, missing_docs)] pub mod migrations { - use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}; - use super::*; - pub type V0940 = ( - clean_state_migration::CleanMigrate, - pallet_nomination_pools::migration::v4::MigrateToV4< - Runtime, - NominationPoolsMigrationV4OldPallet, - >, - pallet_nomination_pools::migration::v5::MigrateToV5, - ); - pub type V0941 = (); // Node only release - no migrations. - pub type V0942 = ( - parachains_configuration::migration::v5::MigrateToV5, - pallet_offences::migration::v1::MigrateToV1, - ); - pub type V0943 = ( - SetStorageVersions, - // Remove UMP dispatch queue - parachains_configuration::migration::v6::MigrateToV6, - ump_migrations::UpdateUmpLimits, - ); - - /// Migrations that set `StorageVersion`s we missed to set. - pub struct SetStorageVersions; - - impl OnRuntimeUpgrade for SetStorageVersions { - fn on_runtime_upgrade() -> Weight { - if FastUnstake::on_chain_storage_version() < 1 { - StorageVersion::new(1).put::(); - return RocksDbWeight::get().reads_writes(1, 1) - } - - RocksDbWeight::get().reads(1) - } - } - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_im_online::migration::v1::Migration, @@ -1331,24 +1289,6 @@ pub mod migrations { ); } -/// Helpers to configure all migrations. -pub mod ump_migrations { - use runtime_parachains::configuration::migration_ump; - - pub const MAX_UPWARD_QUEUE_SIZE: u32 = 8 * 1024 * 1024; - pub const MAX_UPWARD_QUEUE_COUNT: u32 = 1398101; - pub const MAX_UPWARD_MESSAGE_SIZE: u32 = (1 << 17) - 5; // Checked in test `max_upward_message_size`. - pub const MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE: u32 = 512; - - pub type UpdateUmpLimits = migration_ump::latest::ScheduleConfigUpdate< - super::Runtime, - MAX_UPWARD_QUEUE_SIZE, - MAX_UPWARD_QUEUE_COUNT, - MAX_UPWARD_MESSAGE_SIZE, - MAX_UPWARD_MESSAGE_NUM_PER_CANDIDATE, - >; -} - /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -2039,19 +1979,6 @@ sp_api::impl_runtime_apis! { } } -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn max_upward_message_size() { - assert_eq!( - ump_migrations::MAX_UPWARD_MESSAGE_SIZE, - pallet_message_queue::MaxMessageLenOf::::get() - ); - } -} - #[cfg(all(test, feature = "try-runtime"))] mod remote_tests { use super::*; diff --git a/polkadot/runtime/westend/src/tests.rs b/polkadot/runtime/westend/src/tests.rs index 8f835ea49a..226410b072 100644 --- a/polkadot/runtime/westend/src/tests.rs +++ b/polkadot/runtime/westend/src/tests.rs @@ -50,14 +50,6 @@ fn call_size() { ); } -#[test] -fn max_upward_message_size() { - assert_eq!( - ump_migrations::MAX_UPWARD_MESSAGE_SIZE, - pallet_message_queue::MaxMessageLenOf::::get() - ); -} - #[test] fn sanity_check_teleport_assets_weight() { // This test sanity checks that at least 50 teleports can exist in a block.