diff --git a/polkadot/node/network/protocol/src/request_response/mod.rs b/polkadot/node/network/protocol/src/request_response/mod.rs index 610fcc1fc5..f4ca6b336f 100644 --- a/polkadot/node/network/protocol/src/request_response/mod.rs +++ b/polkadot/node/network/protocol/src/request_response/mod.rs @@ -36,8 +36,7 @@ use std::{borrow::Cow, u64}; use std::time::Duration; use futures::channel::mpsc; -use polkadot_node_primitives::MAX_POV_SIZE; -use polkadot_primitives::v1::MAX_CODE_SIZE; +use polkadot_primitives::v1::{MAX_CODE_SIZE, MAX_POV_SIZE}; use strum::EnumIter; pub use sc_network::config as network; diff --git a/polkadot/node/primitives/src/lib.rs b/polkadot/node/primitives/src/lib.rs index 3199d15234..490367db4c 100644 --- a/polkadot/node/primitives/src/lib.rs +++ b/polkadot/node/primitives/src/lib.rs @@ -41,7 +41,7 @@ use polkadot_primitives::v1::{ CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId, OutboundHrmpMessage, PersistedValidationData, Signed, UncheckedSigned, UpwardMessage, ValidationCode, ValidatorIndex, ValidatorSignature, ValidDisputeStatementKind, InvalidDisputeStatementKind, - CandidateReceipt, ValidatorId, SessionIndex, DisputeStatement, + CandidateReceipt, ValidatorId, SessionIndex, DisputeStatement, MAX_CODE_SIZE, MAX_POV_SIZE, }; pub use polkadot_parachain::primitives::BlockData; @@ -49,13 +49,10 @@ pub use polkadot_parachain::primitives::BlockData; pub mod approval; /// The bomb limit for decompressing code blobs. -pub const VALIDATION_CODE_BOMB_LIMIT: usize = 16 * 1024 * 1024; - -/// Maximum PoV size we support right now. -pub const MAX_POV_SIZE: u32 = 20 * 1024 * 1024; +pub const VALIDATION_CODE_BOMB_LIMIT: usize = (MAX_CODE_SIZE * 4u32) as usize; /// The bomb limit for decompressing PoV blobs. -pub const POV_BOMB_LIMIT: usize = MAX_POV_SIZE as usize; +pub const POV_BOMB_LIMIT: usize = (MAX_POV_SIZE * 4u32) as usize; /// The cumulative weight of a block in a fork-choice rule. pub type BlockWeight = u32; diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index de66ad812d..676762b7e5 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -149,8 +149,7 @@ pub fn wococo_config() -> Result { fn default_parachains_host_configuration() -> polkadot_runtime_parachains::configuration::HostConfiguration { - use polkadot_node_primitives::MAX_POV_SIZE; - use polkadot_primitives::v1::MAX_CODE_SIZE; + use polkadot_primitives::v1::{MAX_CODE_SIZE, MAX_POV_SIZE}; polkadot_runtime_parachains::configuration::HostConfiguration { validation_upgrade_frequency: 1u32, diff --git a/polkadot/node/test/service/src/chain_spec.rs b/polkadot/node/test/service/src/chain_spec.rs index 1c24d2270c..c65b70f107 100644 --- a/polkadot/node/test/service/src/chain_spec.rs +++ b/polkadot/node/test/service/src/chain_spec.rs @@ -20,7 +20,7 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use babe_primitives::AuthorityId as BabeId; use grandpa::AuthorityId as GrandpaId; use pallet_staking::Forcing; -use polkadot_primitives::v1::{ValidatorId, AccountId, AssignmentId}; +use polkadot_primitives::v1::{ValidatorId, AccountId, AssignmentId, MAX_CODE_SIZE, MAX_POV_SIZE}; use polkadot_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions}; use polkadot_test_runtime::{constants::currency::DOTS, BABE_GENESIS_EPOCH_CONFIG}; use sc_chain_spec::{ChainSpec, ChainType}; @@ -179,8 +179,8 @@ fn polkadot_testnet_genesis( validation_upgrade_frequency: 10u32, validation_upgrade_delay: 5, code_retention_period: 1200, - max_code_size: 5 * 1024 * 1024, - max_pov_size: 50 * 1024 * 1024, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, max_head_data_size: 32 * 1024, group_rotation_frequency: 20, chain_availability_period: 4, diff --git a/polkadot/primitives/src/v1/mod.rs b/polkadot/primitives/src/v1/mod.rs index 0fe6ed8470..2f9fdfe5f0 100644 --- a/polkadot/primitives/src/v1/mod.rs +++ b/polkadot/primitives/src/v1/mod.rs @@ -190,8 +190,21 @@ pub const ASSIGNMENT_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"asgn"); /// Maximum compressed code size we support right now. /// At the moment we have runtime upgrade on chain, which restricts scalability severely. If we want /// to have bigger values, we should fix that first. +/// +/// Used for: +/// * initial genesis for the Parachains configuration +/// * checking updates to this stored runtime configuration do not exceed this limit +/// * when detecting a code decompression bomb in the client pub const MAX_CODE_SIZE: u32 = 3 * 1024 * 1024; +/// Maximum PoV size we support right now. +/// +/// Used for: +/// * initial genesis for the Parachains configuration +/// * checking updates to this stored runtime configuration do not exceed this limit +/// * when detecting a PoV decompression bomb in the client +pub const MAX_POV_SIZE: u32 = 5 * 1024 * 1024; + // The public key of a keypair used by a validator for determining assignments /// to approve included parachain candidates. mod assignment_app { diff --git a/polkadot/runtime/common/src/integration_tests.rs b/polkadot/runtime/common/src/integration_tests.rs index 28e404e046..bdef226a0a 100644 --- a/polkadot/runtime/common/src/integration_tests.rs +++ b/polkadot/runtime/common/src/integration_tests.rs @@ -171,8 +171,6 @@ impl paras::Config for Test { parameter_types! { pub const ParaDeposit: Balance = 500; pub const DataDepositPerByte: Balance = 1; - pub const MaxCodeSize: u32 = 200; - pub const MaxHeadSize: u32 = 100; } impl paras_registrar::Config for Test { @@ -180,8 +178,6 @@ impl paras_registrar::Config for Test { type OnSwap = (Crowdloan, Slots); type ParaDeposit = ParaDeposit; type DataDepositPerByte = DataDepositPerByte; - type MaxCodeSize = MaxCodeSize; - type MaxHeadSize = MaxHeadSize; type Currency = Balances; type Origin = Origin; type WeightInfo = crate::paras_registrar::TestWeightInfo; @@ -237,7 +233,14 @@ impl crowdloan::Config for Test { /// Create a new set of test externalities. pub fn new_test_ext() -> TestExternalities { - let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + 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(); let keystore = KeyStore::new(); let mut ext: sp_io::TestExternalities = t.into(); ext.register_extension(KeystoreExt(Arc::new(keystore))); @@ -298,8 +301,8 @@ fn basic_end_to_end_works() { let para_2 = LOWEST_PUBLIC_ID + 1; assert!(System::block_number().is_one()); // User 1 and 2 will own parachains - Balances::make_free_balance_be(&1, 1_000); - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); + Balances::make_free_balance_be(&2, 1_000_000_000); // First register 2 parathreads let genesis_head = Registrar::worst_head_data(); let validation_code = Registrar::worst_validation_code(); @@ -348,8 +351,8 @@ fn basic_end_to_end_works() { // Auction ending begins on block 100, so we make a bid before then. run_to_block(90); - Balances::make_free_balance_be(&10, 1_000); - Balances::make_free_balance_be(&20, 1_000); + Balances::make_free_balance_be(&10, 1_000_000_000); + Balances::make_free_balance_be(&20, 1_000_000_000); // User 10 will bid directly for parachain 1 assert_ok!(Auctions::bid( @@ -362,7 +365,7 @@ fn basic_end_to_end_works() { )); // User 2 will be a contribute to crowdloan for parachain 2 - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&2, 1_000_000_000); assert_ok!(Crowdloan::contribute(Origin::signed(2), ParaId::from(para_2), 920, None)); // Auction ends at block 110 @@ -390,7 +393,7 @@ fn basic_end_to_end_works() { ); // Should not be able to contribute to a winning crowdloan - Balances::make_free_balance_be(&3, 1_000); + Balances::make_free_balance_be(&3, 1_000_000_000); assert_noop!(Crowdloan::contribute(Origin::signed(3), ParaId::from(2001), 10, None), CrowdloanError::::BidOrLeaseActive); // New leases will start on block 400 @@ -444,8 +447,8 @@ fn basic_errors_fail() { assert!(System::block_number().is_one()); let para_id = LOWEST_PUBLIC_ID; // Can't double register - Balances::make_free_balance_be(&1, 1_000); - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); + Balances::make_free_balance_be(&2, 1_000_000_000); let genesis_head = Registrar::worst_head_data(); let validation_code = Registrar::worst_validation_code(); @@ -492,7 +495,7 @@ fn competing_slots() { // Create n paras and owners for n in 1 ..= max_bids { - Balances::make_free_balance_be(&n, 1_000); + Balances::make_free_balance_be(&n, 1_000_000_000); let genesis_head = Registrar::worst_head_data(); let validation_code = Registrar::worst_validation_code(); assert_ok!(Registrar::reserve(Origin::signed(n))); @@ -577,7 +580,7 @@ fn competing_bids() { let start_para = LOWEST_PUBLIC_ID - 1; // Create 3 paras and owners for n in 1 ..= 3 { - Balances::make_free_balance_be(&n, 1_000); + Balances::make_free_balance_be(&n, 1_000_000_000); let genesis_head = Registrar::worst_head_data(); let validation_code = Registrar::worst_validation_code(); assert_ok!(Registrar::reserve(Origin::signed(n))); @@ -664,8 +667,8 @@ fn basic_swap_works() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); // So events are emitted // User 1 and 2 will own paras - Balances::make_free_balance_be(&1, 1_000); - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); + Balances::make_free_balance_be(&2, 1_000_000_000); // First register 2 parathreads with different data assert_ok!(Registrar::reserve(Origin::signed(1))); assert_ok!(Registrar::register( @@ -711,7 +714,7 @@ fn basic_swap_works() { // Bunch of contributions let mut total = 0; for i in 10 .. 20 { - Balances::make_free_balance_be(&i, 1_000); + Balances::make_free_balance_be(&i, 1_000_000_000); assert_ok!(Crowdloan::contribute(Origin::signed(i), ParaId::from(2000), 900 - i, None)); total += 900 - i; } @@ -797,8 +800,8 @@ fn crowdloan_ending_period_bid() { new_test_ext().execute_with(|| { assert!(System::block_number().is_one()); // So events are emitted // User 1 and 2 will own paras - Balances::make_free_balance_be(&1, 1_000); - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); + Balances::make_free_balance_be(&2, 1_000_000_000); // First register 2 parathreads assert_ok!(Registrar::reserve(Origin::signed(1))); assert_ok!(Registrar::register( @@ -844,7 +847,7 @@ fn crowdloan_ending_period_bid() { // Bunch of contributions let mut total = 0; for i in 10 .. 20 { - Balances::make_free_balance_be(&i, 1_000); + Balances::make_free_balance_be(&i, 1_000_000_000); assert_ok!(Crowdloan::contribute(Origin::signed(i), ParaId::from(2000), 900 - i, None)); total += 900 - i; } @@ -852,7 +855,7 @@ fn crowdloan_ending_period_bid() { assert_eq!(Balances::free_balance(&crowdloan_account), total); // Bid for para 2 directly - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&2, 1_000_000_000); assert_ok!(Auctions::bid( Origin::signed(2), ParaId::from(2001), @@ -874,7 +877,7 @@ fn crowdloan_ending_period_bid() { run_to_block(101); - Balances::make_free_balance_be(&1234, 1_000); + Balances::make_free_balance_be(&1234, 1_000_000_000); assert_ok!(Crowdloan::contribute(Origin::signed(1234), ParaId::from(2000), 900, None)); // Data propagates correctly @@ -897,7 +900,7 @@ fn auction_bid_requires_registered_para() { assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start)); // Can't bid with non-registered paras - Balances::make_free_balance_be(&1, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); assert_noop!(Auctions::bid( Origin::signed(1), ParaId::from(2000), @@ -930,7 +933,7 @@ fn auction_bid_requires_registered_para() { run_to_session(2); // Success - Balances::make_free_balance_be(&1, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); assert_ok!(Auctions::bid( Origin::signed(1), ParaId::from(2000), @@ -951,8 +954,8 @@ fn gap_bids_work() { let duration = 99u32; let lease_period_index_start = 4u32; assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start)); - Balances::make_free_balance_be(&1, 1_000); - Balances::make_free_balance_be(&2, 1_000); + Balances::make_free_balance_be(&1, 1_000_000_000); + Balances::make_free_balance_be(&2, 1_000_000_000); // Now register 2 paras assert_ok!(Registrar::reserve(Origin::signed(1))); @@ -974,8 +977,8 @@ fn gap_bids_work() { run_to_session(2); // Make bids - Balances::make_free_balance_be(&10, 1_000); - Balances::make_free_balance_be(&20, 1_000); + Balances::make_free_balance_be(&10, 1_000_000_000); + Balances::make_free_balance_be(&20, 1_000_000_000); // Slot 1 for 100 from 10 assert_ok!(Auctions::bid( Origin::signed(10), diff --git a/polkadot/runtime/common/src/paras_registrar.rs b/polkadot/runtime/common/src/paras_registrar.rs index 59059c31c3..26c3ce20d2 100644 --- a/polkadot/runtime/common/src/paras_registrar.rs +++ b/polkadot/runtime/common/src/paras_registrar.rs @@ -33,6 +33,7 @@ use runtime_parachains::{ self, ParaGenesisArgs, }, + configuration, ensure_parachain, Origin, ParaLifecycle, }; @@ -84,7 +85,7 @@ pub mod pallet { #[pallet::config] #[pallet::disable_frame_system_supertrait_check] - pub trait Config: paras::Config { + pub trait Config: configuration::Config + paras::Config { /// The overarching event type. type Event: From> + IsType<::Event>; @@ -110,14 +111,6 @@ pub mod pallet { #[pallet::constant] type DataDepositPerByte: Get>; - /// The maximum size for the validation code. - #[pallet::constant] - type MaxCodeSize: Get; - - /// The maximum size for the head data. - #[pallet::constant] - type MaxHeadSize: Get; - /// Weight Information for the Extrinsics in the Pallet type WeightInfo: WeightInfo; } @@ -388,15 +381,15 @@ impl Registrar for Pallet { #[cfg(any(feature = "runtime-benchmarks", test))] fn worst_head_data() -> HeadData { - // TODO: Figure a way to allow bigger head data in benchmarks? - let max_head_size = (T::MaxHeadSize::get()).min(1 * 1024 * 1024); + let max_head_size = configuration::Pallet::::config().max_head_data_size; + assert!(max_head_size > 0, "max_head_data can't be zero for generating worst head data."); vec![0u8; max_head_size as usize].into() } #[cfg(any(feature = "runtime-benchmarks", test))] fn worst_validation_code() -> ValidationCode { - // TODO: Figure a way to allow bigger wasm in benchmarks? - let max_code_size = (T::MaxCodeSize::get()).min(4 * 1024 * 1024); + let max_code_size = configuration::Pallet::::config().max_code_size; + assert!(max_code_size > 0, "max_code_size can't be zero for generating worst code data."); let validation_code = vec![0u8; max_code_size as usize]; validation_code.into() } @@ -525,8 +518,9 @@ impl Pallet { validation_code: ValidationCode, parachain: bool, ) -> Result<(ParaGenesisArgs, BalanceOf), sp_runtime::DispatchError> { - ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::::CodeTooLarge); - ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::::HeadDataTooLarge); + let config = configuration::Pallet::::config(); + ensure!(validation_code.0.len() <= config.max_code_size as usize, Error::::CodeTooLarge); + ensure!(genesis_head.0.len() <= config.max_head_data_size as usize, Error::::HeadDataTooLarge); let per_byte_fee = T::DataDepositPerByte::get(); let deposit = T::ParaDeposit::get() @@ -577,6 +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}, Parachains: paras::{Pallet, Origin, Call, Storage, Config, Event}, Registrar: paras_registrar::{Pallet, Call, Storage, Event}, } @@ -647,8 +642,6 @@ mod tests { pub const DataDepositPerByte: Balance = 1; pub const QueueSize: usize = 2; pub const MaxRetries: u32 = 3; - pub const MaxCodeSize: u32 = 100; - pub const MaxHeadSize: u32 = 100; } impl Config for Test { @@ -658,14 +651,20 @@ mod tests { type OnSwap = (); type ParaDeposit = ParaDeposit; type DataDepositPerByte = DataDepositPerByte; - type MaxCodeSize = MaxCodeSize; - type MaxHeadSize = MaxHeadSize; type WeightInfo = TestWeightInfo; } 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(); + pallet_balances::GenesisConfig:: { balances: vec![(1, 10_000_000), (2, 10_000_000)], }.assimilate_storage(&mut t).unwrap(); @@ -715,6 +714,14 @@ mod tests { runtime_parachains::Origin::Parachain(id).into() } + fn max_code_size() -> u32 { + ParachainsConfiguration::config().max_code_size + } + + fn max_head_size() -> u32 { + ParachainsConfiguration::config().max_head_data_size + } + #[test] fn basic_setup_works() { new_test_ext().execute_with(|| { @@ -796,8 +803,8 @@ mod tests { assert_noop!(Registrar::register( Origin::signed(1), para_id, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), ), Error::::NotReserved); // Successfully register para @@ -806,15 +813,15 @@ mod tests { assert_noop!(Registrar::register( Origin::signed(2), para_id, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), ), Error::::NotOwner); assert_ok!(Registrar::register( Origin::signed(1), para_id, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), )); run_to_session(2); @@ -825,8 +832,8 @@ mod tests { assert_noop!(Registrar::register( Origin::signed(1), para_id, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), ), Error::::NotReserved); // Head Size Check @@ -834,16 +841,16 @@ mod tests { assert_noop!(Registrar::register( Origin::signed(2), para_id + 1, - test_genesis_head((::MaxHeadSize::get() + 1) as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head((max_head_size() + 1) as usize), + test_validation_code(max_code_size() as usize), ), Error::::HeadDataTooLarge); // Code Size Check assert_noop!(Registrar::register( Origin::signed(2), para_id + 1, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code((::MaxCodeSize::get() + 1) as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code((max_code_size() + 1) as usize), ), Error::::CodeTooLarge); // Needs enough funds for deposit @@ -916,15 +923,15 @@ mod tests { assert_ok!(Registrar::register( Origin::signed(1), para_1, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), )); assert_ok!(Registrar::reserve(Origin::signed(2))); assert_ok!(Registrar::register( Origin::signed(2), para_2, - test_genesis_head(::MaxHeadSize::get() as usize), - test_validation_code(::MaxCodeSize::get() as usize), + test_genesis_head(max_head_size() as usize), + test_validation_code(max_code_size() as usize), )); run_to_session(2); diff --git a/polkadot/runtime/kusama/src/constants.rs b/polkadot/runtime/kusama/src/constants.rs index e1e460f22b..29040efb48 100644 --- a/polkadot/runtime/kusama/src/constants.rs +++ b/polkadot/runtime/kusama/src/constants.rs @@ -85,16 +85,6 @@ pub mod fee { } } -/// Parachains-related. -pub mod paras { - /// Maximum parachain code blob size. - pub const MAX_CODE_SIZE: u32 = 10 * 1024 * 1024; - /// Maximum parachain head size. - pub const MAX_HEAD_SIZE: u32 = 20 * 1024; - /// Maximum PoV size. - pub const MAX_POV_SIZE: u32 = 5 * 1024 * 1024; -} - #[cfg(test)] mod tests { use frame_support::weights::WeightToFeePolynomial; diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 2307ef527f..3ef60d774a 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -103,7 +103,7 @@ pub use pallet_balances::Call as BalancesCall; /// Constant values used within the runtime. pub mod constants; -use constants::{time::*, currency::*, fee::*, paras::*}; +use constants::{time::*, currency::*, fee::*}; // Weights used in the runtime. mod weights; @@ -1105,9 +1105,7 @@ impl parachains_initializer::Config for Runtime { } parameter_types! { - pub const ParaDeposit: Balance = deposit(10, MAX_CODE_SIZE + MAX_HEAD_SIZE); - pub const MaxCodeSize: u32 = MAX_CODE_SIZE; - pub const MaxHeadSize: u32 = MAX_HEAD_SIZE; + pub const ParaDeposit: Balance = 40 * UNITS; } impl paras_registrar::Config for Runtime { @@ -1117,8 +1115,6 @@ impl paras_registrar::Config for Runtime { type OnSwap = (Crowdloan, Slots); type ParaDeposit = ParaDeposit; type DataDepositPerByte = DataDepositPerByte; - type MaxCodeSize = MaxCodeSize; - type MaxHeadSize = MaxHeadSize; type WeightInfo = weights::runtime_common_paras_registrar::WeightInfo; } diff --git a/polkadot/runtime/kusama/src/weights/runtime_common_paras_registrar.rs b/polkadot/runtime/kusama/src/weights/runtime_common_paras_registrar.rs index 70458001a8..a10b1215f4 100644 --- a/polkadot/runtime/kusama/src/weights/runtime_common_paras_registrar.rs +++ b/polkadot/runtime/kusama/src/weights/runtime_common_paras_registrar.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for runtime_common::paras_registrar //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-06-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-06-21, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 // Executed Command: @@ -31,7 +31,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --header=./file_header.txt -// --output=./runtime/kusama/src/weights/ +// --output=./runtime/kusama/src/weights/runtime_common_paras_registrar.rs #![allow(unused_parens)] @@ -44,27 +44,27 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_common::paras_registrar::WeightInfo for WeightInfo { fn reserve() -> Weight { - (48_482_000 as Weight) + (59_279_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn register() -> Weight { - (5_547_143_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (4_148_907_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn force_register() -> Weight { - (5_523_892_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (4_144_844_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn deregister() -> Weight { - (85_065_000 as Weight) + (90_495_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn swap() -> Weight { - (76_222_000 as Weight) + (80_604_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index ab05b6a925..5b500b9d0d 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -19,7 +19,7 @@ //! Configuration can change only at session boundaries and is buffered until then. use sp_std::prelude::*; -use primitives::v1::{Balance, SessionIndex}; +use primitives::v1::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_POV_SIZE}; use frame_support::{ decl_storage, decl_module, decl_error, ensure, @@ -243,6 +243,18 @@ impl HostConfiguration { if self.no_show_slots.is_zero() { panic!("`no_show_slots` must be at least 1!") } + + if self.max_code_size > MAX_CODE_SIZE { + panic!( + "`max_code_size` ({}) is bigger than allowed by the client ({})", + self.max_code_size, + MAX_CODE_SIZE, + ) + } + + if self.max_pov_size > MAX_POV_SIZE { + panic!("`max_pov_size` is bigger than allowed by the client") + } } } @@ -308,6 +320,7 @@ decl_module! { #[weight = (1_000, DispatchClass::Operational)] pub fn set_max_code_size(origin, new: u32) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= MAX_CODE_SIZE, Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_code_size, new) != new }); @@ -318,6 +331,7 @@ decl_module! { #[weight = (1_000, DispatchClass::Operational)] pub fn set_max_pov_size(origin, new: u32) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= MAX_POV_SIZE, Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.max_pov_size, new) != new }); diff --git a/polkadot/runtime/rococo/src/constants.rs b/polkadot/runtime/rococo/src/constants.rs index 1ff2a7103f..1264a746f7 100644 --- a/polkadot/runtime/rococo/src/constants.rs +++ b/polkadot/runtime/rococo/src/constants.rs @@ -46,11 +46,6 @@ pub mod time { pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); } -/// Size restrictions. -pub mod size { - pub use primitives::v1::MAX_CODE_SIZE; -} - /// Fee-related. pub mod fee { pub use sp_runtime::Perbill; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e33ca703c3..d7da171acd 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -94,7 +94,7 @@ use xcm_builder::{ ChildSystemParachainAsSuperuser, LocationInverter, IsConcrete, FixedWeightBounds, BackingToPlurality, SignedToAccountId32, UsingComponents, }; -use constants::{time::*, currency::*, fee::*, size::*}; +use constants::{time::*, currency::*, fee::*}; use frame_support::traits::InstanceFilter; /// Constant values used within the runtime. @@ -790,8 +790,6 @@ impl paras_sudo_wrapper::Config for Runtime {} parameter_types! { pub const ParaDeposit: Balance = 5 * DOLLARS; pub const DataDepositPerByte: Balance = deposit(0, 1); - pub const MaxCodeSize: u32 = MAX_CODE_SIZE; - pub const MaxHeadSize: u32 = 20 * 1024; // 20 KB } impl paras_registrar::Config for Runtime { @@ -801,8 +799,6 @@ impl paras_registrar::Config for Runtime { type OnSwap = (Crowdloan, Slots); type ParaDeposit = ParaDeposit; type DataDepositPerByte = DataDepositPerByte; - type MaxCodeSize = MaxCodeSize; - type MaxHeadSize = MaxHeadSize; type WeightInfo = paras_registrar::TestWeightInfo; } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index d7a3b283de..80c44cb1a7 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -782,8 +782,6 @@ impl paras_sudo_wrapper::Config for Runtime {} parameter_types! { pub const ParaDeposit: Balance = 2000 * CENTS; pub const DataDepositPerByte: Balance = deposit(0, 1); - pub const MaxCodeSize: u32 = 5 * 1024 * 1024; // 10 MB - pub const MaxHeadSize: u32 = 20 * 1024; // 20 KB } impl paras_registrar::Config for Runtime { @@ -793,8 +791,6 @@ impl paras_registrar::Config for Runtime { type OnSwap = (Crowdloan, Slots); type ParaDeposit = ParaDeposit; type DataDepositPerByte = DataDepositPerByte; - type MaxCodeSize = MaxCodeSize; - type MaxHeadSize = MaxHeadSize; type WeightInfo = weights::runtime_common_paras_registrar::WeightInfo; } diff --git a/polkadot/runtime/westend/src/weights/runtime_common_paras_registrar.rs b/polkadot/runtime/westend/src/weights/runtime_common_paras_registrar.rs index 82a60ae3c6..3526923a7d 100644 --- a/polkadot/runtime/westend/src/weights/runtime_common_paras_registrar.rs +++ b/polkadot/runtime/westend/src/weights/runtime_common_paras_registrar.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for runtime_common::paras_registrar //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-06-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-06-21, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 // Executed Command: @@ -31,7 +31,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --header=./file_header.txt -// --output=./runtime/westend/src/weights/ +// --output=./runtime/westend/src/weights/runtime_common_paras_registrar.rs #![allow(unused_parens)] @@ -44,27 +44,27 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_common::paras_registrar::WeightInfo for WeightInfo { fn reserve() -> Weight { - (47_922_000 as Weight) + (58_328_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn register() -> Weight { - (5_460_797_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (4_162_851_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn force_register() -> Weight { - (5_353_681_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) + (4_141_674_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn deregister() -> Weight { - (82_918_000 as Weight) + (91_960_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn swap() -> Weight { - (73_098_000 as Weight) + (79_489_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) }