Add benchmarking for parachain runtime configuration pallet (#3862)

* Add benchmarking for parachain runtime configuration pallet

* cargo fmt

* Add WeightInfo trait

* Specify missing WeightInfo associated type in mocks

* Fix typo

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

* Fix compilation errors

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

* Condense the number of WeightInfo methods

* Fixes

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

* Make use of weights generated from kusama benchmarking

* Use a better dispatch function for weighing set_config_with_block_number

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

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

Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
Keith Yeung
2021-09-18 02:57:50 -07:00
committed by GitHub
parent aca0b2429d
commit 706f142516
18 changed files with 407 additions and 58 deletions
@@ -26,6 +26,10 @@ use primitives::v1::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_POV_SIZE};
use sp_runtime::traits::Zero;
use sp_std::prelude::*;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use pallet::*;
pub mod migration;
@@ -258,6 +262,15 @@ impl<BlockNumber: Zero> HostConfiguration<BlockNumber> {
}
}
pub trait WeightInfo {
fn set_config_with_block_number() -> Weight;
fn set_config_with_u32() -> Weight;
fn set_config_with_option_u32() -> Weight;
fn set_config_with_weight() -> Weight;
fn set_config_with_balance() -> Weight;
fn set_hrmp_open_request_ttl() -> Weight;
}
#[frame_support::pallet]
pub mod pallet {
use super::*;
@@ -268,7 +281,10 @@ pub mod pallet {
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config + shared::Config {}
pub trait Config: frame_system::Config + shared::Config {
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
#[pallet::error]
pub enum Error<T> {
@@ -310,7 +326,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the validation upgrade frequency.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_validation_upgrade_frequency(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -323,7 +339,7 @@ pub mod pallet {
}
/// Set the validation upgrade delay.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_validation_upgrade_delay(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -336,7 +352,7 @@ pub mod pallet {
}
/// Set the acceptance period for an included candidate.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_code_retention_period(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -349,7 +365,7 @@ pub mod pallet {
}
/// Set the max validation code size for incoming upgrades.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_code_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
ensure!(new <= MAX_CODE_SIZE, Error::<T>::InvalidNewValue);
@@ -360,7 +376,7 @@ pub mod pallet {
}
/// Set the max POV block size for incoming upgrades.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_pov_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
ensure!(new <= MAX_POV_SIZE, Error::<T>::InvalidNewValue);
@@ -371,7 +387,7 @@ pub mod pallet {
}
/// Set the max head data size for paras.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_head_data_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -381,7 +397,7 @@ pub mod pallet {
}
/// Set the number of parathread execution cores.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_parathread_cores(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -391,7 +407,7 @@ pub mod pallet {
}
/// Set the number of retries for a particular parathread.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_parathread_retries(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -401,7 +417,7 @@ pub mod pallet {
}
/// Set the parachain validator-group rotation frequency
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_group_rotation_frequency(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -417,7 +433,7 @@ pub mod pallet {
}
/// Set the availability period for parachains.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_chain_availability_period(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -433,7 +449,7 @@ pub mod pallet {
}
/// Set the availability period for parathreads.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_thread_availability_period(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -449,7 +465,7 @@ pub mod pallet {
}
/// Set the scheduling lookahead, in expected number of blocks at peak throughput.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_scheduling_lookahead(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -459,7 +475,7 @@ pub mod pallet {
}
/// Set the maximum number of validators to assign to any core.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_option_u32())]
pub fn set_max_validators_per_core(
origin: OriginFor<T>,
new: Option<u32>,
@@ -472,7 +488,7 @@ pub mod pallet {
}
/// Set the maximum number of validators to use in parachain consensus.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_option_u32())]
pub fn set_max_validators(origin: OriginFor<T>, new: Option<u32>) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -482,7 +498,7 @@ pub mod pallet {
}
/// Set the dispute period, in number of sessions to keep for disputes.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_dispute_period(origin: OriginFor<T>, new: SessionIndex) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -492,7 +508,7 @@ pub mod pallet {
}
/// Set the dispute post conclusion acceptance period.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_dispute_post_conclusion_acceptance_period(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -506,7 +522,7 @@ pub mod pallet {
}
/// Set the maximum number of dispute spam slots.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_dispute_max_spam_slots(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -516,7 +532,7 @@ pub mod pallet {
}
/// Set the dispute conclusion by time out period.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_block_number())]
pub fn set_dispute_conclusion_by_time_out_period(
origin: OriginFor<T>,
new: T::BlockNumber,
@@ -530,7 +546,7 @@ pub mod pallet {
/// Set the no show slots, in number of number of consensus slots.
/// Must be at least 1.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_no_show_slots(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
@@ -543,7 +559,7 @@ pub mod pallet {
}
/// Set the total number of delay tranches.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_n_delay_tranches(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -553,7 +569,7 @@ pub mod pallet {
}
/// Set the zeroth delay tranche width.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_zeroth_delay_tranche_width(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -563,7 +579,7 @@ pub mod pallet {
}
/// Set the number of validators needed to approve a block.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_needed_approvals(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -573,7 +589,7 @@ pub mod pallet {
}
/// Set the number of samples to do of the `RelayVRFModulo` approval assignment criterion.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_relay_vrf_modulo_samples(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -583,7 +599,7 @@ pub mod pallet {
}
/// Sets the maximum items that can present in a upward dispatch queue at once.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_upward_queue_count(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -593,7 +609,7 @@ pub mod pallet {
}
/// Sets the maximum total size of items that can present in a upward dispatch queue at once.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_upward_queue_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -603,7 +619,7 @@ pub mod pallet {
}
/// Set the critical downward message size.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_downward_message_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -613,7 +629,7 @@ pub mod pallet {
}
/// Sets the soft limit for the phase of dispatching dispatchable upward messages.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_weight())]
pub fn set_ump_service_total_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -623,7 +639,7 @@ pub mod pallet {
}
/// Sets the maximum size of an upward message that can be sent by a candidate.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_upward_message_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -633,7 +649,7 @@ pub mod pallet {
}
/// Sets the maximum number of messages that a candidate can contain.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_max_upward_message_num_per_candidate(
origin: OriginFor<T>,
new: u32,
@@ -646,7 +662,7 @@ pub mod pallet {
}
/// Sets the number of sessions after which an HRMP open channel request expires.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_hrmp_open_request_ttl())]
// Deprecated, but is not marked as such, because that would trigger warnings coming from
// the macro.
pub fn set_hrmp_open_request_ttl(_origin: OriginFor<T>, _new: u32) -> DispatchResult {
@@ -654,7 +670,7 @@ pub mod pallet {
}
/// Sets the amount of funds that the sender should provide for opening an HRMP channel.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_balance())]
pub fn set_hrmp_sender_deposit(origin: OriginFor<T>, new: Balance) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -665,7 +681,7 @@ pub mod pallet {
/// Sets the amount of funds that the recipient should provide for accepting opening an HRMP
/// channel.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_balance())]
pub fn set_hrmp_recipient_deposit(origin: OriginFor<T>, new: Balance) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -675,7 +691,7 @@ pub mod pallet {
}
/// Sets the maximum number of messages allowed in an HRMP channel at once.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_channel_max_capacity(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -685,7 +701,7 @@ pub mod pallet {
}
/// Sets the maximum total size of messages in bytes allowed in an HRMP channel at once.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_channel_max_total_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -695,7 +711,7 @@ pub mod pallet {
}
/// Sets the maximum number of inbound HRMP channels a parachain is allowed to accept.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_max_parachain_inbound_channels(
origin: OriginFor<T>,
new: u32,
@@ -708,7 +724,7 @@ pub mod pallet {
}
/// Sets the maximum number of inbound HRMP channels a parathread is allowed to accept.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_max_parathread_inbound_channels(
origin: OriginFor<T>,
new: u32,
@@ -721,7 +737,7 @@ pub mod pallet {
}
/// Sets the maximum size of a message that could ever be put into an HRMP channel.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_channel_max_message_size(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
@@ -731,7 +747,7 @@ pub mod pallet {
}
/// Sets the maximum number of outbound HRMP channels a parachain is allowed to open.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_max_parachain_outbound_channels(
origin: OriginFor<T>,
new: u32,
@@ -744,7 +760,7 @@ pub mod pallet {
}
/// Sets the maximum number of outbound HRMP channels a parathread is allowed to open.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_max_parathread_outbound_channels(
origin: OriginFor<T>,
new: u32,
@@ -757,7 +773,7 @@ pub mod pallet {
}
/// Sets the maximum number of outbound HRMP messages can be sent by a candidate.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_u32())]
pub fn set_hrmp_max_message_num_per_candidate(
origin: OriginFor<T>,
new: u32,
@@ -770,7 +786,7 @@ pub mod pallet {
}
/// Sets the maximum amount of weight any individual upward message may consume.
#[pallet::weight((1_000, DispatchClass::Operational))]
#[pallet::weight(T::WeightInfo::set_config_with_weight())]
pub fn set_ump_max_individual_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {