Add session weight (#477)

* session weight

* decouple session benchmarking and collator selection

* removed mock

* licensing

* benchmarking script

* set benchmarking into runtime

* Update scripts/benchmarks.sh

* real weights

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
JesseAbram
2021-06-08 13:24:19 +02:00
committed by GitHub
parent d935b81e70
commit a7b44a9eff
18 changed files with 312 additions and 7 deletions
Generated
+23 -3
View File
@@ -3874,7 +3874,7 @@ dependencies = [
"pallet-recovery",
"pallet-scheduler",
"pallet-session",
"pallet-session-benchmarking",
"pallet-session-benchmarking 3.0.0 (git+https://github.com/paritytech/substrate?branch=master)",
"pallet-society",
"pallet-staking",
"pallet-staking-reward-fn",
@@ -5675,6 +5675,23 @@ dependencies = [
"sp-trie",
]
[[package]]
name = "pallet-session-benchmarking"
version = "3.0.0"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"pallet-session",
"parity-scale-codec",
"serde",
"sp-core",
"sp-io",
"sp-runtime",
"sp-staking",
"sp-std",
]
[[package]]
name = "pallet-session-benchmarking"
version = "3.0.0"
@@ -7134,7 +7151,7 @@ dependencies = [
"pallet-randomness-collective-flip",
"pallet-scheduler",
"pallet-session",
"pallet-session-benchmarking",
"pallet-session-benchmarking 3.0.0 (git+https://github.com/paritytech/substrate?branch=master)",
"pallet-staking",
"pallet-staking-reward-curve",
"pallet-timestamp",
@@ -10637,6 +10654,7 @@ dependencies = [
"pallet-proxy",
"pallet-randomness-collective-flip",
"pallet-session",
"pallet-session-benchmarking 3.0.0",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
@@ -10724,6 +10742,7 @@ dependencies = [
"pallet-proxy",
"pallet-randomness-collective-flip",
"pallet-session",
"pallet-session-benchmarking 3.0.0",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
@@ -12449,7 +12468,7 @@ dependencies = [
"pallet-recovery",
"pallet-scheduler",
"pallet-session",
"pallet-session-benchmarking",
"pallet-session-benchmarking 3.0.0 (git+https://github.com/paritytech/substrate?branch=master)",
"pallet-society",
"pallet-staking",
"pallet-staking-reward-curve",
@@ -12524,6 +12543,7 @@ dependencies = [
"pallet-proxy",
"pallet-randomness-collective-flip",
"pallet-session",
"pallet-session-benchmarking 3.0.0",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
+1
View File
@@ -11,6 +11,7 @@ members = [
"pallets/collator-selection",
"pallets/dmp-queue",
"pallets/parachain-system",
"pallets/session-benchmarking",
"pallets/xcm",
"pallets/xcmp-queue",
"primitives/core",
+44
View File
@@ -0,0 +1,44 @@
[package]
name = "pallet-session-benchmarking"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/cumulus/"
description = "FRAME sessions pallet benchmarking for statemint"
readme = "README.md"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
sp-staking = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
pallet-session = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
[dev-dependencies]
serde = { version = "1.0.119" }
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
sp-core = { git = 'https://github.com/paritytech/substrate', branch = "master", version = '3.0.0' }
[features]
default = ["std"]
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'frame-system/runtime-benchmarks',
]
std = [
"sp-std/std",
"sp-runtime/std",
"frame-system/std",
"frame-benchmarking/std",
"frame-support/std",
"pallet-session/std",
]
+3
View File
@@ -0,0 +1,3 @@
Benchmarks for the Session Pallet.
License: Apache-2.0
+51
View File
@@ -0,0 +1,51 @@
// Copyright (C) 2021 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.
//! Benchmarking setup for pallet-session
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg(feature = "runtime-benchmarks")]
use sp_std::prelude::*;
use sp_std::vec;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_system::{RawOrigin};
use pallet_session::*;
pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
pub trait Config: pallet_session::Config {}
benchmarks! {
set_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(caller), keys, proof)
purge_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
let _t = pallet_session::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof);
}: _(RawOrigin::Signed(caller))
}
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Test,
extra = false,
);
@@ -41,6 +41,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", default-fea
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session-benchmarking = {path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0"}
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -92,6 +93,7 @@ runtime-benchmarks = [
'pallet-balances/runtime-benchmarks',
'pallet-multisig/runtime-benchmarks',
'pallet-proxy/runtime-benchmarks',
'pallet-session-benchmarking/runtime-benchmarks',
'pallet-uniques/runtime-benchmarks',
'pallet-utility/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
@@ -630,7 +630,7 @@ impl pallet_session::Config for Runtime {
type SessionHandler = <opaque::SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
impl pallet_aura::Config for Runtime {
@@ -858,8 +858,11 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use pallet_session_benchmarking::Pallet as SessionBench;
use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}
impl pallet_session_benchmarking::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
@@ -882,6 +885,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, pallet_uniques, Uniques);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
@@ -3,6 +3,7 @@ pub mod pallet_balances;
pub mod pallet_multisig;
pub mod pallet_collator_selection;
pub mod pallet_proxy;
pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_uniques;
pub mod pallet_utility;
@@ -0,0 +1,41 @@
//! Autogenerated weights for pallet_session
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-06-08, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 128
// Executed Command:
// ./target/release/polkadot-collator
// benchmark
// --chain=statemine-dev
// --execution=wasm
// --wasm-execution=compiled
// --pallet=pallet_session
// --extrinsic=*
// --steps=50
// --repeat=20
// --raw
// --output=./polkadot-parachains/statemine-runtime/src/weights
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;
/// Weight functions for pallet_session.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_session::WeightInfo for WeightInfo<T> {
fn set_keys() -> Weight {
(25_201_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn purge_keys() -> Weight {
(17_510_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
}
@@ -41,6 +41,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", default-fea
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session-benchmarking = { path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -91,6 +92,7 @@ runtime-benchmarks = [
'pallet-balances/runtime-benchmarks',
'pallet-multisig/runtime-benchmarks',
'pallet-proxy/runtime-benchmarks',
'pallet-session-benchmarking/runtime-benchmarks',
'pallet-utility/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-xcm/runtime-benchmarks',
@@ -573,7 +573,7 @@ impl pallet_session::Config for Runtime {
type SessionHandler = <opaque::SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
impl pallet_aura::Config for Runtime {
@@ -791,9 +791,10 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use pallet_session_benchmarking::Pallet as SessionBench;
use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}
impl pallet_session_benchmarking::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
@@ -815,6 +816,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
@@ -3,5 +3,6 @@ pub mod pallet_balances;
pub mod pallet_multisig;
pub mod pallet_collator_selection;
pub mod pallet_proxy;
pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_utility;
@@ -0,0 +1,41 @@
//! Autogenerated weights for pallet_session
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-06-08, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 128
// Executed Command:
// ./target/release/polkadot-collator
// benchmark
// --chain=statemint-dev
// --execution=wasm
// --wasm-execution=compiled
// --pallet=pallet_session
// --extrinsic=*
// --steps=50
// --repeat=20
// --raw
// --output=./polkadot-parachains/statemint-runtime/src/weights
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;
/// Weight functions for pallet_session.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_session::WeightInfo for WeightInfo<T> {
fn set_keys() -> Weight {
(25_040_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn purge_keys() -> Weight {
(17_551_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
}
@@ -41,6 +41,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", default-fea
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session-benchmarking = {path = "../../pallets/session-benchmarking", default-features = false, version = "3.0.0"}
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -91,6 +92,7 @@ runtime-benchmarks = [
'pallet-balances/runtime-benchmarks',
'pallet-multisig/runtime-benchmarks',
'pallet-proxy/runtime-benchmarks',
'pallet-session-benchmarking/runtime-benchmarks',
'pallet-utility/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-xcm/runtime-benchmarks',
@@ -570,7 +570,7 @@ impl pallet_session::Config for Runtime {
type SessionHandler = <opaque::SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}
impl pallet_aura::Config for Runtime {
@@ -789,8 +789,11 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use pallet_session_benchmarking::Pallet as SessionBench;
use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}
impl pallet_session_benchmarking::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
@@ -813,6 +816,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
@@ -3,5 +3,6 @@ pub mod pallet_balances;
pub mod pallet_multisig;
pub mod pallet_collator_selection;
pub mod pallet_proxy;
pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_utility;
@@ -0,0 +1,41 @@
//! Autogenerated weights for pallet_session
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-06-08, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 128
// Executed Command:
// ./target/release/polkadot-collator
// benchmark
// --chain=statemint-dev
// --execution=wasm
// --wasm-execution=compiled
// --pallet=pallet_session
// --extrinsic=*
// --steps=50
// --repeat=20
// --raw
// --output=./polkadot-parachains/statemint-runtime/src/weights
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;
/// Weight functions for pallet_session.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_session::WeightInfo for WeightInfo<T> {
fn set_keys() -> Weight {
(25_040_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn purge_keys() -> Weight {
(17_551_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
}
+44
View File
@@ -0,0 +1,44 @@
#!/bin/bash
steps=50
repeat=20
statemineOutput=./polkadot-parachains/statemine-runtime/src/weights
statemintOutput=./polkadot-parachains/statemint-runtime/src/weights
statemineChain=statemine-dev
statemintChain=statemint-dev
pallets=(
pallet_assets
pallet_balances
pallet_collator_selection
pallet_multisig
pallet_proxy
pallet_session
pallet_timestamp
pallet_utility
)
for p in ${pallets[@]}
do
./target/release/polkadot-collator benchmark \
--chain=$statemineChain \
--execution=wasm \
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
--steps=$steps \
--repeat=$repeat \
--raw \
--output=$statemineOutput
./target/release/polkadot-collator benchmark \
--chain=$statemintChain \
--execution=wasm \
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
--steps=$steps \
--repeat=$repeat \
--raw \
--output=$statemintOutput
done