From 84ca3b2b3bf0a0f74170101200be8e35b33a8d93 Mon Sep 17 00:00:00 2001 From: ferrell-code Date: Wed, 28 Jul 2021 00:56:35 -0400 Subject: [PATCH] Parachains configuration.rs FrameV2 (#3516) * migration * genesis build correctly * migrate runtimes * add genesis builds * expose GenesisBuild * chainspec migration * fmt * check before insert * Reduce visibility of storage items to crate Co-authored-by: Keith Yeung --- polkadot/node/service/src/chain_spec.rs | 12 +- .../runtime/common/src/integration_tests.rs | 19 +- .../runtime/common/src/paras_registrar.rs | 23 +- polkadot/runtime/common/src/xcm_sender.rs | 2 +- polkadot/runtime/kusama/src/lib.rs | 2 +- .../runtime/parachains/src/configuration.rs | 246 ++++++++++-------- polkadot/runtime/parachains/src/disputes.rs | 2 +- polkadot/runtime/parachains/src/hrmp.rs | 10 +- polkadot/runtime/parachains/src/inclusion.rs | 4 +- .../runtime/parachains/src/initializer.rs | 10 +- .../parachains/src/runtime_api_impl/v1.rs | 2 +- polkadot/runtime/parachains/src/scheduler.rs | 12 +- .../runtime/parachains/src/session_info.rs | 2 +- polkadot/runtime/parachains/src/ump.rs | 2 +- polkadot/runtime/parachains/src/util.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 2 +- polkadot/runtime/westend/src/lib.rs | 2 +- 17 files changed, 194 insertions(+), 160 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index a1472e2326..40baba0fc8 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -524,7 +524,7 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Genesi sudo: westend::SudoConfig { key: endowed_accounts[0].clone(), }, - parachains_configuration: westend::ParachainsConfigurationConfig { + configuration: westend::ConfigurationConfig { config: default_parachains_host_configuration(), }, paras: Default::default(), @@ -733,7 +733,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC }, vesting: kusama::VestingConfig { vesting: vec![] }, treasury: Default::default(), - parachains_configuration: kusama::ParachainsConfigurationConfig { + configuration: kusama::ConfigurationConfig { config: default_parachains_host_configuration(), }, gilt: Default::default(), @@ -977,7 +977,7 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime:: paras: vec![], }, hrmp: Default::default(), - parachains_configuration: rococo_runtime::ParachainsConfigurationConfig { + configuration: rococo_runtime::ConfigurationConfig { config: default_parachains_host_configuration(), }, bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig { @@ -1360,7 +1360,7 @@ pub fn kusama_testnet_genesis( }, vesting: kusama::VestingConfig { vesting: vec![] }, treasury: Default::default(), - parachains_configuration: kusama::ParachainsConfigurationConfig { + configuration: kusama::ConfigurationConfig { config: default_parachains_host_configuration(), }, gilt: Default::default(), @@ -1449,7 +1449,7 @@ pub fn westend_testnet_genesis( authority_discovery: westend::AuthorityDiscoveryConfig { keys: vec![] }, vesting: westend::VestingConfig { vesting: vec![] }, sudo: westend::SudoConfig { key: root_key }, - parachains_configuration: westend::ParachainsConfigurationConfig { + configuration: westend::ConfigurationConfig { config: default_parachains_host_configuration(), }, paras: Default::default(), @@ -1517,7 +1517,7 @@ pub fn rococo_testnet_genesis( keys: vec![], }, sudo: rococo_runtime::SudoConfig { key: root_key.clone() }, - parachains_configuration: rococo_runtime::ParachainsConfigurationConfig { + configuration: rococo_runtime::ConfigurationConfig { config: default_parachains_host_configuration(), }, hrmp: Default::default(), diff --git a/polkadot/runtime/common/src/integration_tests.rs b/polkadot/runtime/common/src/integration_tests.rs index 0faf63ab1e..003e49c0ad 100644 --- a/polkadot/runtime/common/src/integration_tests.rs +++ b/polkadot/runtime/common/src/integration_tests.rs @@ -28,7 +28,7 @@ use sp_keystore::{KeystoreExt, testing::KeyStore}; use primitives::v1::{BlockNumber, Header, Id as ParaId, ValidationCode, HeadData, LOWEST_PUBLIC_ID}; use frame_support::{ parameter_types, assert_ok, assert_noop, PalletId, - traits::{Currency, OnInitialize, OnFinalize, KeyOwnerProofSystem}, + traits::{Currency, OnInitialize, OnFinalize, KeyOwnerProofSystem, GenesisBuild}, }; use frame_system::EnsureRoot; use runtime_parachains::{ @@ -234,13 +234,16 @@ impl crowdloan::Config for Test { /// Create a new set of test externalities. pub fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - configuration::GenesisConfig:: { - config: configuration::HostConfiguration { - max_code_size: 2 * 1024 * 1024, // 2 MB - max_head_data_size: 1 * 1024 * 1024, // 1 MB - ..Default::default() - }, - }.assimilate_storage(&mut t).unwrap(); + GenesisBuild::::assimilate_storage( + &configuration::GenesisConfig { + config: configuration::HostConfiguration { + max_code_size: 2 * 1024 * 1024, // 2 MB + max_head_data_size: 1 * 1024 * 1024, // 1 MB + ..Default::default() + } + }, + &mut t + ).unwrap(); let keystore = KeyStore::new(); let mut ext: sp_io::TestExternalities = t.into(); ext.register_extension(KeystoreExt(Arc::new(keystore))); diff --git a/polkadot/runtime/common/src/paras_registrar.rs b/polkadot/runtime/common/src/paras_registrar.rs index 34c952a13e..02cb2a0fe8 100644 --- a/polkadot/runtime/common/src/paras_registrar.rs +++ b/polkadot/runtime/common/src/paras_registrar.rs @@ -551,7 +551,7 @@ mod tests { use primitives::v1::{Balance, BlockNumber, Header}; use frame_system::limits; use frame_support::{ - traits::{OnInitialize, OnFinalize}, + traits::{OnInitialize, OnFinalize, GenesisBuild}, assert_ok, assert_noop, parameter_types, error::BadOrigin, }; @@ -571,7 +571,7 @@ mod tests { { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - ParachainsConfiguration: configuration::{Pallet, Call, Storage, Config}, + Configuration: configuration::{Pallet, Call, Storage, Config}, Parachains: paras::{Pallet, Origin, Call, Storage, Config, Event}, ParasShared: shared::{Pallet, Call, Storage}, Registrar: paras_registrar::{Pallet, Call, Storage, Event}, @@ -658,13 +658,16 @@ mod tests { pub fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - configuration::GenesisConfig:: { - config: configuration::HostConfiguration { - max_code_size: 2 * 1024 * 1024, // 2 MB - max_head_data_size: 1 * 1024 * 1024, // 1 MB - ..Default::default() + GenesisBuild::::assimilate_storage( + &configuration::GenesisConfig { + config: configuration::HostConfiguration { + max_code_size: 2 * 1024 * 1024, // 2 MB + max_head_data_size: 1 * 1024 * 1024, // 1 MB + ..Default::default() + } }, - }.assimilate_storage(&mut t).unwrap(); + &mut t + ).unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(1, 10_000_000), (2, 10_000_000)], @@ -716,11 +719,11 @@ mod tests { } fn max_code_size() -> u32 { - ParachainsConfiguration::config().max_code_size + Configuration::config().max_code_size } fn max_head_size() -> u32 { - ParachainsConfiguration::config().max_head_data_size + Configuration::config().max_head_data_size } #[test] diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 0f88bc39de..eb301a53ea 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -29,7 +29,7 @@ impl SendXcm for ChildParachainRouter match dest { MultiLocation::X1(Junction::Parachain(id)) => { // Downward message passing. - let config = >::config(); + let config = >::config(); >::queue_downward_message( &config, id.into(), diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 542ab8a25b..3d0ab1ebd0 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1473,7 +1473,7 @@ construct_runtime! { // Parachains pallets. Start indices at 50 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 50, - ParachainsConfiguration: parachains_configuration::{Pallet, Call, Storage, Config} = 51, + Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 51, ParasShared: parachains_shared::{Pallet, Call, Storage} = 52, ParaInclusion: parachains_inclusion::{Pallet, Call, Storage, Event} = 53, ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent} = 54, diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 206ce5ee9a..609e287bc9 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -20,17 +20,14 @@ use sp_std::prelude::*; use primitives::v1::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_POV_SIZE}; -use frame_support::{ - decl_storage, decl_module, decl_error, - ensure, - dispatch::DispatchResult, - weights::{DispatchClass, Weight}, -}; use parity_scale_codec::{Encode, Decode}; -use frame_system::ensure_root; +use frame_system::pallet_prelude::*; +use frame_support::pallet_prelude::*; use sp_runtime::traits::Zero; use crate::shared; +pub use pallet::*; + /// All configuration of the runtime with respect to parachains and parathreads. #[derive(Clone, Encode, Decode, PartialEq, sp_core::RuntimeDebug)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] @@ -258,37 +255,68 @@ impl HostConfiguration { } } -pub trait Config: frame_system::Config + shared::Config { } +#[frame_support::pallet] +pub mod pallet { + use super::*; -decl_storage! { - trait Store for Module as Configuration { - /// The active configuration for the current session. - ActiveConfig get(fn config) config(): HostConfiguration; - /// Pending configuration (if any) for the next session. - PendingConfig: map hasher(twox_64_concat) SessionIndex => Option>; - } - add_extra_genesis { - build(|config: &Self| { - config.config.check_consistency(); - }) - } -} + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); -decl_error! { - pub enum Error for Module { + #[pallet::config] + pub trait Config: frame_system::Config + shared::Config {} + + #[pallet::error] + pub enum Error { /// The new value for a configuration parameter is invalid. InvalidNewValue, } -} -decl_module! { - /// The parachains configuration module. - pub struct Module for enum Call where origin: ::Origin { - type Error = Error; + /// The active configuration for the current session. + #[pallet::storage] + #[pallet::getter(fn config)] + pub(crate) type ActiveConfig = StorageValue< + _, + HostConfiguration, + ValueQuery + >; + /// Pending configuration (if any) for the next session. + #[pallet::storage] + pub(crate) type PendingConfig = StorageMap< + _, + Twox64Concat, + SessionIndex, + HostConfiguration + >; + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub config: HostConfiguration + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { + config: Default::default() + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + self.config.check_consistency(); + ActiveConfig::::put(&self.config); + } + } + + #[pallet::call] + impl Pallet { /// Set the validation upgrade frequency. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_validation_upgrade_frequency(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_validation_upgrade_frequency(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.validation_upgrade_frequency, new) != new @@ -297,8 +325,8 @@ decl_module! { } /// Set the validation upgrade delay. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_validation_upgrade_delay(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_validation_upgrade_delay(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.validation_upgrade_delay, new) != new @@ -307,8 +335,8 @@ decl_module! { } /// Set the acceptance period for an included candidate. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_code_retention_period(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_code_retention_period(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.code_retention_period, new) != new @@ -317,8 +345,8 @@ decl_module! { } /// Set the max validation code size for incoming upgrades. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_code_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_code_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; ensure!(new <= MAX_CODE_SIZE, Error::::InvalidNewValue); Self::update_config_member(|config| { @@ -328,8 +356,8 @@ decl_module! { } /// Set the max POV block size for incoming upgrades. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_pov_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_pov_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; ensure!(new <= MAX_POV_SIZE, Error::::InvalidNewValue); Self::update_config_member(|config| { @@ -339,8 +367,8 @@ decl_module! { } /// Set the max head data size for paras. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_head_data_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_head_data_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_head_data_size, new) != new @@ -349,8 +377,8 @@ decl_module! { } /// Set the number of parathread execution cores. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_parathread_cores(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_parathread_cores(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.parathread_cores, new) != new @@ -359,8 +387,8 @@ decl_module! { } /// Set the number of retries for a particular parathread. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_parathread_retries(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_parathread_retries(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.parathread_retries, new) != new @@ -370,8 +398,8 @@ decl_module! { /// Set the parachain validator-group rotation frequency - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_group_rotation_frequency(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_group_rotation_frequency(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; ensure!(!new.is_zero(), Error::::InvalidNewValue); @@ -383,8 +411,8 @@ decl_module! { } /// Set the availability period for parachains. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_chain_availability_period(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_chain_availability_period(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; ensure!(!new.is_zero(), Error::::InvalidNewValue); @@ -396,8 +424,8 @@ decl_module! { } /// Set the availability period for parathreads. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_thread_availability_period(origin, new: T::BlockNumber) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_thread_availability_period(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; ensure!(!new.is_zero(), Error::::InvalidNewValue); @@ -409,8 +437,8 @@ decl_module! { } /// Set the scheduling lookahead, in expected number of blocks at peak throughput. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_scheduling_lookahead(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_scheduling_lookahead(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.scheduling_lookahead, new) != new @@ -419,8 +447,8 @@ decl_module! { } /// Set the maximum number of validators to assign to any core. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_validators_per_core(origin, new: Option) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_validators_per_core(origin: OriginFor, new: Option) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_validators_per_core, new) != new @@ -429,8 +457,8 @@ decl_module! { } /// Set the maximum number of validators to use in parachain consensus. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_validators(origin, new: Option) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_validators(origin: OriginFor, new: Option) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_validators, new) != new @@ -439,8 +467,8 @@ decl_module! { } /// Set the dispute period, in number of sessions to keep for disputes. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_dispute_period(origin, new: SessionIndex) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_dispute_period(origin: OriginFor, new: SessionIndex) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.dispute_period, new) != new @@ -449,9 +477,9 @@ decl_module! { } /// Set the dispute post conclusion acceptance period. - #[weight = (1_000, DispatchClass::Operational)] + #[pallet::weight((1_000, DispatchClass::Operational))] pub fn set_dispute_post_conclusion_acceptance_period( - origin, + origin: OriginFor, new: T::BlockNumber, ) -> DispatchResult { ensure_root(origin)?; @@ -462,8 +490,8 @@ decl_module! { } /// Set the maximum number of dispute spam slots. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_dispute_max_spam_slots(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_dispute_max_spam_slots(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.dispute_max_spam_slots, new) != new @@ -472,8 +500,8 @@ decl_module! { } /// Set the dispute conclusion by time out period. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_dispute_conclusion_by_time_out_period(origin, new: T::BlockNumber) + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_dispute_conclusion_by_time_out_period(origin: OriginFor, new: T::BlockNumber) -> DispatchResult { ensure_root(origin)?; @@ -485,8 +513,8 @@ decl_module! { /// Set the no show slots, in number of number of consensus slots. /// Must be at least 1. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_no_show_slots(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_no_show_slots(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; ensure!(!new.is_zero(), Error::::InvalidNewValue); @@ -498,8 +526,8 @@ decl_module! { } /// Set the total number of delay tranches. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_n_delay_tranches(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_n_delay_tranches(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.n_delay_tranches, new) != new @@ -508,8 +536,8 @@ decl_module! { } /// Set the zeroth delay tranche width. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_zeroth_delay_tranche_width(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_zeroth_delay_tranche_width(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.zeroth_delay_tranche_width, new) != new @@ -518,8 +546,8 @@ decl_module! { } /// Set the number of validators needed to approve a block. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_needed_approvals(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_needed_approvals(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.needed_approvals, new) != new @@ -528,8 +556,8 @@ decl_module! { } /// Set the number of samples to do of the `RelayVRFModulo` approval assignment criterion. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_relay_vrf_modulo_samples(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_relay_vrf_modulo_samples(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.relay_vrf_modulo_samples, new) != new @@ -538,8 +566,8 @@ decl_module! { } /// Sets the maximum items that can present in a upward dispatch queue at once. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_upward_queue_count(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_upward_queue_count(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_upward_queue_count, new) != new @@ -548,8 +576,8 @@ decl_module! { } /// Sets the maximum total size of items that can present in a upward dispatch queue at once. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_upward_queue_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_upward_queue_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_upward_queue_size, new) != new @@ -558,8 +586,8 @@ decl_module! { } /// Set the critical downward message size. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_downward_message_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_downward_message_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_downward_message_size, new) != new @@ -568,8 +596,8 @@ decl_module! { } /// Sets the soft limit for the phase of dispatching dispatchable upward messages. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_ump_service_total_weight(origin, new: Weight) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_ump_service_total_weight(origin: OriginFor, new: Weight) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.ump_service_total_weight, new) != new @@ -578,8 +606,8 @@ decl_module! { } /// Sets the maximum size of an upward message that can be sent by a candidate. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_upward_message_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_upward_message_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_upward_message_size, new) != new @@ -588,8 +616,8 @@ decl_module! { } /// Sets the maximum number of messages that a candidate can contain. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_max_upward_message_num_per_candidate(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_max_upward_message_num_per_candidate(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_upward_message_num_per_candidate, new) != new @@ -598,8 +626,8 @@ decl_module! { } /// Sets the number of sessions after which an HRMP open channel request expires. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_open_request_ttl(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_open_request_ttl(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_open_request_ttl, new) != new @@ -608,8 +636,8 @@ decl_module! { } /// Sets the amount of funds that the sender should provide for opening an HRMP channel. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_sender_deposit(origin, new: Balance) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_sender_deposit(origin: OriginFor, new: Balance) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_sender_deposit, new) != new @@ -619,8 +647,8 @@ decl_module! { /// Sets the amount of funds that the recipient should provide for accepting opening an HRMP /// channel. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_recipient_deposit(origin, new: Balance) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_recipient_deposit(origin: OriginFor, new: Balance) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_recipient_deposit, new) != new @@ -629,8 +657,8 @@ decl_module! { } /// Sets the maximum number of messages allowed in an HRMP channel at once. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_channel_max_capacity(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_channel_max_capacity(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_channel_max_capacity, new) != new @@ -639,8 +667,8 @@ decl_module! { } /// Sets the maximum total size of messages in bytes allowed in an HRMP channel at once. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_channel_max_total_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_channel_max_total_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_channel_max_total_size, new) != new @@ -649,8 +677,8 @@ decl_module! { } /// Sets the maximum number of inbound HRMP channels a parachain is allowed to accept. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_max_parachain_inbound_channels(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_max_parachain_inbound_channels(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parachain_inbound_channels, new) != new @@ -659,8 +687,8 @@ decl_module! { } /// Sets the maximum number of inbound HRMP channels a parathread is allowed to accept. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_max_parathread_inbound_channels(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_max_parathread_inbound_channels(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parathread_inbound_channels, new) != new @@ -669,8 +697,8 @@ decl_module! { } /// Sets the maximum size of a message that could ever be put into an HRMP channel. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_channel_max_message_size(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_channel_max_message_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_channel_max_message_size, new) != new @@ -679,8 +707,8 @@ decl_module! { } /// Sets the maximum number of outbound HRMP channels a parachain is allowed to open. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_max_parachain_outbound_channels(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_max_parachain_outbound_channels(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parachain_outbound_channels, new) != new @@ -689,8 +717,8 @@ decl_module! { } /// Sets the maximum number of outbound HRMP channels a parathread is allowed to open. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_max_parathread_outbound_channels(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_max_parathread_outbound_channels(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parathread_outbound_channels, new) != new @@ -699,8 +727,8 @@ decl_module! { } /// Sets the maximum number of outbound HRMP messages can be sent by a candidate. - #[weight = (1_000, DispatchClass::Operational)] - pub fn set_hrmp_max_message_num_per_candidate(origin, new: u32) -> DispatchResult { + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_hrmp_max_message_num_per_candidate(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_message_num_per_candidate, new) != new @@ -710,7 +738,7 @@ decl_module! { } } -impl Module { +impl Pallet { /// Called by the initializer to initialize the configuration module. pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight { 0 diff --git a/polkadot/runtime/parachains/src/disputes.rs b/polkadot/runtime/parachains/src/disputes.rs index fbc6e58c9c..ea813d6733 100644 --- a/polkadot/runtime/parachains/src/disputes.rs +++ b/polkadot/runtime/parachains/src/disputes.rs @@ -558,7 +558,7 @@ impl StatementSetFilter { impl Pallet { /// Called by the initializer to initialize the disputes module. pub(crate) fn initializer_initialize(now: T::BlockNumber) -> Weight { - let config = >::config(); + let config = >::config(); let mut weight = 0; for (session_index, candidate_hash, mut dispute) in >::iter() { diff --git a/polkadot/runtime/parachains/src/hrmp.rs b/polkadot/runtime/parachains/src/hrmp.rs index 5dba28396d..6a684b7e9a 100644 --- a/polkadot/runtime/parachains/src/hrmp.rs +++ b/polkadot/runtime/parachains/src/hrmp.rs @@ -522,7 +522,7 @@ pub mod pallet { #[pallet::weight(0)] pub fn force_process_hrmp_open(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; - let host_config = configuration::Module::::config(); + let host_config = configuration::Pallet::::config(); Self::process_hrmp_open_channel_requests(&host_config); Ok(()) } @@ -542,7 +542,7 @@ pub mod pallet { #[cfg(feature = "std")] fn initialize_storage(preopen_hrmp_channels: &[(ParaId, ParaId, u32, u32)]) { - let host_config = configuration::Module::::config(); + let host_config = configuration::Pallet::::config(); for &(sender, recipient, max_capacity, max_message_size) in preopen_hrmp_channels { if let Err(err) = preopen_hrmp_channel::(sender, recipient, max_capacity, max_message_size) { panic!("failed to initialize the genesis storage: {:?}", err); @@ -1051,7 +1051,7 @@ impl Pallet { Error::::OpenHrmpChannelInvalidRecipient, ); - let config = >::config(); + let config = >::config(); ensure!( proposed_max_capacity > 0, Error::::OpenHrmpChannelZeroCapacity, @@ -1154,7 +1154,7 @@ impl Pallet { // check if by accepting this open channel request, this parachain would exceed the // number of inbound channels. - let config = >::config(); + let config = >::config(); let channel_num_limit = if >::is_parathread(origin) { config.hrmp_max_parathread_inbound_channels } else { @@ -1221,7 +1221,7 @@ impl Pallet { ::HrmpCloseChannelRequests::insert(&channel_id, ()); ::HrmpCloseChannelRequestsList::append(channel_id.clone()); - let config = >::config(); + let config = >::config(); let notification_bytes = { use parity_scale_codec::Encode as _; use xcm::opaque::{v0::Xcm, VersionedXcm}; diff --git a/polkadot/runtime/parachains/src/inclusion.rs b/polkadot/runtime/parachains/src/inclusion.rs index 222941e75b..279ef7a167 100644 --- a/polkadot/runtime/parachains/src/inclusion.rs +++ b/polkadot/runtime/parachains/src/inclusion.rs @@ -674,7 +674,7 @@ impl Pallet { ) -> Weight { let plain = receipt.to_plain(); let commitments = receipt.commitments; - let config = >::config(); + let config = >::config(); T::RewardValidators::reward_backing(backers.iter().enumerate() .filter(|(_, backed)| **backed) @@ -876,7 +876,7 @@ struct CandidateCheckContext { impl CandidateCheckContext { fn new(now: T::BlockNumber, relay_parent_number: T::BlockNumber) -> Self { Self { - config: >::config(), + config: >::config(), now, relay_parent_number, } diff --git a/polkadot/runtime/parachains/src/initializer.rs b/polkadot/runtime/parachains/src/initializer.rs index 4a6fea384b..312df0d555 100644 --- a/polkadot/runtime/parachains/src/initializer.rs +++ b/polkadot/runtime/parachains/src/initializer.rs @@ -132,7 +132,7 @@ pub mod pallet { // - DMP // - UMP // - HRMP - let total_weight = configuration::Module::::initializer_initialize(now) + + let total_weight = configuration::Pallet::::initializer_initialize(now) + shared::Pallet::::initializer_initialize(now) + paras::Pallet::::initializer_initialize(now) + scheduler::Module::::initializer_initialize(now) + @@ -159,7 +159,7 @@ pub mod pallet { scheduler::Module::::initializer_finalize(); paras::Pallet::::initializer_finalize(); shared::Pallet::::initializer_finalize(); - configuration::Module::::initializer_finalize(); + configuration::Pallet::::initializer_finalize(); // Apply buffered session changes as the last thing. This way the runtime APIs and the // next block will observe the next session. @@ -199,7 +199,7 @@ impl Pallet { all_validators: Vec, queued: Vec, ) { - let prev_config = >::config(); + let prev_config = >::config(); let random_seed = { let mut buf = [0u8; 32]; @@ -213,9 +213,9 @@ impl Pallet { // We can't pass the new config into the thing that determines the new config, // so we don't pass the `SessionChangeNotification` into this module. - configuration::Module::::initializer_on_new_session(&session_index); + configuration::Pallet::::initializer_on_new_session(&session_index); - let new_config = >::config(); + let new_config = >::config(); let validators = shared::Pallet::::initializer_on_new_session( session_index, diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs b/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs index dd1bc1416d..7c61cbd7a7 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/v1.rs @@ -52,7 +52,7 @@ pub fn validator_groups() -> ( pub fn availability_cores() -> Vec> { let cores = >::availability_cores(); let parachains = >::parachains(); - let config = >::config(); + let config = >::config(); let now = >::block_number() + One::one(); >::clear(); diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index 067d442955..97a8cc7098 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -335,7 +335,7 @@ impl Module { pub fn add_parathread_claim(claim: ParathreadClaim) { if !>::is_parathread(claim.0) { return } - let config = >::config(); + let config = >::config(); let queue_max_size = config.parathread_cores * config.scheduling_lookahead; ParathreadQueue::mutate(|queue| { @@ -368,7 +368,7 @@ impl Module { now: T::BlockNumber, ) { let mut cores = AvailabilityCores::get(); - let config = >::config(); + let config = >::config(); for (freed_index, freed_reason) in just_freed_cores { if (freed_index.0 as usize) < cores.len() { @@ -552,7 +552,7 @@ impl Module { /// Get the group assigned to a specific core by index at the current block number. Result undefined if the core index is unknown /// or the block number is less than the session start index. pub(crate) fn group_assigned_to_core(core: CoreIndex, at: T::BlockNumber) -> Option { - let config = >::config(); + let config = >::config(); let session_start_block = >::get(); if at < session_start_block { return None } @@ -588,7 +588,7 @@ impl Module { /// which prevents us from testing the code if using `impl Trait`. pub(crate) fn availability_timeout_predicate() -> Option bool>> { let now = >::block_number(); - let config = >::config(); + let config = >::config(); let session_start = >::get(); let blocks_since_session_start = now.saturating_sub(session_start); @@ -630,7 +630,7 @@ impl Module { /// Returns a helper for determining group rotation. pub(crate) fn group_rotation_info(now: T::BlockNumber) -> GroupRotationInfo { let session_start_block = Self::session_start_block(); - let group_rotation_frequency = >::config() + let group_rotation_frequency = >::config() .group_rotation_frequency; GroupRotationInfo { @@ -708,7 +708,7 @@ impl Module { // Free all scheduled cores and return parathread claims to queue, with retries incremented. pub(crate) fn clear() { - let config = >::config(); + let config = >::config(); ParathreadQueue::mutate(|queue| { for core_assignment in Scheduled::take() { if let AssignmentKind::Parathread(collator, retries) = core_assignment.kind { diff --git a/polkadot/runtime/parachains/src/session_info.rs b/polkadot/runtime/parachains/src/session_info.rs index 8ec0b5638b..49627c1e67 100644 --- a/polkadot/runtime/parachains/src/session_info.rs +++ b/polkadot/runtime/parachains/src/session_info.rs @@ -82,7 +82,7 @@ impl Module { pub(crate) fn initializer_on_new_session( notification: &crate::initializer::SessionChangeNotification ) { - let config = >::config(); + let config = >::config(); let dispute_period = config.dispute_period; diff --git a/polkadot/runtime/parachains/src/ump.rs b/polkadot/runtime/parachains/src/ump.rs index 24d9976b5f..c0a8af36f8 100644 --- a/polkadot/runtime/parachains/src/ump.rs +++ b/polkadot/runtime/parachains/src/ump.rs @@ -388,7 +388,7 @@ impl Pallet { pub(crate) fn process_pending_upward_messages() -> Weight { let mut weight_used = 0; - let config = >::config(); + let config = >::config(); let mut cursor = NeedsDispatchCursor::new::(); let mut queue_cache = QueueCache::new(); diff --git a/polkadot/runtime/parachains/src/util.rs b/polkadot/runtime/parachains/src/util.rs index 45b5781668..1f867235d7 100644 --- a/polkadot/runtime/parachains/src/util.rs +++ b/polkadot/runtime/parachains/src/util.rs @@ -31,7 +31,7 @@ pub fn make_persisted_validation_data( relay_parent_number: T::BlockNumber, relay_parent_storage_root: T::Hash, ) -> Option> { - let config = >::config(); + let config = >::config(); Some(PersistedValidationData { parent_head: >::para_head(¶_id)?, diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 16cabf4d73..790248daf6 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -222,7 +222,7 @@ construct_runtime! { // Parachains modules. ParachainsOrigin: parachains_origin::{Pallet, Origin}, - ParachainsConfiguration: parachains_configuration::{Pallet, Call, Storage, Config}, + Configuration: parachains_configuration::{Pallet, Call, Storage, Config}, ParasShared: parachains_shared::{Pallet, Call, Storage}, ParaInclusion: parachains_inclusion::{Pallet, Call, Storage, Event}, ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent}, diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 30ac44a893..cdc849a104 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1063,7 +1063,7 @@ construct_runtime! { // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, - ParachainsConfiguration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, + Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, ParasShared: parachains_shared::{Pallet, Call, Storage} = 43, ParaInclusion: parachains_inclusion::{Pallet, Call, Storage, Event} = 44, ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent} = 45,