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: Parity Bot <admin@parity.io>
This commit is contained in:
Shawn Tabrizi
2021-06-21 18:24:49 +01:00
committed by GitHub
parent 45ed52a273
commit 6b1baba490
15 changed files with 131 additions and 126 deletions
@@ -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::<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 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::<Test>::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),
+42 -35
View File
@@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
@@ -110,14 +111,6 @@ pub mod pallet {
#[pallet::constant]
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
type WeightInfo: WeightInfo;
}
@@ -388,15 +381,15 @@ impl<T: Config> Registrar for Pallet<T> {
#[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::<T>::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::<T>::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<T: Config> Pallet<T> {
validation_code: ValidationCode,
parachain: bool,
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::<T>::CodeTooLarge);
ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::<T>::HeadDataTooLarge);
let config = configuration::Pallet::<T>::config();
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 deposit = T::ParaDeposit::get()
@@ -577,6 +571,7 @@ mod tests {
{
System: frame_system::{Pallet, Call, Config, Storage, 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},
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
}
@@ -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::<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> {
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(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),
test_genesis_head(max_head_size() as usize),
test_validation_code(max_code_size() as usize),
), Error::<Test>::NotReserved);
// Successfully register para
@@ -806,15 +813,15 @@ mod tests {
assert_noop!(Registrar::register(
Origin::signed(2),
para_id,
test_genesis_head(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),
test_genesis_head(max_head_size() as usize),
test_validation_code(max_code_size() as usize),
), Error::<Test>::NotOwner);
assert_ok!(Registrar::register(
Origin::signed(1),
para_id,
test_genesis_head(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::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(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),
test_genesis_head(max_head_size() as usize),
test_validation_code(max_code_size() as usize),
), Error::<Test>::NotReserved);
// Head Size Check
@@ -834,16 +841,16 @@ mod tests {
assert_noop!(Registrar::register(
Origin::signed(2),
para_id + 1,
test_genesis_head((<Test as super::Config>::MaxHeadSize::get() + 1) as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),
test_genesis_head((max_head_size() + 1) as usize),
test_validation_code(max_code_size() as usize),
), Error::<Test>::HeadDataTooLarge);
// Code Size Check
assert_noop!(Registrar::register(
Origin::signed(2),
para_id + 1,
test_genesis_head(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code((<Test as super::Config>::MaxCodeSize::get() + 1) as usize),
test_genesis_head(max_head_size() as usize),
test_validation_code((max_code_size() + 1) as usize),
), Error::<Test>::CodeTooLarge);
// Needs enough funds for deposit
@@ -916,15 +923,15 @@ mod tests {
assert_ok!(Registrar::register(
Origin::signed(1),
para_1,
test_genesis_head(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::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(<Test as super::Config>::MaxHeadSize::get() as usize),
test_validation_code(<Test as super::Config>::MaxCodeSize::get() as usize),
test_genesis_head(max_head_size() as usize),
test_validation_code(max_code_size() as usize),
));
run_to_session(2);