Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add benchmarking for parachain runtime configuration pallet (#3862)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
KiChjang and Parity Bot authored Sep 18, 2021
1 parent e106953 commit 4c54766
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 58 deletions.
4 changes: 3 additions & 1 deletion runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
}

impl configuration::Config for Test {}
impl configuration::Config for Test {
type WeightInfo = configuration::weights::WeightInfo<Test>;
}

impl shared::Config for Test {}

Expand Down
14 changes: 8 additions & 6 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub mod pallet {
///
/// ## Events
/// The `Registered` event is emitted in case of success.
#[pallet::weight(T::WeightInfo::register())]
#[pallet::weight(<T as Config>::WeightInfo::register())]
pub fn register(
origin: OriginFor<T>,
id: ParaId,
Expand All @@ -231,7 +231,7 @@ pub mod pallet {
///
/// The deposit taken can be specified for this registration. Any `ParaId`
/// can be registered, including sub-1000 IDs which are System Parachains.
#[pallet::weight(T::WeightInfo::force_register())]
#[pallet::weight(<T as Config>::WeightInfo::force_register())]
pub fn force_register(
origin: OriginFor<T>,
who: T::AccountId,
Expand All @@ -247,7 +247,7 @@ pub mod pallet {
/// Deregister a Para Id, freeing all data and returning any deposit.
///
/// The caller must be Root, the `para` owner, or the `para` itself. The para must be a parathread.
#[pallet::weight(T::WeightInfo::deregister())]
#[pallet::weight(<T as Config>::WeightInfo::deregister())]
pub fn deregister(origin: OriginFor<T>, id: ParaId) -> DispatchResult {
Self::ensure_root_para_or_owner(origin, id)?;
Self::do_deregister(id)
Expand All @@ -264,7 +264,7 @@ pub mod pallet {
/// `ParaId` to be a long-term identifier of a notional "parachain". However, their
/// scheduling info (i.e. whether they're a parathread or parachain), auction information
/// and the auction deposit are switched.
#[pallet::weight(T::WeightInfo::swap())]
#[pallet::weight(<T as Config>::WeightInfo::swap())]
pub fn swap(origin: OriginFor<T>, id: ParaId, other: ParaId) -> DispatchResult {
Self::ensure_root_para_or_owner(origin, id)?;

Expand Down Expand Up @@ -325,7 +325,7 @@ pub mod pallet {
///
/// ## Events
/// The `Reserved` event is emitted in case of success, which provides the ID reserved for use.
#[pallet::weight(T::WeightInfo::reserve())]
#[pallet::weight(<T as Config>::WeightInfo::reserve())]
pub fn reserve(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let id = NextFreeParaId::<T>::get().max(LOWEST_PUBLIC_ID);
Expand Down Expand Up @@ -659,7 +659,9 @@ mod tests {
type Event = Event;
}

impl configuration::Config for Test {}
impl configuration::Config for Test {
type WeightInfo = configuration::weights::WeightInfo<Test>;
}

parameter_types! {
pub const ParaDeposit: Balance = 10;
Expand Down
6 changes: 5 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,9 @@ impl pallet_proxy::Config for Runtime {

impl parachains_origin::Config for Runtime {}

impl parachains_configuration::Config for Runtime {}
impl parachains_configuration::Config for Runtime {
type WeightInfo = weights::runtime_parachains_configuration::WeightInfo<Runtime>;
}

impl parachains_shared::Config for Runtime {}

Expand Down Expand Up @@ -2000,6 +2002,7 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, runtime_common::claims, Claims);
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);
// Substrate
list_benchmark!(list, extra, pallet_bags_list, BagsList);
list_benchmark!(list, extra, pallet_balances, Balances);
Expand Down Expand Up @@ -2074,6 +2077,7 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, runtime_common::claims, Claims);
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);
// Substrate
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_bags_list, BagsList);
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ pub mod runtime_common_claims;
pub mod runtime_common_crowdloan;
pub mod runtime_common_paras_registrar;
pub mod runtime_common_slots;
pub mod runtime_parachains_configuration;
91 changes: 91 additions & 0 deletions runtime/kusama/src/weights/runtime_parachains_configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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 <http://www.gnu.org/licenses/>.
//! Autogenerated weights for `runtime_parachains::configuration`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-09-17, 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::configuration
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/kusama/src/weights/runtime_parachains_configuration.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::configuration`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for WeightInfo<T> {
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_block_number() -> Weight {
(12_378_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_u32() -> Weight {
(12_384_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_option_u32() -> Weight {
(12_746_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_weight() -> Weight {
(12_563_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Benchmark Override (r:0 w:0)
fn set_hrmp_open_request_ttl() -> Weight {
(2_000_000_000_000 as Weight)
}
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_balance() -> Weight {
(12_644_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
4 changes: 2 additions & 2 deletions runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pallet-authority-discovery = { git = "https://github.com/paritytech/substrate",
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

xcm = { package = "xcm", path = "../../xcm", default-features = false }
xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", default-features = false }
Expand Down
Loading

0 comments on commit 4c54766

Please sign in to comment.