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

Add benchmarking to rococo; Remove weights from runtime_parachains #3914

Merged
18 commits merged into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ impl pallet_balances::Config for Test {
}

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

impl shared::Config for Test {}

impl paras::Config for Test {
type Origin = Origin;
type Event = Event;
type WeightInfo = paras::weights::WeightInfo<Test>;
type WeightInfo = paras::TestWeightInfo;
}

parameter_types! {
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,11 @@ mod tests {
impl paras::Config for Test {
type Origin = Origin;
type Event = Event;
type WeightInfo = paras::weights::WeightInfo<Test>;
type WeightInfo = paras::TestWeightInfo;
}

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

parameter_types! {
Expand Down
23 changes: 22 additions & 1 deletion runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sp_std::prelude::*;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;

pub use pallet::*;

Expand Down Expand Up @@ -278,6 +277,28 @@ pub trait WeightInfo {
fn set_hrmp_open_request_ttl() -> Weight;
}

pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn set_config_with_block_number() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn set_config_with_u32() -> Weight {
frame_system::limits::BlockWeights::default().max_block
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
}
fn set_config_with_option_u32() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn set_config_with_weight() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn set_config_with_balance() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn set_hrmp_open_request_ttl() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ impl crate::initializer::Config for Test {
}

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

impl crate::shared::Config for Test {}

impl crate::paras::Config for Test {
type Origin = Origin;
type Event = Event;
type WeightInfo = crate::paras::weights::WeightInfo<Test>;
type WeightInfo = crate::paras::TestWeightInfo;
}

impl crate::dmp::Config for Test {}
Expand Down
20 changes: 19 additions & 1 deletion runtime/parachains/src/paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub use crate::Origin as ParachainOrigin;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;

pub use pallet::*;

Expand Down Expand Up @@ -279,6 +278,25 @@ pub trait WeightInfo {
fn force_queue_action() -> Weight;
}

pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn force_set_current_code(_c: u32) -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn force_set_current_head(_s: u32) -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn force_schedule_code_upgrade(_c: u32) -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn force_note_new_head(_s: u32) -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
fn force_queue_action() -> Weight {
frame_system::limits::BlockWeights::default().max_block
}
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down
5 changes: 5 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", defa
xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default-features = false }
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
hex-literal = { version = "0.3.3", optional = true }

# Bridge Dependencies
bp-messages = { path = "../../bridges/primitives/messages", default-features = false }
bp-rococo = { path = "../../bridges/primitives/chain-rococo", default-features = false }
Expand Down Expand Up @@ -169,6 +172,8 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"frame-benchmarking",
"hex-literal"
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down
55 changes: 53 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ use xcm_executor::XcmExecutor;
/// Constant values used within the runtime.
pub mod constants;
mod validator_manager;
mod weights;

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -570,7 +571,7 @@ impl pallet_authorship::Config for Runtime {
impl parachains_origin::Config for Runtime {}

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

impl parachains_shared::Config for Runtime {}
Expand All @@ -591,7 +592,7 @@ impl parachains_inclusion::Config for Runtime {
impl parachains_paras::Config for Runtime {
type Origin = Origin;
type Event = Event;
type WeightInfo = parachains_paras::weights::WeightInfo<Runtime>;
type WeightInfo = weights::runtime_parachains_paras::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1559,4 +1560,54 @@ sp_api::impl_runtime_apis! {
TransactionPayment::query_fee_details(uxt, len)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, runtime_parachains::configuration, Configuration);
list_benchmark!(list, extra, runtime_parachains::paras, Paras);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig,
) -> Result<
Vec<frame_benchmarking::BenchmarkBatch>,
sp_runtime::RuntimeString,
> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};

let mut batches = Vec::<BenchmarkBatch>::new();
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
// Execution Phase
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
// Event Count
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
];
let params = (&config, &whitelist);

add_benchmark!(params, batches, runtime_parachains::configuration, Configuration);
add_benchmark!(params, batches, runtime_parachains::paras, Paras);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
}
19 changes: 19 additions & 0 deletions runtime/rococo/src/weights/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! A list of the different weight modules for our runtime.

pub mod runtime_parachains_configuration;
pub mod runtime_parachains_paras;
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
// 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("westend-dev"), DB CACHE: 128
//! DATE: 2021-09-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("rococo-dev"), DB CACHE: 128

// Executed Command:
// ./target/release/polkadot
// target/release/polkadot
// benchmark
// --chain
// westend-dev
// --chain=rococo-dev
// --steps=50
// --repeat=20
// --pallet=runtime_parachains::configuration
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --pallet
// runtime_parachains::configuration
// --steps
// 50
// --repeat
// 20
// --raw
// --extrinsic
// *
// --output
// runtime/parachains/src/configuration/weights.rs
// --heap-pages=4096
// --output=./runtime/rococo/src/weights/runtime_parachains_configuration.rs
// --header=./file_header.txt


#![cfg_attr(rustfmt, rustfmt_skip)]
Expand All @@ -34,36 +43,36 @@ use sp_std::marker::PhantomData;

/// Weight functions for `runtime_parachains::configuration`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> super::WeightInfo for WeightInfo<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 {
(16_730_000 as Weight)
(13_098_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 {
(16_592_000 as Weight)
(13_216_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 {
(16_419_000 as Weight)
(13_080_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 {
(16_732_000 as Weight)
(13_178_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
Expand All @@ -75,7 +84,7 @@ impl<T: frame_system::Config> super::WeightInfo for WeightInfo<T> {
// Storage: Configuration PendingConfig (r:1 w:1)
// Storage: Configuration ActiveConfig (r:1 w:0)
fn set_config_with_balance() -> Weight {
(16_752_000 as Weight)
(13_080_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
Expand Down
Loading