diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index c2fa01f66f36..fbe3d45f93f5 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1181,6 +1181,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; + type WeightInfo = weights::runtime_parachains_initializer::WeightInfo; } parameter_types! { @@ -2054,6 +2055,7 @@ sp_api::impl_runtime_apis! { list_benchmark!(list, extra, runtime_common::slots, Slots); list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar); list_benchmark!(list, extra, runtime_parachains::configuration, Configuration); + list_benchmark!(list, extra, runtime_parachains::initializer, Initializer); list_benchmark!(list, extra, runtime_parachains::paras, Paras); // Substrate list_benchmark!(list, extra, pallet_bags_list, BagsList); @@ -2130,6 +2132,7 @@ sp_api::impl_runtime_apis! { add_benchmark!(params, batches, runtime_common::slots, Slots); add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar); add_benchmark!(params, batches, runtime_parachains::configuration, Configuration); + add_benchmark!(params, batches, runtime_parachains::initializer, Initializer); add_benchmark!(params, batches, runtime_parachains::paras, Paras); // Substrate add_benchmark!(params, batches, pallet_balances, Balances); diff --git a/runtime/kusama/src/weights/mod.rs b/runtime/kusama/src/weights/mod.rs index 0b944e458a90..ea8c2fc7f58d 100644 --- a/runtime/kusama/src/weights/mod.rs +++ b/runtime/kusama/src/weights/mod.rs @@ -45,4 +45,5 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_initializer; pub mod runtime_parachains_paras; diff --git a/runtime/kusama/src/weights/runtime_parachains_initializer.rs b/runtime/kusama/src/weights/runtime_parachains_initializer.rs new file mode 100644 index 000000000000..6b41892d3e45 --- /dev/null +++ b/runtime/kusama/src/weights/runtime_parachains_initializer.rs @@ -0,0 +1,55 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::initializer` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=kusama-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::initializer +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/runtime_parachains_initializer.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::initializer`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::initializer::WeightInfo for WeightInfo { + // Storage: System Digest (r:1 w:1) + fn force_approve(d: u32, ) -> Weight { + (5_156_000 as Weight) + // Standard Error: 0 + .saturating_add((2_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/parachains/src/initializer.rs b/runtime/parachains/src/initializer.rs index 6958d754c462..ebaa68b46ba5 100644 --- a/runtime/parachains/src/initializer.rs +++ b/runtime/parachains/src/initializer.rs @@ -24,12 +24,19 @@ use crate::{ disputes::DisputesHandler, dmp, hrmp, inclusion, paras, scheduler, session_info, shared, ump, }; -use frame_support::traits::{OneSessionHandler, Randomness}; +use frame_support::{ + traits::{OneSessionHandler, Randomness}, + weights::Weight, +}; +use frame_system::limits::BlockWeights; use parity_scale_codec::{Decode, Encode}; use primitives::v1::{BlockNumber, ConsensusLog, SessionIndex, ValidatorId}; use scale_info::TypeInfo; use sp_std::prelude::*; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + pub use pallet::*; /// Information about a session change that has just occurred. @@ -69,6 +76,16 @@ struct BufferedSessionChange { session_index: SessionIndex, } +pub trait WeightInfo { + fn force_approve(d: u32) -> Weight; +} + +impl WeightInfo for () { + fn force_approve(_: u32) -> Weight { + BlockWeights::default().max_block + } +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -96,6 +113,8 @@ pub mod pallet { type Randomness: Randomness; /// An origin which is allowed to force updates to parachains. type ForceOrigin: EnsureOrigin<::Origin>; + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; } /// Whether the parachains modules have been initialized within this block. @@ -181,7 +200,12 @@ pub mod pallet { /// Issue a signal to the consensus engine to forcibly act as though all parachain /// blocks in all relay chain blocks up to and including the given number in the current /// chain are valid and should be finalized. - #[pallet::weight((0, DispatchClass::Operational))] + #[pallet::weight(( + ::WeightInfo::force_approve( + frame_system::Pallet::::digest().logs.len() as u32, + ), + DispatchClass::Operational, + ))] pub fn force_approve(origin: OriginFor, up_to: BlockNumber) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; diff --git a/runtime/parachains/src/initializer/benchmarking.rs b/runtime/parachains/src/initializer/benchmarking.rs new file mode 100644 index 000000000000..d73c427f133d --- /dev/null +++ b/runtime/parachains/src/initializer/benchmarking.rs @@ -0,0 +1,44 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use super::*; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; +use frame_system::{DigestItemOf, RawOrigin}; +use primitives::v1::ConsensusLog; + +// Random large number for the digest +const DIGEST_MAX_LEN: u32 = 65536; + +benchmarks! { + force_approve { + let d in 0 .. DIGEST_MAX_LEN; + for _ in 0 .. d { + >::deposit_log(ConsensusLog::ForceApprove(d).into()); + } + }: _(RawOrigin::Root, d + 1) + verify { + assert_eq!( + >::digest().logs.last().unwrap(), + &>::from(ConsensusLog::ForceApprove(d + 1)), + ); + } +} + +impl_benchmark_test_suite!( + Pallet, + crate::mock::new_test_ext(Default::default()), + crate::mock::Test +); diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 1ccf57ea357a..9e646dbbc1ca 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -112,6 +112,7 @@ impl pallet_balances::Config for Test { impl crate::initializer::Config for Test { type Randomness = TestRandomness; type ForceOrigin = frame_system::EnsureRoot; + type WeightInfo = (); } impl crate::configuration::Config for Test { diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index dccd33ebb8ad..62f0a8287b2a 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1146,6 +1146,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; + type WeightInfo = weights::runtime_parachains_initializer::WeightInfo; } parameter_types! { diff --git a/runtime/polkadot/src/weights/mod.rs b/runtime/polkadot/src/weights/mod.rs index 3dcd0edaac38..19842799a533 100644 --- a/runtime/polkadot/src/weights/mod.rs +++ b/runtime/polkadot/src/weights/mod.rs @@ -43,4 +43,5 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_initializer; pub mod runtime_parachains_paras; diff --git a/runtime/polkadot/src/weights/runtime_common_crowdloan.rs b/runtime/polkadot/src/weights/runtime_common_crowdloan.rs index e69442c8a884..7929c8c16754 100644 --- a/runtime/polkadot/src/weights/runtime_common_crowdloan.rs +++ b/runtime/polkadot/src/weights/runtime_common_crowdloan.rs @@ -41,7 +41,7 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for runtime_common::crowdloan. +/// Weight functions for `runtime_common::crowdloan`. pub struct WeightInfo(PhantomData); impl runtime_common::crowdloan::WeightInfo for WeightInfo { // Storage: Crowdloan Funds (r:1 w:1) diff --git a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs index 8dfc9409741c..84d3a89e92d0 100644 --- a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs @@ -41,7 +41,7 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for runtime_common::paras_registrar. +/// Weight functions for `runtime_common::paras_registrar`. pub struct WeightInfo(PhantomData); impl runtime_common::paras_registrar::WeightInfo for WeightInfo { // Storage: Registrar NextFreeParaId (r:1 w:1) diff --git a/runtime/polkadot/src/weights/runtime_parachains_initializer.rs b/runtime/polkadot/src/weights/runtime_parachains_initializer.rs new file mode 100644 index 000000000000..6b41892d3e45 --- /dev/null +++ b/runtime/polkadot/src/weights/runtime_parachains_initializer.rs @@ -0,0 +1,55 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::initializer` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=kusama-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::initializer +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/runtime_parachains_initializer.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::initializer`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::initializer::WeightInfo for WeightInfo { + // Storage: System Digest (r:1 w:1) + fn force_approve(d: u32, ) -> Weight { + (5_156_000 as Weight) + // Standard Error: 0 + .saturating_add((2_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 3cb61efd3c4a..72ededa5a2ed 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -751,6 +751,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; + type WeightInfo = (); } impl paras_sudo_wrapper::Config for Runtime {} diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 09da961b2169..842f451c40ed 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -480,6 +480,7 @@ impl parachains_paras_inherent::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = frame_system::EnsureRoot; + type WeightInfo = (); } impl parachains_session_info::Config for Runtime {} diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 196a28d57819..ca3c4366ad7a 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -805,7 +805,7 @@ impl pallet_proxy::Config for Runtime { impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { - type WeightInfo = parachains_configuration::weights::WeightInfo; + type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; } impl parachains_shared::Config for Runtime {} @@ -850,6 +850,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; + type WeightInfo = weights::runtime_parachains_initializer::WeightInfo; } impl paras_sudo_wrapper::Config for Runtime {} @@ -1478,6 +1479,7 @@ sp_api::impl_runtime_apis! { list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar); list_benchmark!(list, extra, runtime_common::slots, Slots); list_benchmark!(list, extra, runtime_parachains::configuration, Configuration); + list_benchmark!(list, extra, runtime_parachains::initializer, Initializer); list_benchmark!(list, extra, runtime_parachains::paras, Paras); // Substrate list_benchmark!(list, extra, pallet_bags_list, BagsList); @@ -1545,6 +1547,7 @@ sp_api::impl_runtime_apis! { add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar); add_benchmark!(params, batches, runtime_common::slots, Slots); add_benchmark!(params, batches, runtime_parachains::configuration, Configuration); + add_benchmark!(params, batches, runtime_parachains::initializer, Initializer); add_benchmark!(params, batches, runtime_parachains::paras, Paras); // Substrate add_benchmark!(params, batches, pallet_bags_list, BagsList); diff --git a/runtime/westend/src/weights/mod.rs b/runtime/westend/src/weights/mod.rs index c7dba930ed49..2e716c739e49 100644 --- a/runtime/westend/src/weights/mod.rs +++ b/runtime/westend/src/weights/mod.rs @@ -35,4 +35,5 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_initializer; pub mod runtime_parachains_paras; diff --git a/runtime/westend/src/weights/runtime_parachains_initializer.rs b/runtime/westend/src/weights/runtime_parachains_initializer.rs new file mode 100644 index 000000000000..9877d23b93fa --- /dev/null +++ b/runtime/westend/src/weights/runtime_parachains_initializer.rs @@ -0,0 +1,55 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::initializer` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=westend-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::initializer +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/westend/src/weights/runtime_parachains_initializer.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::initializer`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::initializer::WeightInfo for WeightInfo { + // Storage: System Digest (r:1 w:1) + fn force_approve(d: u32, ) -> Weight { + (6_607_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +}