diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 0de78464bd..9c2c3beb77 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -403,7 +403,7 @@ impl pallet_session::Trait for Runtime { type SessionHandler = ::KeyTypeIdProviders; type Keys = SessionKeys; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; - type WeightInfo = (); + type WeightInfo = weights::pallet_session::WeightInfo; } impl pallet_session::historical::Trait for Runtime { @@ -762,7 +762,6 @@ impl pallet_offences::Trait for Runtime { type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; - type WeightInfo = (); } impl pallet_authority_discovery::Trait for Runtime {} diff --git a/substrate/bin/node/runtime/src/weights/mod.rs b/substrate/bin/node/runtime/src/weights/mod.rs index 668b9462a7..e2e65595d3 100644 --- a/substrate/bin/node/runtime/src/weights/mod.rs +++ b/substrate/bin/node/runtime/src/weights/mod.rs @@ -25,6 +25,7 @@ pub mod pallet_indices; pub mod pallet_im_online; pub mod pallet_proxy; pub mod pallet_scheduler; +pub mod pallet_session; pub mod pallet_staking; pub mod pallet_timestamp; pub mod pallet_utility; diff --git a/substrate/bin/node/runtime/src/weights/pallet_session.rs b/substrate/bin/node/runtime/src/weights/pallet_session.rs new file mode 100644 index 0000000000..3973936242 --- /dev/null +++ b/substrate/bin/node/runtime/src/weights/pallet_session.rs @@ -0,0 +1,37 @@ +// This file is part of Substrate. + +// Copyright (C) 2017-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. + +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +pub struct WeightInfo; +impl pallet_session::WeightInfo for WeightInfo { + fn set_keys() -> Weight { + (88_411_000 as Weight) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn purge_keys() -> Weight { + (51_843_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } +} diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index 34e9ff113d..925e301dea 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -230,7 +230,6 @@ impl pallet_offences::Trait for Test { type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; - type WeightInfo = (); } impl Trait for Test { diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index 81026c7562..7358d50e26 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -245,7 +245,6 @@ impl pallet_offences::Trait for Test { type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; - type WeightInfo = (); } impl Trait for Test { diff --git a/substrate/frame/offences/benchmarking/src/mock.rs b/substrate/frame/offences/benchmarking/src/mock.rs index 12a14e90b0..b0071b8800 100644 --- a/substrate/frame/offences/benchmarking/src/mock.rs +++ b/substrate/frame/offences/benchmarking/src/mock.rs @@ -204,7 +204,6 @@ impl pallet_offences::Trait for Test { type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; - type WeightInfo = (); } impl frame_system::offchain::SendTransactionTypes for Test where Call: From { diff --git a/substrate/frame/offences/src/lib.rs b/substrate/frame/offences/src/lib.rs index bf072f4a40..bec1981301 100644 --- a/substrate/frame/offences/src/lib.rs +++ b/substrate/frame/offences/src/lib.rs @@ -77,8 +77,6 @@ pub trait Trait: frame_system::Trait { /// `on_initialize`. /// Note it's going to be exceeded before we stop adding to it, so it has to be set conservatively. type WeightSoftLimit: Get; - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; } decl_storage! { @@ -111,7 +109,7 @@ decl_event!( pub enum Event { /// There is an offence reported of the given `kind` happened at the `session_index` and /// (kind-specific) time slot. This event is not deposited for duplicate slashes. last - /// element indicates of the offence was applied (true) or queued (false) + /// element indicates of the offence was applied (true) or queued (false) /// \[kind, timeslot, applied\]. Offence(Kind, OpaqueTimeSlot, bool), } diff --git a/substrate/frame/offences/src/mock.rs b/substrate/frame/offences/src/mock.rs index f981e70835..5e51e8b6c4 100644 --- a/substrate/frame/offences/src/mock.rs +++ b/substrate/frame/offences/src/mock.rs @@ -132,7 +132,6 @@ impl Trait for Runtime { type IdentificationTuple = u64; type OnOffenceHandler = OnOffenceHandler; type WeightSoftLimit = OffencesWeightSoftLimit; - type WeightInfo = (); } mod offences { diff --git a/substrate/frame/session/benchmarking/src/lib.rs b/substrate/frame/session/benchmarking/src/lib.rs index ee66223fc0..6fcdeaafc9 100644 --- a/substrate/frame/session/benchmarking/src/lib.rs +++ b/substrate/frame/session/benchmarking/src/lib.rs @@ -28,7 +28,7 @@ use sp_std::vec; use frame_benchmarking::benchmarks; use frame_support::{ codec::Decode, - storage::StorageValue, + storage::{StorageValue, StorageMap}, traits::{KeyOwnerProofSystem, OnInitialize}, }; use frame_system::RawOrigin; @@ -54,7 +54,7 @@ benchmarks! { _ { } set_keys { - let n in 1 .. MAX_NOMINATIONS as u32; + let n = MAX_NOMINATIONS as u32; let v_stash = create_validator_with_nominators::( n, MAX_NOMINATIONS as u32, @@ -64,17 +64,24 @@ benchmarks! { let v_controller = pallet_staking::Module::::bonded(&v_stash).ok_or("not stash")?; let keys = T::Keys::default(); let proof: Vec = vec![0,1,2,3]; + // Whitelist controller account from further DB operations. + let v_controller_key = frame_system::Account::::hashed_key_for(&v_controller); + frame_benchmarking::benchmarking::add_to_whitelist(v_controller_key.into()); }: _(RawOrigin::Signed(v_controller), keys, proof) purge_keys { - let n in 1 .. MAX_NOMINATIONS as u32; + let n = MAX_NOMINATIONS as u32; let v_stash = create_validator_with_nominators::(n, MAX_NOMINATIONS as u32, false, RewardDestination::Staked)?; let v_controller = pallet_staking::Module::::bonded(&v_stash).ok_or("not stash")?; let keys = T::Keys::default(); let proof: Vec = vec![0,1,2,3]; Session::::set_keys(RawOrigin::Signed(v_controller.clone()).into(), keys, proof)?; + // Whitelist controller account from further DB operations. + let v_controller_key = frame_system::Account::::hashed_key_for(&v_controller); + frame_benchmarking::benchmarking::add_to_whitelist(v_controller_key.into()); }: _(RawOrigin::Signed(v_controller)) + #[extra] check_membership_proof_current_session { let n in 2 .. MAX_VALIDATORS as u32; @@ -87,6 +94,7 @@ benchmarks! { assert!(Historical::::check_proof(key, key_owner_proof2).is_some()); } + #[extra] check_membership_proof_historical_session { let n in 2 .. MAX_VALIDATORS as u32; diff --git a/substrate/frame/session/src/default_weights.rs b/substrate/frame/session/src/default_weights.rs new file mode 100644 index 0000000000..f3082981c7 --- /dev/null +++ b/substrate/frame/session/src/default_weights.rs @@ -0,0 +1,36 @@ +// This file is part of Substrate. + +// Copyright (C) 2017-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. + +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +impl crate::WeightInfo for () { + fn set_keys() -> Weight { + (88_411_000 as Weight) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn purge_keys() -> Weight { + (51_843_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } +} diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs index ede88b26f9..1d81f38bdf 100644 --- a/substrate/frame/session/src/lib.rs +++ b/substrate/frame/session/src/lib.rs @@ -123,6 +123,8 @@ mod tests; #[cfg(feature = "historical")] pub mod historical; +mod default_weights; + /// Decides whether the session should be ended. pub trait ShouldEndSession { /// Return `true` if the session should be ended. @@ -352,13 +354,8 @@ impl ValidatorRegistration for Module { } pub trait WeightInfo { - fn set_keys(n: u32, ) -> Weight; - fn purge_keys(n: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn set_keys(_n: u32, ) -> Weight { 1_000_000_000 } - fn purge_keys(_n: u32, ) -> Weight { 1_000_000_000 } + fn set_keys() -> Weight; + fn purge_keys() -> Weight; } pub trait Trait: frame_system::Trait { @@ -524,9 +521,7 @@ decl_module! { /// - DbReads per key id: `KeyOwner` /// - DbWrites per key id: `KeyOwner` /// # - #[weight = 200_000_000 - + T::DbWeight::get().reads(2 + T::Keys::key_ids().len() as Weight) - + T::DbWeight::get().writes(1 + T::Keys::key_ids().len() as Weight)] + #[weight = T::WeightInfo::set_keys()] pub fn set_keys(origin, keys: T::Keys, proof: Vec) -> dispatch::DispatchResult { let who = ensure_signed(origin)?; @@ -549,8 +544,7 @@ decl_module! { /// - DbWrites: `NextKeys`, `origin account` /// - DbWrites per key id: `KeyOwnder` /// # - #[weight = 120_000_000 - + T::DbWeight::get().reads_writes(2, 1 + T::Keys::key_ids().len() as Weight)] + #[weight = T::WeightInfo::purge_keys()] pub fn purge_keys(origin) { let who = ensure_signed(origin)?; Self::do_purge_keys(&who)?;