Skip to content

Commit

Permalink
Max proof size from relay, get Impl for max weight, int tests env hos…
Browse files Browse the repository at this point in the history
…tconfig

vals set
  • Loading branch information
thea-leake committed Dec 15, 2022
1 parent d5f7159 commit 3934b40
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 29 deletions.
73 changes: 48 additions & 25 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockWeights> 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<Weight> for MaxBlockWeight {
fn get() -> Weight {
let max_pov_size = if cfg!(test) {
MAX_POV_SIZE
} else {
cumulus_pallet_parachain_system::Pallet::<Runtime>::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
Expand All @@ -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;
Expand Down Expand Up @@ -590,15 +614,14 @@ 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<u32> = Some(10);
}

impl pallet_scheduler::Config for Runtime {
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type MaximumWeight = MaximumSchedulerWeight;
type MaximumWeight = MaxBlockWeight;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type PalletsOrigin = OriginCaller;
type Preimages = Preimage;
Expand Down
50 changes: 46 additions & 4 deletions runtime/integration-tests/src/pools/utils/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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};
Expand Down Expand Up @@ -679,9 +681,11 @@ fn test_env(

// We need to HostConfiguration and use the default here.
state.insert_storage(
polkadot_runtime_parachains::configuration::GenesisConfig::<RelayRt>::default()
.build_storage()
.expect("ESSENTIAL: GenesisBuild must not fail at this stage."),
polkadot_runtime_parachains::configuration::GenesisConfig::<RelayRt> {
config: default_parachains_host_configuration(),
}
.build_storage()
.expect("ESSENTIAL: GenesisBuild must not fail at this stage."),
);

state.insert_storage(
Expand Down Expand Up @@ -837,3 +841,41 @@ pub fn pass_n(env: &mut TestEnv, n: u64) -> Result<(), ()> {

Ok(())
}

fn default_parachains_host_configuration() -> HostConfiguration<BlockNumber> {
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()
}
}

0 comments on commit 3934b40

Please sign in to comment.