mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
Use Message Queue pallet for UMP dispatch (#6271)
* Add ProcessXcmMessage struct * Migrate away from weights in host config * New well-known key to report UMPQ capacity * Add missing file * Fixes * Remove original UMP files * Docs * Update runtime/parachains/src/inclusion/mod.rs Co-authored-by: asynchronous rob <rphmeier@gmail.com> * Add benchmarking * Benchmarks * Mock example of using the QueueChangeHandler to update the WKK * Use master Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Merge remote-tracking branch 'origin/master' into gav-message-queue * Update Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update remove-weight migration The migration got touched on master; just resolving conflicts here. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add message- to dispatch-origin conversion for XCM processing Just using the `impl Into<MultiLocation>` was a bit inflexible. Like this, the Relaychain can convert `UMP(para)` to a MultiLocation `para`. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * DNM: Temporarily comment code since XCMv3 is not merged yet Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use u64 for queue-wide limits on UmpAcceptanceCheckErr Using u32 here was one audit finding for the queue pallet. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Define one sub-queue per *MP queue Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Harden check_upward_messages Using safe math and casts. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add type-safe well_known_keys Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add message-queue weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Deploy MessageQueue to Polkadot Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update Cargo.toml Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Migrate to parachain config V5 Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update UMP tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert messed up merge 🤦 Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update remove-weight migration The migration got touched on master; just resolving conflicts here. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add message- to dispatch-origin conversion for XCM processing Just using the `impl Into<MultiLocation>` was a bit inflexible. Like this, the Relaychain can convert `UMP(para)` to a MultiLocation `para`. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * DNM: Temporarily comment code since XCMv3 is not merged yet Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use u64 for queue-wide limits on UmpAcceptanceCheckErr Using u32 here was one audit finding for the queue pallet. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Define one sub-queue per *MP queue Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Harden check_upward_messages Using safe math and casts. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add type-safe well_known_keys Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add message-queue weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Deploy MessageQueue to Polkadot Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update Cargo.toml Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Migrate to parachain config V5 Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update UMP tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Make stuff compile Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Move DMP and HRMP messages to the MessageQueue It currently does not compile in the CIbecause of some local tweaks to Substrate. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Diener for CI Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * diener update cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert wrong changes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "DNM: Temporarily comment code since XCMv3 is not merged yet" This reverts commit 820aa235cb21dd1d2621843607f7682bf035434e. * Make compile Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup runtimes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Define benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use master Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Lockfile Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add AggregateMessageOrigin This enum currently only holds one value, but having it will make it easier in the future to extend. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Forbid UMP for off-boarding paras - Reject candidates with UMP messages for off-boarding paras - Forbid scheduling off-boarding when a para has unprocess UMPs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Delete stupid test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use BoundedVec for upward messages Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add weights and fix MessageProcessor Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Bound receive_upward_messages and check bound in configuration pallet Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Bound Debug impl Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test runtime Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix xcm-simulator Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Properly fix xcm-simulator and fuzzer Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * cargo update -p sp-io Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Adapt to upstream Substrate changes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix ProcesseMessage impls Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Some tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use master Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * cargo update -p sp-io Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new MQ API Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add UMP while Para offboarding tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use Mocked message processor for benchmarking Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use variables for constants Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add MQ pallet weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use MQ pallet weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Configure QueueChangeHandler Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add config test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix MQ serive weight Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup outgoing UMP dispatch queues Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use Master Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update Cargo.lock Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Weight mul is not const Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove merge marker Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update runtime/parachains/src/inclusion/mod.rs Co-authored-by: Gavin Wood <gavin@parity.io> * Update runtime/kusama/src/lib.rs Co-authored-by: Gavin Wood <gavin@parity.io> * Use lowercase UMP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clarify comment Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use Weight::from_parts Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix doc Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Emit event after the fact Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add defensive_proof to receive_upward_messages Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Reapply "Remove original UMP files" Looks like they came back from the dead. Re-apply commit cf6d316f0 Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove old files Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Rename MaxUmpMessageLen -> MaxUmpMessageLenOf Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test defensive message dropping of receive_upward_messages Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup imports Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update implementors guide Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove FAIL-CI mark Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Delete unused code Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add another test for MQ change hook Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Imports Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Keep Kusama runtime formatting Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Delete unused code" This reverts commit dd76bca5025b7e1ef846a9539c3607eed185f16a. * Feature gate mock functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review: Use saturating_add Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test RelayDispatchQueueSize storage key Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Move migration to own file to avoid merge conflicts Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Migration in own file Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Rococo: configure MQ pallet Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Rococo: configure MQ pallet" Going to do this as follow up, since it needs Substrate changes and i dont want to stall this MR any longer. This reverts commit b9c15e8a8339c4e877d654ee3f09903af4210736. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Fixup tests" This reverts commit 88f1cbe20774d20e5e1e554e798960ae39437af1. * Fixup migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix CI Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix other migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Bump MAX_CODE_SIZE to 10MiB Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add ForceUpdateUmpLimits migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * imports Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use defensive instead of defensive_proof 'defensive_proof' also prints the 'self', which spams the console too much when running the tests. Just the length is enough. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Rename to ScheduleConfigUpdate Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup migration checks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add MAX_CODE_SIZE to ScheduleConfigUpdate Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Set MAX_CODE_SIZE to 4MiB Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix benchmark Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix formatting Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Add MAX_CODE_SIZE to ScheduleConfigUpdate" This reverts commit 7caffb09e83083b57affd548215e45b25c3d64dc. * Revert "Set MAX_CODE_SIZE to 4MiB" This reverts commit 103ffbaf686487d2fbe0082a16826af17cacc1a1. * Revert "Bump MAX_CODE_SIZE to 10MiB" This reverts commit 530734b7b0da5b7680054e0242348fcc79a666fe. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove consistency check from migration Re-addig these checks is blocked on https://github.com/paritytech/polkadot/issues/7108 Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix constants Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Bump MAX_UPWARD_MESSAGE_SIZE_BOUND for Westend Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix migrations Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use old nightly for fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixes * cargo fmt * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixes * Add MQ pallet to fuzzer Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix XMC simulator example Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove runtime-benchmarks from fuzzers Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Remove runtime-benchmarks from fuzzers" This reverts commit e1f2bb01b6dea2dd465539d3658719895b58b557. * Fix example simulator Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add V6 migration and remove old ones Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Actually make old migrations reusable Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Dont delete old migrations Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Future proof AggregateMessageOrigin and review fixes There are indications that Loopback and Bridged will be needed soon. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix fuzzer build Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review Co-authored-by: muharem <ismailov.m.h@gmail.com> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove old migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Set MQ service weight to 20% Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tabs in Markdown Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: asynchronous rob <rphmeier@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -27,8 +27,6 @@ benchmarks! {
|
||||
|
||||
set_config_with_option_u32 {}: set_max_validators(RawOrigin::Root, Some(10))
|
||||
|
||||
set_config_with_weight {}: set_ump_service_total_weight(RawOrigin::Root, Weight::from_parts(3_000_000, 0))
|
||||
|
||||
set_hrmp_open_request_ttl {}: {
|
||||
Err(BenchmarkError::Override(
|
||||
BenchmarkResult::from_weight(T::BlockWeights::get().max_block)
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
//! A module that is responsible for migration of storage.
|
||||
|
||||
use crate::configuration::{self, ActiveConfig, Config, Pallet, PendingConfigs, MAX_POV_SIZE};
|
||||
use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::vstaging::AsyncBackingParams;
|
||||
use sp_std::vec::Vec;
|
||||
use frame_support::traits::StorageVersion;
|
||||
use primitives::ExecutorParams;
|
||||
|
||||
/// The current storage version.
|
||||
///
|
||||
@@ -29,376 +26,10 @@ use sp_std::vec::Vec;
|
||||
/// v2-v3: <https://github.com/paritytech/polkadot/pull/6091>
|
||||
/// v3-v4: <https://github.com/paritytech/polkadot/pull/6345>
|
||||
/// v4-v5: <https://github.com/paritytech/polkadot/pull/6937>
|
||||
/// + <https://github.com/paritytech/polkadot/pull/6961>
|
||||
/// + <https://github.com/paritytech/polkadot/pull/6934>
|
||||
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);
|
||||
/// + <https://github.com/paritytech/polkadot/pull/6961>
|
||||
/// + <https://github.com/paritytech/polkadot/pull/6934>
|
||||
/// v5-v6: <https://github.com/paritytech/polkadot/pull/6271> (remove UMP dispatch queue)
|
||||
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(6);
|
||||
|
||||
pub mod v5 {
|
||||
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 OldHostConfiguration<BlockNumber> {
|
||||
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<u32>,
|
||||
pub max_validators: Option<u32>,
|
||||
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,
|
||||
}
|
||||
|
||||
impl<BlockNumber: Default + From<u32>> Default for OldHostConfiguration<BlockNumber> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MigrateToV5<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
|
||||
|
||||
ensure!(StorageVersion::get::<Pallet<T>>() == 4, "The migration requires version 4");
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
if StorageVersion::get::<Pallet<T>>() == 4 {
|
||||
let weight_consumed = migrate_to_v5::<T>();
|
||||
|
||||
log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully");
|
||||
STORAGE_VERSION.put::<Pallet<T>>();
|
||||
|
||||
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<u8>) -> Result<(), &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
|
||||
ensure!(
|
||||
StorageVersion::get::<Pallet<T>>() == STORAGE_VERSION,
|
||||
"Storage version should be 5 after the migration"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_to_v5<T: Config>() -> 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: v5::OldHostConfiguration<BlockNumberFor<T>>| ->
|
||||
configuration::HostConfiguration<BlockNumberFor<T>>
|
||||
{
|
||||
super::HostConfiguration {
|
||||
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(),
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(_) = ActiveConfig::<T>::translate(|pre| pre.map(translate)) {
|
||||
// `Err` is returned when the pre-migration type cannot be deserialized. This
|
||||
// cannot happen if the migration runs correctly, i.e. against the expected version.
|
||||
//
|
||||
// This happening almost surely will lead to a panic somewhere else. Corruption seems
|
||||
// to be unlikely to be caused by this. So we just log. Maybe it'll work out still?
|
||||
log::error!(
|
||||
target: configuration::LOG_TARGET,
|
||||
"unexpected error when performing translation of the active configuration during storage upgrade to v5."
|
||||
);
|
||||
}
|
||||
|
||||
if let Err(_) = PendingConfigs::<T>::translate(|pre| {
|
||||
pre.map(
|
||||
|v: Vec<(primitives::SessionIndex, v5::OldHostConfiguration<BlockNumberFor<T>>)>| {
|
||||
v.into_iter()
|
||||
.map(|(session, config)| (session, translate(config)))
|
||||
.collect::<Vec<_>>()
|
||||
},
|
||||
)
|
||||
}) {
|
||||
log::error!(
|
||||
target: configuration::LOG_TARGET,
|
||||
"unexpected error when performing translation of the pending configuration during storage upgrade to v5."
|
||||
);
|
||||
}
|
||||
|
||||
let num_configs = (PendingConfigs::<T>::get().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 = v5::OldHostConfiguration::<primitives::BlockNumber>::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 = v5::OldHostConfiguration::<primitives::BlockNumber> {
|
||||
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.
|
||||
frame_support::storage::unhashed::put_raw(
|
||||
&configuration::ActiveConfig::<Test>::hashed_key(),
|
||||
&v4.encode(),
|
||||
);
|
||||
frame_support::storage::unhashed::put_raw(
|
||||
&configuration::PendingConfigs::<Test>::hashed_key(),
|
||||
&pending_configs.encode(),
|
||||
);
|
||||
|
||||
migrate_to_v5::<Test>();
|
||||
|
||||
let v5 = configuration::ActiveConfig::<Test>::get();
|
||||
let mut configs_to_check = configuration::PendingConfigs::<Test>::get();
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
pub mod v5;
|
||||
pub mod v6;
|
||||
|
||||
@@ -0,0 +1,504 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! 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<BlockNumber> {
|
||||
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<u32>,
|
||||
pub max_validators: Option<u32>,
|
||||
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<BlockNumber> {
|
||||
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<u32>,
|
||||
pub max_validators: Option<u32>,
|
||||
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,
|
||||
}
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V4ActiveConfig<T: Config> =
|
||||
StorageValue<Pallet<T>, V4HostConfiguration<BlockNumberFor<T>>, OptionQuery>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V4PendingConfigs<T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Vec<(SessionIndex, V4HostConfiguration<BlockNumberFor<T>>)>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V5ActiveConfig<T: Config> =
|
||||
StorageValue<Pallet<T>, V5HostConfiguration<BlockNumberFor<T>>, OptionQuery>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V5PendingConfigs<T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Vec<(SessionIndex, V5HostConfiguration<BlockNumberFor<T>>)>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
impl<BlockNumber: Default + From<u32>> Default for V4HostConfiguration<BlockNumber> {
|
||||
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<BlockNumber: Default + From<u32>> Default for V5HostConfiguration<BlockNumber> {
|
||||
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<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
|
||||
|
||||
ensure!(StorageVersion::get::<Pallet<T>>() == 4, "The migration requires version 4");
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
if StorageVersion::get::<Pallet<T>>() == 4 {
|
||||
let weight_consumed = migrate_to_v5::<T>();
|
||||
|
||||
log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully");
|
||||
StorageVersion::new(5).put::<Pallet<T>>();
|
||||
|
||||
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<u8>) -> Result<(), &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
|
||||
ensure!(
|
||||
StorageVersion::get::<Pallet<T>>() == 5,
|
||||
"Storage version should be 5 after the migration"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_to_v5<T: Config>() -> 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<BlockNumberFor<T>>| ->
|
||||
V5HostConfiguration<BlockNumberFor<T>>
|
||||
{
|
||||
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 = V4ActiveConfig::<T>::get()
|
||||
.defensive_proof("Could not decode old config")
|
||||
.unwrap_or_default();
|
||||
let v5 = translate(v4);
|
||||
V5ActiveConfig::<T>::set(Some(v5));
|
||||
|
||||
let pending_v4 = V4PendingConfigs::<T>::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));
|
||||
}
|
||||
V5PendingConfigs::<T>::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 = v5::V4HostConfiguration::<primitives::BlockNumber>::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 = v5::V4HostConfiguration::<primitives::BlockNumber> {
|
||||
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.
|
||||
V4ActiveConfig::<Test>::set(Some(v4));
|
||||
V4PendingConfigs::<Test>::set(Some(pending_configs));
|
||||
|
||||
migrate_to_v5::<Test>();
|
||||
|
||||
let v5 = V5ActiveConfig::<Test>::get().unwrap();
|
||||
let mut configs_to_check = V5PendingConfigs::<Test>::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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A module that is responsible for migration of storage.
|
||||
|
||||
use crate::configuration::{self, Config, Pallet};
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{Defensive, StorageVersion},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use primitives::SessionIndex;
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use super::v5::V5HostConfiguration;
|
||||
// Change this once there is V7.
|
||||
type V6HostConfiguration<BlockNumber> = configuration::HostConfiguration<BlockNumber>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V5ActiveConfig<T: Config> =
|
||||
StorageValue<Pallet<T>, V5HostConfiguration<BlockNumberFor<T>>, OptionQuery>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V5PendingConfigs<T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Vec<(SessionIndex, V5HostConfiguration<BlockNumberFor<T>>)>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V6ActiveConfig<T: Config> =
|
||||
StorageValue<Pallet<T>, V6HostConfiguration<BlockNumberFor<T>>, OptionQuery>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type V6PendingConfigs<T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Vec<(SessionIndex, V6HostConfiguration<BlockNumberFor<T>>)>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
pub struct MigrateToV6<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
|
||||
|
||||
ensure!(StorageVersion::get::<Pallet<T>>() == 5, "The migration requires version 4");
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
if StorageVersion::get::<Pallet<T>>() == 5 {
|
||||
let weight_consumed = migrate_to_v6::<T>();
|
||||
|
||||
log::info!(target: configuration::LOG_TARGET, "MigrateToV6 executed successfully");
|
||||
StorageVersion::new(6).put::<Pallet<T>>();
|
||||
|
||||
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<u8>) -> Result<(), &'static str> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
|
||||
ensure!(
|
||||
StorageVersion::get::<Pallet<T>>() == 6,
|
||||
"Storage version should be 6 after the migration"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_to_v6<T: Config>() -> 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<BlockNumberFor<T>>| ->
|
||||
V6HostConfiguration<BlockNumberFor<T>>
|
||||
{
|
||||
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 = V5ActiveConfig::<T>::get()
|
||||
.defensive_proof("Could not decode old config")
|
||||
.unwrap_or_default();
|
||||
let v6 = translate(v5);
|
||||
V6ActiveConfig::<T>::set(Some(v6));
|
||||
|
||||
let pending_v4 = V5PendingConfigs::<T>::get()
|
||||
.defensive_proof("Could not decode old pending")
|
||||
.unwrap_or_default();
|
||||
let mut pending_v5 = Vec::new();
|
||||
|
||||
for (session, v5) in pending_v4.into_iter() {
|
||||
let v6 = translate(v5);
|
||||
pending_v5.push((session, v6));
|
||||
}
|
||||
V6PendingConfigs::<T>::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};
|
||||
|
||||
#[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::<primitives::BlockNumber>::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.
|
||||
}
|
||||
|
||||
#[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::<primitives::BlockNumber> {
|
||||
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.
|
||||
V5ActiveConfig::<Test>::set(Some(v5));
|
||||
V5PendingConfigs::<Test>::set(Some(pending_configs));
|
||||
|
||||
migrate_to_v6::<Test>();
|
||||
|
||||
let v6 = V6ActiveConfig::<Test>::get().unwrap();
|
||||
let mut configs_to_check = V6PendingConfigs::<Test>::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.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! 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::{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<T>);
|
||||
|
||||
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_std::vec::Vec<u8>, &'static str> {
|
||||
log::info!(target: LOG_TARGET, "pre_upgrade");
|
||||
let mut pending = PendingConfigs::<T>::get();
|
||||
pending.sort_by_key(|(s, _)| *s);
|
||||
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"Active HostConfig:\n\n{:#?}\n",
|
||||
ActiveConfig::<T>::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::<T>::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<u8>) -> Result<(), &'static str> {
|
||||
log::info!(target: LOG_TARGET, "post_upgrade");
|
||||
let old_pending: u32 = Decode::decode(&mut &state[..]).expect("Known good");
|
||||
let mut pending = PendingConfigs::<T>::get();
|
||||
pending.sort_by_key(|(s, _)| *s);
|
||||
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"Last pending HostConfig upgrade:\n\n{:#?}\n",
|
||||
pending.last()
|
||||
);
|
||||
assert_eq!(
|
||||
pending.len(),
|
||||
old_pending as usize + 1,
|
||||
"There must be a new pending upgrade enqueued"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::mock::{new_test_ext, Configuration, ParasShared, RuntimeOrigin, Test};
|
||||
use frame_support::{assert_err, assert_ok};
|
||||
use frame_support::{assert_err, assert_noop, assert_ok};
|
||||
|
||||
fn on_new_session(session_index: SessionIndex) -> (HostConfiguration<u32>, HostConfiguration<u32>) {
|
||||
ParasShared::set_session_index(session_index);
|
||||
@@ -309,7 +309,6 @@ fn setting_pending_config_members() {
|
||||
max_upward_queue_count: 1337,
|
||||
max_upward_queue_size: 228,
|
||||
max_downward_message_size: 2048,
|
||||
ump_service_total_weight: Weight::from_parts(20000, 20000),
|
||||
max_upward_message_size: 448,
|
||||
max_upward_message_num_per_candidate: 5,
|
||||
hrmp_sender_deposit: 22,
|
||||
@@ -322,7 +321,6 @@ fn setting_pending_config_members() {
|
||||
hrmp_max_parachain_outbound_channels: 10,
|
||||
hrmp_max_parathread_outbound_channels: 20,
|
||||
hrmp_max_message_num_per_candidate: 20,
|
||||
ump_max_individual_weight: Weight::from_parts(909, 909),
|
||||
pvf_checking_enabled: true,
|
||||
pvf_voting_ttl: 3,
|
||||
minimum_validation_upgrade_delay: 20,
|
||||
@@ -418,16 +416,18 @@ fn setting_pending_config_members() {
|
||||
new_config.max_upward_queue_size,
|
||||
)
|
||||
.unwrap();
|
||||
assert_noop!(
|
||||
Configuration::set_max_upward_queue_size(
|
||||
RuntimeOrigin::root(),
|
||||
MAX_UPWARD_MESSAGE_SIZE_BOUND + 1,
|
||||
),
|
||||
Error::<Test>::InvalidNewValue
|
||||
);
|
||||
Configuration::set_max_downward_message_size(
|
||||
RuntimeOrigin::root(),
|
||||
new_config.max_downward_message_size,
|
||||
)
|
||||
.unwrap();
|
||||
Configuration::set_ump_service_total_weight(
|
||||
RuntimeOrigin::root(),
|
||||
new_config.ump_service_total_weight,
|
||||
)
|
||||
.unwrap();
|
||||
Configuration::set_max_upward_message_size(
|
||||
RuntimeOrigin::root(),
|
||||
new_config.max_upward_message_size,
|
||||
@@ -488,11 +488,6 @@ fn setting_pending_config_members() {
|
||||
new_config.hrmp_max_message_num_per_candidate,
|
||||
)
|
||||
.unwrap();
|
||||
Configuration::set_ump_max_individual_weight(
|
||||
RuntimeOrigin::root(),
|
||||
new_config.ump_max_individual_weight,
|
||||
)
|
||||
.unwrap();
|
||||
Configuration::set_pvf_checking_enabled(
|
||||
RuntimeOrigin::root(),
|
||||
new_config.pvf_checking_enabled,
|
||||
|
||||
Reference in New Issue
Block a user