Unverified Commit 897afffb authored by Shawn Tabrizi's avatar Shawn Tabrizi Committed by GitHub
Browse files

Use `max_code_size` and `max_wasm_data_size` from Parachains Configuration (#3329)



* use `configuration::config()` for max bytes

* Update integration_tests.rs

* Update paras_registrar.rs

* remove consts

* add asserts for non-zero

* more const clean up

* cargo run --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::paras_registrar --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_paras_registrar.rs

* cargo run --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_common::paras_registrar --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_common_paras_registrar.rs

* add checks to `MAX_CODE_SIZE`

* re-pot MAX_POV_SIZE

* check pov limit in runtime

* POV_BOMB_LIMIT multiplier

* fix compile

* Update configuration.rs

* Update node/primitives/src/lib.rs

* fix test
Co-authored-by: default avatarParity Bot <admin@parity.io>
parent aa4e1545
Pipeline #143542 canceled with stages
in 14 minutes and 54 seconds
...@@ -36,8 +36,7 @@ use std::{borrow::Cow, u64}; ...@@ -36,8 +36,7 @@ use std::{borrow::Cow, u64};
use std::time::Duration; use std::time::Duration;
use futures::channel::mpsc; use futures::channel::mpsc;
use polkadot_node_primitives::MAX_POV_SIZE; use polkadot_primitives::v1::{MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_primitives::v1::MAX_CODE_SIZE;
use strum::EnumIter; use strum::EnumIter;
pub use sc_network::config as network; pub use sc_network::config as network;
......
...@@ -41,7 +41,7 @@ use polkadot_primitives::v1::{ ...@@ -41,7 +41,7 @@ use polkadot_primitives::v1::{
CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId, OutboundHrmpMessage, CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId, OutboundHrmpMessage,
PersistedValidationData, Signed, UncheckedSigned, UpwardMessage, ValidationCode, PersistedValidationData, Signed, UncheckedSigned, UpwardMessage, ValidationCode,
ValidatorIndex, ValidatorSignature, ValidDisputeStatementKind, InvalidDisputeStatementKind, ValidatorIndex, ValidatorSignature, ValidDisputeStatementKind, InvalidDisputeStatementKind,
CandidateReceipt, ValidatorId, SessionIndex, DisputeStatement, CandidateReceipt, ValidatorId, SessionIndex, DisputeStatement, MAX_CODE_SIZE, MAX_POV_SIZE,
}; };
pub use polkadot_parachain::primitives::BlockData; pub use polkadot_parachain::primitives::BlockData;
...@@ -49,13 +49,10 @@ pub use polkadot_parachain::primitives::BlockData; ...@@ -49,13 +49,10 @@ pub use polkadot_parachain::primitives::BlockData;
pub mod approval; pub mod approval;
/// The bomb limit for decompressing code blobs. /// The bomb limit for decompressing code blobs.
pub const VALIDATION_CODE_BOMB_LIMIT: usize = 16 * 1024 * 1024; pub const VALIDATION_CODE_BOMB_LIMIT: usize = (MAX_CODE_SIZE * 4u32) as usize;
/// Maximum PoV size we support right now.
pub const MAX_POV_SIZE: u32 = 20 * 1024 * 1024;
/// The bomb limit for decompressing PoV blobs. /// 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. /// The cumulative weight of a block in a fork-choice rule.
pub type BlockWeight = u32; pub type BlockWeight = u32;
......
...@@ -149,8 +149,7 @@ pub fn wococo_config() -> Result<RococoChainSpec, String> { ...@@ -149,8 +149,7 @@ pub fn wococo_config() -> Result<RococoChainSpec, String> {
fn default_parachains_host_configuration() -> fn default_parachains_host_configuration() ->
polkadot_runtime_parachains::configuration::HostConfiguration<polkadot_primitives::v1::BlockNumber> polkadot_runtime_parachains::configuration::HostConfiguration<polkadot_primitives::v1::BlockNumber>
{ {
use polkadot_node_primitives::MAX_POV_SIZE; use polkadot_primitives::v1::{MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_primitives::v1::MAX_CODE_SIZE;
polkadot_runtime_parachains::configuration::HostConfiguration { polkadot_runtime_parachains::configuration::HostConfiguration {
validation_upgrade_frequency: 1u32, validation_upgrade_frequency: 1u32,
......
...@@ -20,7 +20,7 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; ...@@ -20,7 +20,7 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use babe_primitives::AuthorityId as BabeId; use babe_primitives::AuthorityId as BabeId;
use grandpa::AuthorityId as GrandpaId; use grandpa::AuthorityId as GrandpaId;
use pallet_staking::Forcing; 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_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions};
use polkadot_test_runtime::{constants::currency::DOTS, BABE_GENESIS_EPOCH_CONFIG}; use polkadot_test_runtime::{constants::currency::DOTS, BABE_GENESIS_EPOCH_CONFIG};
use sc_chain_spec::{ChainSpec, ChainType}; use sc_chain_spec::{ChainSpec, ChainType};
...@@ -179,8 +179,8 @@ fn polkadot_testnet_genesis( ...@@ -179,8 +179,8 @@ fn polkadot_testnet_genesis(
validation_upgrade_frequency: 10u32, validation_upgrade_frequency: 10u32,
validation_upgrade_delay: 5, validation_upgrade_delay: 5,
code_retention_period: 1200, code_retention_period: 1200,
max_code_size: 5 * 1024 * 1024, max_code_size: MAX_CODE_SIZE,
max_pov_size: 50 * 1024 * 1024, max_pov_size: MAX_POV_SIZE,
max_head_data_size: 32 * 1024, max_head_data_size: 32 * 1024,
group_rotation_frequency: 20, group_rotation_frequency: 20,
chain_availability_period: 4, chain_availability_period: 4,
......
...@@ -190,8 +190,21 @@ pub const ASSIGNMENT_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"asgn"); ...@@ -190,8 +190,21 @@ pub const ASSIGNMENT_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"asgn");
/// Maximum compressed code size we support right now. /// Maximum compressed code size we support right now.
/// At the moment we have runtime upgrade on chain, which restricts scalability severely. If we want /// 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. /// 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; 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 // The public key of a keypair used by a validator for determining assignments
/// to approve included parachain candidates. /// to approve included parachain candidates.
mod assignment_app { mod assignment_app {
......
...@@ -171,8 +171,6 @@ impl paras::Config for Test { ...@@ -171,8 +171,6 @@ impl paras::Config for Test {
parameter_types! { parameter_types! {
pub const ParaDeposit: Balance = 500; pub const ParaDeposit: Balance = 500;
pub const DataDepositPerByte: Balance = 1; pub const DataDepositPerByte: Balance = 1;
pub const MaxCodeSize: u32 = 200;
pub const MaxHeadSize: u32 = 100;
} }
impl paras_registrar::Config for Test { impl paras_registrar::Config for Test {
...@@ -180,8 +178,6 @@ impl paras_registrar::Config for Test { ...@@ -180,8 +178,6 @@ impl paras_registrar::Config for Test {
type OnSwap = (Crowdloan, Slots); type OnSwap = (Crowdloan, Slots);
type ParaDeposit = ParaDeposit; type ParaDeposit = ParaDeposit;
type DataDepositPerByte = DataDepositPerByte; type DataDepositPerByte = DataDepositPerByte;
type MaxCodeSize = MaxCodeSize;
type MaxHeadSize = MaxHeadSize;
type Currency = Balances; type Currency = Balances;
type Origin = Origin; type Origin = Origin;
type WeightInfo = crate::paras_registrar::TestWeightInfo; type WeightInfo = crate::paras_registrar::TestWeightInfo;
...@@ -237,7 +233,14 @@ impl crowdloan::Config for Test { ...@@ -237,7 +233,14 @@ impl crowdloan::Config for Test {
/// Create a new set of test externalities. /// Create a new set of test externalities.
pub fn new_test_ext() -> TestExternalities { pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap(); let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
configuration::GenesisConfig::<Test> {
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 keystore = KeyStore::new();
let mut ext: sp_io::TestExternalities = t.into(); let mut ext: sp_io::TestExternalities = t.into();
ext.register_extension(KeystoreExt(Arc::new(keystore))); ext.register_extension(KeystoreExt(Arc::new(keystore)));
...@@ -298,8 +301,8 @@ fn basic_end_to_end_works() { ...@@ -298,8 +301,8 @@ fn basic_end_to_end_works() {
let para_2 = LOWEST_PUBLIC_ID + 1; let para_2 = LOWEST_PUBLIC_ID + 1;
assert!(System::block_number().is_one()); assert!(System::block_number().is_one());
// User 1 and 2 will own parachains // User 1 and 2 will own parachains
Balances::make_free_balance_be(&1, 1_000); Balances::make_free_balance_be(&1, 1_000_000_000);
Balances::make_free_balance_be(&2, 1_000); Balances::make_free_balance_be(&2, 1_000_000_000);
// First register 2 parathreads // First register 2 parathreads
let genesis_head = Registrar::worst_head_data(); let genesis_head = Registrar::worst_head_data();
let validation_code = Registrar::worst_validation_code(); let validation_code = Registrar::worst_validation_code();
...@@ -348,8 +351,8 @@ fn basic_end_to_end_works() { ...@@ -348,8 +351,8 @@ fn basic_end_to_end_works() {
// Auction ending begins on block 100, so we make a bid before then. // Auction ending begins on block 100, so we make a bid before then.
run_to_block(90); run_to_block(90);
Balances::make_free_balance_be(&10, 1_000); Balances::make_free_balance_be(&10, 1_000_000_000);
Balances::make_free_balance_be(&20, 1_000); Balances::make_free_balance_be(&20, 1_000_000_000);
// User 10 will bid directly for parachain 1 // User 10 will bid directly for parachain 1
assert_ok!(Auctions::bid( assert_ok!(Auctions::bid(
...@@ -362,7 +365,7 @@ fn basic_end_to_end_works() { ...@@ -362,7 +365,7 @@ fn basic_end_to_end_works() {
)); ));
// User 2 will be a contribute to crowdloan for parachain 2 // 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)); assert_ok!(Crowdloan::contribute(Origin::signed(2), ParaId::from(para_2), 920, None));
// Auction ends at block 110 // Auction ends at block 110
...@@ -390,7 +393,7 @@ fn basic_end_to_end_works() { ...@@ -390,7 +393,7 @@ fn basic_end_to_end_works() {
); );
// Should not be able to contribute to a winning crowdloan // 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::<Test>::BidOrLeaseActive); assert_noop!(Crowdloan::contribute(Origin::signed(3), ParaId::from(2001), 10, None), CrowdloanError::<Test>::BidOrLeaseActive);
// New leases will start on block 400 // New leases will start on block 400
...@@ -444,8 +447,8 @@ fn basic_errors_fail() { ...@@ -444,8 +447,8 @@ fn basic_errors_fail() {
assert!(System::block_number().is_one()); assert!(System::block_number().is_one());
let para_id = LOWEST_PUBLIC_ID; let para_id = LOWEST_PUBLIC_ID;
// Can't double register // Can't double register
Balances::make_free_balance_be(&1, 1_000); Balances::make_free_balance_be(&1, 1_000_000_000);
Balances::make_free_balance_be(&2, 1_000); Balances::make_free_balance_be(&2, 1_000_000_000);
let genesis_head = Registrar::worst_head_data(); let genesis_head = Registrar::worst_head_data();
let validation_code = Registrar::worst_validation_code(); let validation_code = Registrar::worst_validation_code();
...@@ -492,7 +495,7 @@ fn competing_slots() { ...@@ -492,7 +495,7 @@ fn competing_slots() {
// Create n paras and owners // Create n paras and owners
for n in 1 ..= max_bids { 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 genesis_head = Registrar::worst_head_data();
let validation_code = Registrar::worst_validation_code(); let validation_code = Registrar::worst_validation_code();
assert_ok!(Registrar::reserve(Origin::signed(n))); assert_ok!(Registrar::reserve(Origin::signed(n)));
...@@ -577,7 +580,7 @@ fn competing_bids() { ...@@ -577,7 +580,7 @@ fn competing_bids() {
let start_para = LOWEST_PUBLIC_ID - 1; let start_para = LOWEST_PUBLIC_ID - 1;
// Create 3 paras and owners // Create 3 paras and owners
for n in 1 ..= 3 { 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 genesis_head = Registrar::worst_head_data();
let validation_code = Registrar::worst_validation_code(); let validation_code = Registrar::worst_validation_code();
assert_ok!(Registrar::reserve(Origin::signed(n))); assert_ok!(Registrar::reserve(Origin::signed(n)));
...@@ -664,8 +667,8 @@ fn basic_swap_works() { ...@@ -664,8 +667,8 @@ fn basic_swap_works() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
assert!(System::block_number().is_one()); // So events are emitted assert!(System::block_number().is_one()); // So events are emitted
// User 1 and 2 will own paras // User 1 and 2 will own paras
Balances::make_free_balance_be(&1, 1_000); Balances::make_free_balance_be(&1, 1_000_000_000);
Balances::make_free_balance_be(&2, 1_000); Balances::make_free_balance_be(&2, 1_000_000_000);
// First register 2 parathreads with different data // First register 2 parathreads with different data
assert_ok!(Registrar::reserve(Origin::signed(1))); assert_ok!(Registrar::reserve(Origin::signed(1)));
assert_ok!(Registrar::register( assert_ok!(Registrar::register(
...@@ -711,7 +714,7 @@ fn basic_swap_works() { ...@@ -711,7 +714,7 @@ fn basic_swap_works() {
// Bunch of contributions // Bunch of contributions
let mut total = 0; let mut total = 0;
for i in 10 .. 20 { 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)); assert_ok!(Crowdloan::contribute(Origin::signed(i), ParaId::from(2000), 900 - i, None));
total += 900 - i; total += 900 - i;
} }
...@@ -797,8 +800,8 @@ fn crowdloan_ending_period_bid() { ...@@ -797,8 +800,8 @@ fn crowdloan_ending_period_bid() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
assert!(System::block_number().is_one()); // So events are emitted assert!(System::block_number().is_one()); // So events are emitted
// User 1 and 2 will own paras // User 1 and 2 will own paras
Balances::make_free_balance_be(&1, 1_000); Balances::make_free_balance_be(&1, 1_000_000_000);
Balances::make_free_balance_be(&2, 1_000); Balances::make_free_balance_be(&2, 1_000_000_000);
// First register 2 parathreads // First register 2 parathreads
assert_ok!(Registrar::reserve(Origin::signed(1))); assert_ok!(Registrar::reserve(Origin::signed(1)));
assert_ok!(Registrar::register( assert_ok!(Registrar::register(
...@@ -844,7 +847,7 @@ fn crowdloan_ending_period_bid() { ...@@ -844,7 +847,7 @@ fn crowdloan_ending_period_bid() {
// Bunch of contributions // Bunch of contributions
let mut total = 0; let mut total = 0;
for i in 10 .. 20 { 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)); assert_ok!(Crowdloan::contribute(Origin::signed(i), ParaId::from(2000), 900 - i, None));
total += 900 - i; total += 900 - i;
} }
...@@ -852,7 +855,7 @@ fn crowdloan_ending_period_bid() { ...@@ -852,7 +855,7 @@ fn crowdloan_ending_period_bid() {
assert_eq!(Balances::free_balance(&crowdloan_account), total); assert_eq!(Balances::free_balance(&crowdloan_account), total);
// Bid for para 2 directly // 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( assert_ok!(Auctions::bid(
Origin::signed(2), Origin::signed(2),
ParaId::from(2001), ParaId::from(2001),
...@@ -874,7 +877,7 @@ fn crowdloan_ending_period_bid() { ...@@ -874,7 +877,7 @@ fn crowdloan_ending_period_bid() {
run_to_block(101); 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)); assert_ok!(Crowdloan::contribute(Origin::signed(1234), ParaId::from(2000), 900, None));
// Data propagates correctly // Data propagates correctly
...@@ -897,7 +900,7 @@ fn auction_bid_requires_registered_para() { ...@@ -897,7 +900,7 @@ fn auction_bid_requires_registered_para() {
assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start)); assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start));
// Can't bid with non-registered paras // 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( assert_noop!(Auctions::bid(
Origin::signed(1), Origin::signed(1),
ParaId::from(2000), ParaId::from(2000),
...@@ -930,7 +933,7 @@ fn auction_bid_requires_registered_para() { ...@@ -930,7 +933,7 @@ fn auction_bid_requires_registered_para() {
run_to_session(2); run_to_session(2);
// Success // Success
Balances::make_free_balance_be(&1, 1_000); Balances::make_free_balance_be(&1, 1_000_000_000);
assert_ok!(Auctions::bid( assert_ok!(Auctions::bid(
Origin::signed(1), Origin::signed(1),
ParaId::from(2000), ParaId::from(2000),
...@@ -951,8 +954,8 @@ fn gap_bids_work() { ...@@ -951,8 +954,8 @@ fn gap_bids_work() {
let duration = 99u32; let duration = 99u32;
let lease_period_index_start = 4u32; let lease_period_index_start = 4u32;
assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start)); 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(&1, 1_000_000_000);
Balances::make_free_balance_be(&2, 1_000); Balances::make_free_balance_be(&2, 1_000_000_000);
// Now register 2 paras // Now register 2 paras
assert_ok!(Registrar::reserve(Origin::signed(1))); assert_ok!(Registrar::reserve(Origin::signed(1)));
...@@ -974,8 +977,8 @@ fn gap_bids_work() { ...@@ -974,8 +977,8 @@ fn gap_bids_work() {
run_to_session(2); run_to_session(2);
// Make bids // Make bids
Balances::make_free_balance_be(&10, 1_000); Balances::make_free_balance_be(&10, 1_000_000_000);
Balances::make_free_balance_be(&20, 1_000); Balances::make_free_balance_be(&20, 1_000_000_000);
// Slot 1 for 100 from 10 // Slot 1 for 100 from 10
assert_ok!(Auctions::bid( assert_ok!(Auctions::bid(
Origin::signed(10), Origin::signed(10),
......
...@@ -33,6 +33,7 @@ use runtime_parachains::{ ...@@ -33,6 +33,7 @@ use runtime_parachains::{
self, self,
ParaGenesisArgs, ParaGenesisArgs,
}, },
configuration,
ensure_parachain, ensure_parachain,
Origin, ParaLifecycle, Origin, ParaLifecycle,
}; };
...@@ -84,7 +85,7 @@ pub mod pallet { ...@@ -84,7 +85,7 @@ pub mod pallet {
#[pallet::config] #[pallet::config]
#[pallet::disable_frame_system_supertrait_check] #[pallet::disable_frame_system_supertrait_check]
pub trait Config: paras::Config { pub trait Config: configuration::Config + paras::Config {
/// The overarching event type. /// The overarching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>; type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
...@@ -110,14 +111,6 @@ pub mod pallet { ...@@ -110,14 +111,6 @@ pub mod pallet {
#[pallet::constant] #[pallet::constant]
type DataDepositPerByte: Get<BalanceOf<Self>>; type DataDepositPerByte: Get<BalanceOf<Self>>;
/// The maximum size for the validation code.
#[pallet::constant]
type MaxCodeSize: Get<u32>;
/// The maximum size for the head data.
#[pallet::constant]
type MaxHeadSize: Get<u32>;
/// Weight Information for the Extrinsics in the Pallet /// Weight Information for the Extrinsics in the Pallet
type WeightInfo: WeightInfo; type WeightInfo: WeightInfo;
} }
...@@ -388,15 +381,15 @@ impl<T: Config> Registrar for Pallet<T> { ...@@ -388,15 +381,15 @@ impl<T: Config> Registrar for Pallet<T> {
#[cfg(any(feature = "runtime-benchmarks", test))] #[cfg(any(feature = "runtime-benchmarks", test))]
fn worst_head_data() -> HeadData { fn worst_head_data() -> HeadData {
// TODO: Figure a way to allow bigger head data in benchmarks? let max_head_size = configuration::Pallet::<T>::config().max_head_data_size;
let max_head_size = (T::MaxHeadSize::get()).min(1 * 1024 * 1024); 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() vec![0u8; max_head_size as usize].into()
} }
#[cfg(any(feature = "runtime-benchmarks", test))] #[cfg(any(feature = "runtime-benchmarks", test))]
fn worst_validation_code() -> ValidationCode { fn worst_validation_code() -> ValidationCode {
// TODO: Figure a way to allow bigger wasm in benchmarks? let max_code_size = configuration::Pallet::<T>::config().max_code_size;
let max_code_size = (T::MaxCodeSize::get()).min(4 * 1024 * 1024); 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]; let validation_code = vec![0u8; max_code_size as usize];
validation_code.into() validation_code.into()
} }
...@@ -525,8 +518,9 @@ impl<T: Config> Pallet<T> { ...@@ -525,8 +518,9 @@ impl<T: Config> Pallet<T> {
validation_code: ValidationCode, validation_code: ValidationCode,
parachain: bool, parachain: bool,
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> { ) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::<T>::CodeTooLarge); let config = configuration::Pallet::<T>::config();
ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::<T>::HeadDataTooLarge); ensure!(validation_code.0.len() <= config.max_code_size as usize, Error::<T>::CodeTooLarge);
ensure!(genesis_head.0.len() <= config.max_head_data_size as usize, Error::<T>::HeadDataTooLarge);
let per_byte_fee = T::DataDepositPerByte::get(); let per_byte_fee = T::DataDepositPerByte::get();
let deposit = T::ParaDeposit::get() let deposit = T::ParaDeposit::get()
...@@ -577,6 +571,7 @@ mod tests { ...@@ -577,6 +571,7 @@ mod tests {
{ {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
ParachainsConfiguration: configuration::{Pallet, Call, Storage, Config<T>},
Parachains: paras::{Pallet, Origin, Call, Storage, Config<T>, Event}, Parachains: paras::{Pallet, Origin, Call, Storage, Config<T>, Event},
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>}, Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
} }
...@@ -647,8 +642,6 @@ mod tests { ...@@ -647,8 +642,6 @@ mod tests {
pub const DataDepositPerByte: Balance = 1; pub const DataDepositPerByte: Balance = 1;
pub const QueueSize: usize = 2; pub const QueueSize: usize = 2;
pub const MaxRetries: u32 = 3; pub const MaxRetries: u32 = 3;
pub const MaxCodeSize: u32 = 100;
pub const MaxHeadSize: u32 = 100;
} }
impl Config for Test { impl Config for Test {
...@@ -658,14 +651,20 @@ mod tests { ...@@ -658,14 +651,20 @@ mod tests {
type OnSwap = (); type OnSwap = ();
type ParaDeposit = ParaDeposit; type ParaDeposit = ParaDeposit;
type DataDepositPerByte = DataDepositPerByte; type DataDepositPerByte = DataDepositPerByte;
type MaxCodeSize = MaxCodeSize;
type MaxHeadSize = MaxHeadSize;
type WeightInfo = TestWeightInfo; type WeightInfo = TestWeightInfo;
} }
pub fn new_test_ext() -> TestExternalities { pub fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap(); let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
configuration::GenesisConfig::<Test> {
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::<Test> { pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10_000_000), (2, 10_000_000)], balances: vec![(1, 10_000_000), (2, 10_000_000)],
}.assimilate_storage(&mut t).unwrap(); }.assimilate_storage(&mut t).unwrap();
...@@ -715,6 +714,14 @@ mod tests { ...@@ -715,6 +714,14 @@ mod tests {
runtime_parachains::Origin::Parachain(id).into() 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] #[test]
fn basic_setup_works() { fn basic_setup_works() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
...@@ -796,8 +803,8 @@ mod tests { ...@@ -796,8 +803,8 @@ mod tests {
assert_noop!(Registrar::register( assert_noop!(Registrar::register(
Origin::signed(1), Origin::signed(1),
para_id, para_id,
test_genesis_head(<Test as super::Config>::MaxHeadSize::get() as usize), test_genesis_head(max_head_size() as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),