From b65c5e281f5468d9346f17e14cbbbef8074c7d11 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 22 Sep 2021 21:35:35 -0700 Subject: [PATCH 01/12] Add benchmarking for parachain runtime initializer pallet --- runtime/kusama/src/lib.rs | 3 ++ runtime/parachains/src/initializer.rs | 17 +++++++- .../src/initializer/benchmarking.rs | 37 ++++++++++++++++ runtime/parachains/src/initializer/weights.rs | 42 +++++++++++++++++++ runtime/parachains/src/mock.rs | 1 + runtime/rococo/src/lib.rs | 1 + runtime/test-runtime/src/lib.rs | 1 + runtime/westend/src/lib.rs | 3 ++ 8 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 runtime/parachains/src/initializer/benchmarking.rs create mode 100644 runtime/parachains/src/initializer/weights.rs diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index c2fa01f66f36..445887d613a5 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 = (); } 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/parachains/src/initializer.rs b/runtime/parachains/src/initializer.rs index 6958d754c462..b78eddfeb046 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 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 mod weights; + pub use pallet::*; /// Information about a session change that has just occurred. @@ -69,6 +76,10 @@ struct BufferedSessionChange { session_index: SessionIndex, } +pub trait WeightInfo { + fn force_approve() -> Weight; +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -96,6 +107,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 +194,7 @@ 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(), 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..0d53c754948e --- /dev/null +++ b/runtime/parachains/src/initializer/benchmarking.rs @@ -0,0 +1,37 @@ +// 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; +use sp_runtime::traits::One; + +benchmarks! { + force_approve {}: _(RawOrigin::Root, One::one()) + verify { + assert_eq!( + >::digest().logs.last().unwrap(), + &>::from(ConsensusLog::ForceApprove(One::one())), + ); + } +} + +impl_benchmark_test_suite!( + Pallet, + crate::mock::new_test_ext(Default::default()), + crate::mock::Test +); diff --git a/runtime/parachains/src/initializer/weights.rs b/runtime/parachains/src/initializer/weights.rs new file mode 100644 index 000000000000..5affdd3df623 --- /dev/null +++ b/runtime/parachains/src/initializer/weights.rs @@ -0,0 +1,42 @@ + +//! Autogenerated weights for `runtime_parachains::initializer` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-23, 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 +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// runtime_parachains::initializer +// --steps +// 50 +// --repeat +// 20 +// --raw +// --extrinsic +// * +// --output +// runtime/parachains/src/initializer/weights.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; + +/// Weight functions for `runtime_parachains::initializer`. +impl super::WeightInfo for () { + // Storage: System Digest (r:1 w:1) + fn force_approve() -> Weight { + (5_115_000 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/mock.rs b/runtime/parachains/src/mock.rs index 387e0a7bf5e8..9e8a71f9b479 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/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 9f03cc8253e8..b03651bc23db 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -749,6 +749,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 722aab3e16af..197762ef0ffc 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -479,6 +479,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 179088dc1a57..86f143829d9a 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -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 = (); } 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); From b425d228374bf9ca5080ed70d0e979f5aef9c4dc Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 22 Sep 2021 23:41:49 -0700 Subject: [PATCH 02/12] Fix default impl for initializer pallet WeightInfo --- runtime/parachains/src/initializer/weights.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/initializer/weights.rs b/runtime/parachains/src/initializer/weights.rs index 5affdd3df623..c7128b1bd307 100644 --- a/runtime/parachains/src/initializer/weights.rs +++ b/runtime/parachains/src/initializer/weights.rs @@ -29,14 +29,14 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::weights::{constants::RocksDbWeight, Weight}; /// Weight functions for `runtime_parachains::initializer`. -impl super::WeightInfo for () { +impl super::WeightInfo for () { // Storage: System Digest (r:1 w:1) fn force_approve() -> Weight { (5_115_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } } From 808b1d3ed60e26cf586cc346ce7b67570510048f Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 23 Sep 2021 06:51:43 +0000 Subject: [PATCH 03/12] cargo run --quiet --release --features=runtime-benchmarks -- 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 --- .../weights/runtime_parachains_initializer.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 runtime/westend/src/weights/runtime_parachains_initializer.rs 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..8257b898dcf3 --- /dev/null +++ b/runtime/westend/src/weights/runtime_parachains_initializer.rs @@ -0,0 +1,53 @@ +// 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-23, 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() -> Weight { + (4_257_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} From 1987b3baa85b2c0c00f393b874414043128c22ca Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 23 Sep 2021 07:12:35 +0000 Subject: [PATCH 04/12] cargo run --quiet --release --features=runtime-benchmarks -- 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 --- .../weights/runtime_parachains_initializer.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 runtime/kusama/src/weights/runtime_parachains_initializer.rs 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..742afbcd23dd --- /dev/null +++ b/runtime/kusama/src/weights/runtime_parachains_initializer.rs @@ -0,0 +1,53 @@ +// 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-23, 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() -> Weight { + (4_297_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} From 694dfa4acd779d5a523f997a38d4ed68515ec638 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 23 Sep 2021 01:36:53 -0700 Subject: [PATCH 05/12] Use real weights and use max_block as default weight --- runtime/kusama/src/lib.rs | 2 +- runtime/kusama/src/weights/mod.rs | 1 + runtime/parachains/src/initializer.rs | 8 +++- runtime/parachains/src/initializer/weights.rs | 42 ------------------- runtime/westend/src/lib.rs | 4 +- runtime/westend/src/weights/mod.rs | 1 + 6 files changed, 12 insertions(+), 46 deletions(-) delete mode 100644 runtime/parachains/src/initializer/weights.rs diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 445887d613a5..fbe3d45f93f5 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1181,7 +1181,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; - type WeightInfo = (); + type WeightInfo = weights::runtime_parachains_initializer::WeightInfo; } parameter_types! { 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/parachains/src/initializer.rs b/runtime/parachains/src/initializer.rs index b78eddfeb046..1cf337f002e0 100644 --- a/runtime/parachains/src/initializer.rs +++ b/runtime/parachains/src/initializer.rs @@ -28,6 +28,7 @@ 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; @@ -35,7 +36,6 @@ use sp_std::prelude::*; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -pub mod weights; pub use pallet::*; @@ -80,6 +80,12 @@ pub trait WeightInfo { fn force_approve() -> Weight; } +impl WeightInfo for () { + fn force_approve() -> Weight { + BlockWeights::default().max_block + } +} + #[frame_support::pallet] pub mod pallet { use super::*; diff --git a/runtime/parachains/src/initializer/weights.rs b/runtime/parachains/src/initializer/weights.rs deleted file mode 100644 index c7128b1bd307..000000000000 --- a/runtime/parachains/src/initializer/weights.rs +++ /dev/null @@ -1,42 +0,0 @@ - -//! Autogenerated weights for `runtime_parachains::initializer` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-23, 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 -// --execution=wasm -// --wasm-execution=compiled -// --pallet -// runtime_parachains::initializer -// --steps -// 50 -// --repeat -// 20 -// --raw -// --extrinsic -// * -// --output -// runtime/parachains/src/initializer/weights.rs - - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::weights::{constants::RocksDbWeight, Weight}; - -/// Weight functions for `runtime_parachains::initializer`. -impl super::WeightInfo for () { - // Storage: System Digest (r:1 w:1) - fn force_approve() -> Weight { - (5_115_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } -} diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 86f143829d9a..2c71209852e2 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,7 +850,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; - type WeightInfo = (); + type WeightInfo = weights::runtime_parachains_initializer::WeightInfo; } impl paras_sudo_wrapper::Config for Runtime {} 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; From bf724d85f3fab6734d4a282b5b4fb67b4181ac1b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 24 Sep 2021 19:32:37 -0700 Subject: [PATCH 06/12] Add variable for digest vec length for initializer benchmark --- .../src/weights/runtime_parachains_initializer.rs | 2 +- runtime/parachains/src/initializer.rs | 11 ++++++++--- runtime/parachains/src/initializer/benchmarking.rs | 13 ++++++++++--- .../src/weights/runtime_parachains_initializer.rs | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_parachains_initializer.rs b/runtime/kusama/src/weights/runtime_parachains_initializer.rs index 742afbcd23dd..e4ef330416e1 100644 --- a/runtime/kusama/src/weights/runtime_parachains_initializer.rs +++ b/runtime/kusama/src/weights/runtime_parachains_initializer.rs @@ -45,7 +45,7 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_parachains::initializer::WeightInfo for WeightInfo { // Storage: System Digest (r:1 w:1) - fn force_approve() -> Weight { + fn force_approve(_: u32) -> Weight { (4_297_000 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 1cf337f002e0..ebaa68b46ba5 100644 --- a/runtime/parachains/src/initializer.rs +++ b/runtime/parachains/src/initializer.rs @@ -77,11 +77,11 @@ struct BufferedSessionChange { } pub trait WeightInfo { - fn force_approve() -> Weight; + fn force_approve(d: u32) -> Weight; } impl WeightInfo for () { - fn force_approve() -> Weight { + fn force_approve(_: u32) -> Weight { BlockWeights::default().max_block } } @@ -200,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((::WeightInfo::force_approve(), 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 index 0d53c754948e..7b52a25b278b 100644 --- a/runtime/parachains/src/initializer/benchmarking.rs +++ b/runtime/parachains/src/initializer/benchmarking.rs @@ -18,14 +18,21 @@ use super::*; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; use frame_system::{DigestItemOf, RawOrigin}; use primitives::v1::ConsensusLog; -use sp_runtime::traits::One; + +// Random large number for the digest +const DIGEST_MAX_LEN: u32 = 65536; benchmarks! { - force_approve {}: _(RawOrigin::Root, One::one()) + force_approve { + let d in 0 .. DIGEST_MAX_LEN; + for _ in 0 .. d { + >::deposit_log(ConsensusLog::ForceApprove(l).into()); + } + }: _(RawOrigin::Root, l + 1) verify { assert_eq!( >::digest().logs.last().unwrap(), - &>::from(ConsensusLog::ForceApprove(One::one())), + &>::from(ConsensusLog::ForceApprove(l + 1)), ); } } diff --git a/runtime/westend/src/weights/runtime_parachains_initializer.rs b/runtime/westend/src/weights/runtime_parachains_initializer.rs index 8257b898dcf3..b1cc58b01ff1 100644 --- a/runtime/westend/src/weights/runtime_parachains_initializer.rs +++ b/runtime/westend/src/weights/runtime_parachains_initializer.rs @@ -45,7 +45,7 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_parachains::initializer::WeightInfo for WeightInfo { // Storage: System Digest (r:1 w:1) - fn force_approve() -> Weight { + fn force_approve(_: u32) -> Weight { (4_257_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) From 196ccf376b8a1fdf7aec8793cb5f7c5bbb238689 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 24 Sep 2021 19:38:13 -0700 Subject: [PATCH 07/12] Fix compilation errors --- runtime/parachains/src/initializer/benchmarking.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/initializer/benchmarking.rs b/runtime/parachains/src/initializer/benchmarking.rs index 7b52a25b278b..d73c427f133d 100644 --- a/runtime/parachains/src/initializer/benchmarking.rs +++ b/runtime/parachains/src/initializer/benchmarking.rs @@ -26,13 +26,13 @@ benchmarks! { force_approve { let d in 0 .. DIGEST_MAX_LEN; for _ in 0 .. d { - >::deposit_log(ConsensusLog::ForceApprove(l).into()); + >::deposit_log(ConsensusLog::ForceApprove(d).into()); } - }: _(RawOrigin::Root, l + 1) + }: _(RawOrigin::Root, d + 1) verify { assert_eq!( >::digest().logs.last().unwrap(), - &>::from(ConsensusLog::ForceApprove(l + 1)), + &>::from(ConsensusLog::ForceApprove(d + 1)), ); } } From ec780410fc3ac58e81c57cc142e96ef5501eb32c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 24 Sep 2021 21:37:22 -0700 Subject: [PATCH 08/12] Add WeightInfo to parachains_initializer config in polkadot runtime --- runtime/polkadot/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index dccd33ebb8ad..1bb4f47c2283 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 = (); } parameter_types! { From a5134eecaccc1ca5c7e3cd2db45f32d40230ef61 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Sat, 25 Sep 2021 04:52:59 +0000 Subject: [PATCH 09/12] cargo run --quiet --release --features=runtime-benchmarks -- 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 --- .../westend/src/weights/runtime_parachains_initializer.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/westend/src/weights/runtime_parachains_initializer.rs b/runtime/westend/src/weights/runtime_parachains_initializer.rs index b1cc58b01ff1..9877d23b93fa 100644 --- a/runtime/westend/src/weights/runtime_parachains_initializer.rs +++ b/runtime/westend/src/weights/runtime_parachains_initializer.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::initializer` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! 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: @@ -45,8 +45,10 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_parachains::initializer::WeightInfo for WeightInfo { // Storage: System Digest (r:1 w:1) - fn force_approve(_: u32) -> Weight { - (4_257_000 as Weight) + 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)) } From b74c1bbc983a114ad95ca579778dbb1336bcc92f Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Sat, 25 Sep 2021 05:12:42 +0000 Subject: [PATCH 10/12] cargo run --quiet --release --features=runtime-benchmarks -- 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 --- .../kusama/src/weights/runtime_parachains_initializer.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_parachains_initializer.rs b/runtime/kusama/src/weights/runtime_parachains_initializer.rs index e4ef330416e1..6b41892d3e45 100644 --- a/runtime/kusama/src/weights/runtime_parachains_initializer.rs +++ b/runtime/kusama/src/weights/runtime_parachains_initializer.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::initializer` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! 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: @@ -45,8 +45,10 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_parachains::initializer::WeightInfo for WeightInfo { // Storage: System Digest (r:1 w:1) - fn force_approve(_: u32) -> Weight { - (4_297_000 as Weight) + 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)) } From acdb91aafbadf908ec235593e0984f378bec6a1a Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 24 Sep 2021 22:37:15 -0700 Subject: [PATCH 11/12] Appease spellchecker --- runtime/polkadot/src/weights/runtime_common_crowdloan.rs | 2 +- runtime/polkadot/src/weights/runtime_common_paras_registrar.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) From 48d549eed69eacfc8ef86e0d28b876fca608bb90 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 24 Sep 2021 22:39:14 -0700 Subject: [PATCH 12/12] Use kusama weights in polkadot runtime for parachain initializer pallet --- runtime/polkadot/src/lib.rs | 2 +- runtime/polkadot/src/weights/mod.rs | 1 + .../weights/runtime_parachains_initializer.rs | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 runtime/polkadot/src/weights/runtime_parachains_initializer.rs diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 1bb4f47c2283..62f0a8287b2a 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1146,7 +1146,7 @@ impl parachains_scheduler::Config for Runtime {} impl parachains_initializer::Config for Runtime { type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type ForceOrigin = EnsureRoot; - type WeightInfo = (); + 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_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)) + } +}