From 3934b400950554f818f43000867fa716a07eede0 Mon Sep 17 00:00:00 2001 From: Thea Leake Date: Thu, 15 Dec 2022 13:50:08 +0100 Subject: [PATCH] Max proof size from relay, get Impl for max weight, int tests env hostconfig vals set --- runtime/development/src/lib.rs | 73 ++++++++++++------- .../integration-tests/src/pools/utils/env.rs | 50 ++++++++++++- 2 files changed, 94 insertions(+), 29 deletions(-) diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 48949593e8..d5350a55bb 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -143,32 +143,56 @@ pub fn native_version() -> NativeVersion { } } -const MAX_BLOCK_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.set_proof_size(MAX_POV_SIZE as u64); - parameter_types! { - pub const MaximumBlockWeight: Weight = MAXIMUM_BLOCK_WEIGHT; pub const Version: RuntimeVersion = VERSION; pub RuntimeBlockLength: BlockLength = BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); - pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() - .base_block(BlockExecutionWeight::get()) - .for_class(DispatchClass::all(), |weights| { - weights.base_extrinsic = ExtrinsicBaseWeight::get(); - }) - .for_class(DispatchClass::Normal, |weights| { - weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAX_BLOCK_WEIGHT); - }) - .for_class(DispatchClass::Operational, |weights| { - weights.max_total = Some(MAX_BLOCK_WEIGHT); - // Operational transactions have some extra reserved space, so that they - // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. - weights.reserved = Some( - MAX_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAX_BLOCK_WEIGHT - ); - }) - .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) - .build_or_panic(); - pub const SS58Prefix: u8 = 136; + pub const SS58Prefix: u8 = 36; +} + +pub struct CalculateBlockWeights; + +impl Get for CalculateBlockWeights { + fn get() -> BlockWeights { + let max_weight = MaxBlockWeight::get(); + + BlockWeights::builder() + .base_block(BlockExecutionWeight::get()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = ExtrinsicBaseWeight::get(); + }) + .for_class(DispatchClass::Normal, |weights| { + weights.max_total = Some(NORMAL_DISPATCH_RATIO * max_weight); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = Some(max_weight); + // Operational transactions have some extra reserved space, so that they + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. + weights.reserved = Some(max_weight - NORMAL_DISPATCH_RATIO * max_weight); + }) + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) + // NOTE: We could think about chaning this to something that is sane default with a + // error log. As we now depend on some dynamic state from the relay-chain + .build_or_panic() + } +} + +pub struct MaxBlockWeight; + +impl Get for MaxBlockWeight { + fn get() -> Weight { + let max_pov_size = if cfg!(test) { + MAX_POV_SIZE + } else { + cumulus_pallet_parachain_system::Pallet::::validation_data() + .map(|x| x.max_pov_size) + .unwrap_or(MAX_POV_SIZE) + }; + + MAXIMUM_BLOCK_WEIGHT + .set_proof_size(max_pov_size.into()) + .into() + } } // system support impls @@ -184,7 +208,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; /// The index type for blocks. type BlockNumber = BlockNumber; - type BlockWeights = RuntimeBlockWeights; + type BlockWeights = CalculateBlockWeights; type DbWeight = RocksDbWeight; /// The type for hashing blocks and tries. type Hash = Hash; @@ -590,7 +614,6 @@ impl pallet_utility::Config for Runtime { } parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get(); pub const MaxScheduledPerBlock: u32 = 50; // Retry a scheduled item every 10 blocks (2 minutes) until the preimage exists. pub const NoPreimagePostponement: Option = Some(10); @@ -598,7 +621,7 @@ parameter_types! { impl pallet_scheduler::Config for Runtime { type MaxScheduledPerBlock = MaxScheduledPerBlock; - type MaximumWeight = MaximumSchedulerWeight; + type MaximumWeight = MaxBlockWeight; type OriginPrivilegeCmp = EqualPrivilegeOnly; type PalletsOrigin = OriginCaller; type Preimages = Preimage; diff --git a/runtime/integration-tests/src/pools/utils/env.rs b/runtime/integration-tests/src/pools/utils/env.rs index 6453841706..4e244712a7 100644 --- a/runtime/integration-tests/src/pools/utils/env.rs +++ b/runtime/integration-tests/src/pools/utils/env.rs @@ -18,7 +18,7 @@ use std::{ use cfg_primitives::{AuraId, BlockNumber, Index}; use codec::{Decode, Encode}; -use frame_support::traits::GenesisBuild; +use frame_support::{traits::GenesisBuild, weights::Weight}; use frame_system::EventRecord; use fudge::{ digest::{DigestCreator, DigestProvider, FudgeAuraDigest, FudgeBabeDigest}, @@ -35,6 +35,8 @@ use lazy_static::lazy_static; pub use macros::*; use polkadot_core_primitives::{Block as RelayBlock, Header as RelayHeader}; use polkadot_parachain::primitives::Id as ParaId; +use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_runtime_parachains::configuration::HostConfiguration; use rand::Rng; use sc_executor::{WasmExecutionMethod, WasmExecutor}; use sc_service::{TFullClient, TaskManager}; @@ -679,9 +681,11 @@ fn test_env( // We need to HostConfiguration and use the default here. state.insert_storage( - polkadot_runtime_parachains::configuration::GenesisConfig::::default() - .build_storage() - .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), + polkadot_runtime_parachains::configuration::GenesisConfig:: { + config: default_parachains_host_configuration(), + } + .build_storage() + .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), ); state.insert_storage( @@ -837,3 +841,41 @@ pub fn pass_n(env: &mut TestEnv, n: u64) -> Result<(), ()> { Ok(()) } + +fn default_parachains_host_configuration() -> HostConfiguration { + HostConfiguration { + minimum_validation_upgrade_delay: 5, + validation_upgrade_cooldown: 5u32, + validation_upgrade_delay: 5, + code_retention_period: 1200, + 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, + thread_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024, + ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + ..Default::default() + } +}