This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add benchmarking for parachain runtime initializer pallet #3913
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b65c5e2
Add benchmarking for parachain runtime initializer pallet
KiChjang b425d22
Fix default impl for initializer pallet WeightInfo
KiChjang c85f1cf
Merge branch 'master' of https://github.com/paritytech/polkadot into …
808b1d3
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
1987b3b
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
694dfa4
Use real weights and use max_block as default weight
KiChjang bf724d8
Add variable for digest vec length for initializer benchmark
KiChjang 196ccf3
Fix compilation errors
KiChjang e2cabdc
Merge remote-tracking branch 'origin' into kckyeung/parachains-initia…
KiChjang ec78041
Add WeightInfo to parachains_initializer config in polkadot runtime
KiChjang a5134ee
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
b74c1bb
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
acdb91a
Appease spellchecker
KiChjang 48d549e
Use kusama weights in polkadot runtime for parachain initializer pallet
KiChjang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
runtime/kusama/src/weights/runtime_parachains_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
//! 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<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> runtime_parachains::initializer::WeightInfo for WeightInfo<T> { | ||
// 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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
|
||
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 { | ||
<frame_system::Pallet<T>>::deposit_log(ConsensusLog::ForceApprove(d).into()); | ||
} | ||
}: _(RawOrigin::Root, d + 1) | ||
verify { | ||
assert_eq!( | ||
<frame_system::Pallet<T>>::digest().logs.last().unwrap(), | ||
&<DigestItemOf<T>>::from(ConsensusLog::ForceApprove(d + 1)), | ||
); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::mock::new_test_ext(Default::default()), | ||
crate::mock::Test | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
runtime/polkadot/src/weights/runtime_parachains_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
//! 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<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> runtime_parachains::initializer::WeightInfo for WeightInfo<T> { | ||
// 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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Runtime>; | ||
type WeightInfo = weights::runtime_parachains_configuration::WeightInfo<Runtime>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think #3914 should take of this |
||
} | ||
|
||
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<Runtime>; | ||
type ForceOrigin = EnsureRoot<AccountId>; | ||
type WeightInfo = weights::runtime_parachains_initializer::WeightInfo<Runtime>; | ||
} | ||
|
||
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
runtime/westend/src/weights/runtime_parachains_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
//! 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<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> runtime_parachains::initializer::WeightInfo for WeightInfo<T> { | ||
// 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)) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially I think the only storage op here is an
<Digest<T>>::append(item);
- without looking at the code I am guessing it has to decode the vec, push the item, and then encode it (But maybe it is more optimized?). I am wondering if for something like this we should benchmark with a large vec to assume worst case?My naive guess though is that practically we will never have enough logs for the append op to be that expensive + this is from a force origin so it doesn't look like a significant DoS vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through the code, and while it doesn't decode the entire vec (it only decodes the first 4 bytes to get the encoded length), it does however copy the entire vec to a new one whenever the new encoded length is different from the previous (which is pretty much always).
I'll most likely need to add in a variable and see how the complexity varies with the digest vec length.