From 3def15a9403d4c8d8e0e970266de3f38814ab465 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 21 Sep 2020 13:03:25 +0200 Subject: [PATCH] Companion for https://github.com/paritytech/substrate/pull/7161 --- runtime/kusama/src/lib.rs | 2 +- runtime/kusama/src/weights/mod.rs | 1 + .../src/weights/pallet_elections_phragmen.rs | 88 +++++++++++++++++++ runtime/polkadot/src/lib.rs | 2 +- runtime/polkadot/src/weights/mod.rs | 1 + .../src/weights/pallet_elections_phragmen.rs | 88 +++++++++++++++++++ runtime/polkadot/tests/weights.rs | 33 +++++-- 7 files changed, 206 insertions(+), 9 deletions(-) create mode 100644 runtime/kusama/src/weights/pallet_elections_phragmen.rs create mode 100644 runtime/polkadot/src/weights/pallet_elections_phragmen.rs diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index cecc7200cee8..d4d97ff5be2e 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -457,7 +457,7 @@ impl pallet_elections_phragmen::Trait for Runtime { type DesiredRunnersUp = DesiredRunnersUp; type TermDuration = TermDuration; type ModuleId = ElectionsPhragmenModuleId; - type WeightInfo = (); + type WeightInfo = weights::pallet_elections_phragmen::WeightInfo; } parameter_types! { diff --git a/runtime/kusama/src/weights/mod.rs b/runtime/kusama/src/weights/mod.rs index 9aa57bd71fd3..3818a53ccd28 100644 --- a/runtime/kusama/src/weights/mod.rs +++ b/runtime/kusama/src/weights/mod.rs @@ -27,3 +27,4 @@ pub mod pallet_timestamp; pub mod pallet_treasury; pub mod pallet_utility; pub mod pallet_vesting; +pub mod pallet_elections_phragmen; diff --git a/runtime/kusama/src/weights/pallet_elections_phragmen.rs b/runtime/kusama/src/weights/pallet_elections_phragmen.rs new file mode 100644 index 000000000000..2071cc28eca5 --- /dev/null +++ b/runtime/kusama/src/weights/pallet_elections_phragmen.rs @@ -0,0 +1,88 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-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_elections_phragmen::WeightInfo for WeightInfo { + fn vote(v: u32, ) -> Weight { + (35890000 as Weight) + .saturating_add((168000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn vote_update(v: u32, ) -> Weight { + (23406000 as Weight) + .saturating_add((312000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn remove_voter() -> Weight { + (35814000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn report_defunct_voter_correct(c: u32, v: u32, ) -> Weight { + (0 as Weight) + .saturating_add((1917000 as Weight).saturating_mul(c as Weight)) + .saturating_add((28128000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn report_defunct_voter_incorrect(c: u32, v: u32, ) -> Weight { + (0 as Weight) + .saturating_add((1946000 as Weight).saturating_mul(c as Weight)) + .saturating_add((28514000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + } + fn submit_candidacy(c: u32, ) -> Weight { + (41826000 as Weight) + .saturating_add((235000 as Weight).saturating_mul(c as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn renounce_candidacy_candidate(c: u32, ) -> Weight { + (27830000 as Weight) + .saturating_add((181000 as Weight).saturating_mul(c as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn renounce_candidacy_members() -> Weight { + (41689000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(4 as Weight)) + } + fn renounce_candidacy_runners_up() -> Weight { + (27689000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn remove_member_with_replacement() -> Weight { + (41510000 as Weight) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn remove_member_wrong_refund() -> Weight { + (5159000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + } +} diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 619dbce285f1..b05d94c10ead 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -513,7 +513,7 @@ impl pallet_elections_phragmen::Trait for Runtime { type DesiredMembers = DesiredMembers; type DesiredRunnersUp = DesiredRunnersUp; type TermDuration = TermDuration; - type WeightInfo = (); + type WeightInfo = weights::pallet_elections_phragmen::WeightInfo; } parameter_types! { diff --git a/runtime/polkadot/src/weights/mod.rs b/runtime/polkadot/src/weights/mod.rs index 9aa57bd71fd3..3818a53ccd28 100644 --- a/runtime/polkadot/src/weights/mod.rs +++ b/runtime/polkadot/src/weights/mod.rs @@ -27,3 +27,4 @@ pub mod pallet_timestamp; pub mod pallet_treasury; pub mod pallet_utility; pub mod pallet_vesting; +pub mod pallet_elections_phragmen; diff --git a/runtime/polkadot/src/weights/pallet_elections_phragmen.rs b/runtime/polkadot/src/weights/pallet_elections_phragmen.rs new file mode 100644 index 000000000000..2071cc28eca5 --- /dev/null +++ b/runtime/polkadot/src/weights/pallet_elections_phragmen.rs @@ -0,0 +1,88 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-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_elections_phragmen::WeightInfo for WeightInfo { + fn vote(v: u32, ) -> Weight { + (35890000 as Weight) + .saturating_add((168000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn vote_update(v: u32, ) -> Weight { + (23406000 as Weight) + .saturating_add((312000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn remove_voter() -> Weight { + (35814000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn report_defunct_voter_correct(c: u32, v: u32, ) -> Weight { + (0 as Weight) + .saturating_add((1917000 as Weight).saturating_mul(c as Weight)) + .saturating_add((28128000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn report_defunct_voter_incorrect(c: u32, v: u32, ) -> Weight { + (0 as Weight) + .saturating_add((1946000 as Weight).saturating_mul(c as Weight)) + .saturating_add((28514000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + } + fn submit_candidacy(c: u32, ) -> Weight { + (41826000 as Weight) + .saturating_add((235000 as Weight).saturating_mul(c as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn renounce_candidacy_candidate(c: u32, ) -> Weight { + (27830000 as Weight) + .saturating_add((181000 as Weight).saturating_mul(c as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn renounce_candidacy_members() -> Weight { + (41689000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(4 as Weight)) + } + fn renounce_candidacy_runners_up() -> Weight { + (27689000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn remove_member_with_replacement() -> Weight { + (41510000 as Weight) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn remove_member_wrong_refund() -> Weight { + (5159000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + } +} diff --git a/runtime/polkadot/tests/weights.rs b/runtime/polkadot/tests/weights.rs index be9fd79ad4e4..88865ab29bbd 100644 --- a/runtime/polkadot/tests/weights.rs +++ b/runtime/polkadot/tests/weights.rs @@ -84,24 +84,43 @@ fn weight_of_session_purge_keys_is_correct() { #[test] fn weight_of_phragmen_vote_is_correct() { - // #[weight = 100_000_000] - let expected_weight = 350_000_000; - let weight = PhragmenCall::vote::(Default::default(), Default::default()).get_dispatch_info().weight; + // (35890000 as Weight) + // .saturating_add((168000 as Weight).saturating_mul(v as Weight)) + // .saturating_add(DbWeight::get().reads(5 as Weight)) + // .saturating_add(DbWeight::get().writes(2 as Weight)) + let expected_weight = + 35_890_000 + + (DbWeight::get().read * 5) + (DbWeight::get().write * 2) + + 168000 * 2; + let weight = PhragmenCall::vote::( + vec![Default::default(), Default::default()], + Default::default(), + ).get_dispatch_info().weight; assert_eq!(weight, expected_weight); } #[test] fn weight_of_phragmen_submit_candidacy_is_correct() { - let expected_weight = WEIGHT_PER_MICROS * 35 + 1 * 375 * WEIGHT_PER_NANOS + DbWeight::get().reads_writes(4, 1); - let weight = PhragmenCall::submit_candidacy::(1).get_dispatch_info().weight; + // (41826000 as Weight) + // .saturating_add((235000 as Weight).saturating_mul(c as Weight)) + // .saturating_add(DbWeight::get().reads(3 as Weight)) + // .saturating_add(DbWeight::get().writes(1 as Weight)) + let expected_weight = + 41826000 + + (235000 * 3) + + (DbWeight::get().read * 3) + (DbWeight::get().write * 1); + let weight = PhragmenCall::submit_candidacy::(3).get_dispatch_info().weight; assert_eq!(weight, expected_weight); } #[test] -fn weight_of_phragmen_renounce_candidacy_is_correct() { - let expected_weight = 46 * WEIGHT_PER_MICROS + DbWeight::get().reads_writes(2, 2); +fn weight_of_phragmen_renounce_candidacy_member_is_correct() { + // (41689000 as Weight) + // .saturating_add(DbWeight::get().reads(3 as Weight)) + // .saturating_add(DbWeight::get().writes(4 as Weight)) + let expected_weight = 41689000 + (DbWeight::get().read * 3) + (DbWeight::get().write * 4); let weight = PhragmenCall::renounce_candidacy::(pallet_elections_phragmen::Renouncing::Member) .get_dispatch_info().weight;