From 4cca01ecc5e2a34044be1bd7f30489d1c1a09020 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 18 Sep 2020 02:40:15 +0200 Subject: [PATCH] Pallet Indices --- bin/node/runtime/src/lib.rs | 2 +- bin/node/runtime/src/weights/mod.rs | 1 + .../runtime/src/weights/pallet_indices.rs | 52 +++++++++++++++++++ frame/indices/src/benchmarking.rs | 24 +++------ frame/indices/src/default_weights.rs | 51 ++++++++++++++++++ frame/indices/src/lib.rs | 36 +++++-------- 6 files changed, 124 insertions(+), 42 deletions(-) create mode 100644 bin/node/runtime/src/weights/pallet_indices.rs create mode 100644 frame/indices/src/default_weights.rs diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 16fcc9f70bc16..468605ddb7a09 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -320,7 +320,7 @@ impl pallet_indices::Trait for Runtime { type Currency = Balances; type Deposit = IndexDeposit; type Event = Event; - type WeightInfo = (); + type WeightInfo = weights::pallet_indices::WeightInfo; } parameter_types! { diff --git a/bin/node/runtime/src/weights/mod.rs b/bin/node/runtime/src/weights/mod.rs index fd6d3cab49e28..a07aa2e5bc896 100644 --- a/bin/node/runtime/src/weights/mod.rs +++ b/bin/node/runtime/src/weights/mod.rs @@ -20,6 +20,7 @@ pub mod pallet_balances; pub mod pallet_collective; pub mod pallet_democracy; pub mod pallet_identity; +pub mod pallet_indices; pub mod pallet_im_online; pub mod pallet_proxy; pub mod pallet_staking; diff --git a/bin/node/runtime/src/weights/pallet_indices.rs b/bin/node/runtime/src/weights/pallet_indices.rs new file mode 100644 index 0000000000000..f6a708bbd46b6 --- /dev/null +++ b/bin/node/runtime/src/weights/pallet_indices.rs @@ -0,0 +1,52 @@ +// 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_indices::WeightInfo for WeightInfo { + fn claim() -> Weight { + (56_237_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn transfer() -> Weight { + (63_665_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn free() -> Weight { + (50_736_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn force_transfer() -> Weight { + (52_361_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn freeze() -> Weight { + (46_483_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } +} diff --git a/frame/indices/src/benchmarking.rs b/frame/indices/src/benchmarking.rs index e8465c44cdc16..382bf07f1136e 100644 --- a/frame/indices/src/benchmarking.rs +++ b/frame/indices/src/benchmarking.rs @@ -32,9 +32,7 @@ benchmarks! { _ { } claim { - // Index being claimed - let i in 0 .. 1000; - let account_index = T::AccountIndex::from(i); + let account_index = T::AccountIndex::from(SEED); let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); }: _(RawOrigin::Signed(caller.clone()), account_index) @@ -43,13 +41,11 @@ benchmarks! { } transfer { - // Index being claimed - let i in 0 .. 1000; - let account_index = T::AccountIndex::from(i); + let account_index = T::AccountIndex::from(SEED); // Setup accounts let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let recipient: T::AccountId = account("recipient", i, SEED); + let recipient: T::AccountId = account("recipient", 0, SEED); T::Currency::make_free_balance_be(&recipient, BalanceOf::::max_value()); // Claim the index Indices::::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?; @@ -59,9 +55,7 @@ benchmarks! { } free { - // Index being claimed - let i in 0 .. 1000; - let account_index = T::AccountIndex::from(i); + let account_index = T::AccountIndex::from(SEED); // Setup accounts let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -73,13 +67,11 @@ benchmarks! { } force_transfer { - // Index being claimed - let i in 0 .. 1000; - let account_index = T::AccountIndex::from(i); + let account_index = T::AccountIndex::from(SEED); // Setup accounts let original: T::AccountId = account("original", 0, SEED); T::Currency::make_free_balance_be(&original, BalanceOf::::max_value()); - let recipient: T::AccountId = account("recipient", i, SEED); + let recipient: T::AccountId = account("recipient", 0, SEED); T::Currency::make_free_balance_be(&recipient, BalanceOf::::max_value()); // Claim the index Indices::::claim(RawOrigin::Signed(original).into(), account_index)?; @@ -89,9 +81,7 @@ benchmarks! { } freeze { - // Index being claimed - let i in 0 .. 1000; - let account_index = T::AccountIndex::from(i); + let account_index = T::AccountIndex::from(SEED); // Setup accounts let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); diff --git a/frame/indices/src/default_weights.rs b/frame/indices/src/default_weights.rs new file mode 100644 index 0000000000000..6b3b9c13e40a0 --- /dev/null +++ b/frame/indices/src/default_weights.rs @@ -0,0 +1,51 @@ +// 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 claim() -> Weight { + (56_237_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn transfer() -> Weight { + (63_665_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn free() -> Weight { + (50_736_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn force_transfer() -> Weight { + (52_361_000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn freeze() -> Weight { + (46_483_000 as Weight) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } +} diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 3dc0cec9d94bc..edbaed17e536f 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -28,7 +28,7 @@ use sp_runtime::traits::{ use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage, ensure}; use frame_support::dispatch::DispatchResult; use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved}; -use frame_support::weights::{Weight, constants::WEIGHT_PER_MICROS}; +use frame_support::weights::Weight; use frame_system::{ensure_signed, ensure_root}; use self::address::Address as RawAddress; @@ -36,24 +36,17 @@ mod mock; pub mod address; mod tests; mod benchmarking; +mod default_weights; pub type Address = RawAddress<::AccountId, ::AccountIndex>; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; pub trait WeightInfo { - fn claim(i: u32, ) -> Weight; - fn transfer(i: u32, ) -> Weight; - fn free(i: u32, ) -> Weight; - fn force_transfer(i: u32, ) -> Weight; - fn freeze(i: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn claim(_i: u32, ) -> Weight { 1_000_000_000 } - fn transfer(_i: u32, ) -> Weight { 1_000_000_000 } - fn free(_i: u32, ) -> Weight { 1_000_000_000 } - fn force_transfer(_i: u32, ) -> Weight { 1_000_000_000 } - fn freeze(_i: u32, ) -> Weight { 1_000_000_000 } + fn claim() -> Weight; + fn transfer() -> Weight; + fn free() -> Weight; + fn force_transfer() -> Weight; + fn freeze() -> Weight; } /// The module's config trait. @@ -142,10 +135,9 @@ decl_module! { /// - One reserve operation. /// - One event. /// ------------------- - /// - Base Weight: 28.69 µs /// - DB Weight: 1 Read/Write (Accounts) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) + 30 * WEIGHT_PER_MICROS] + #[weight = T::WeightInfo::claim()] fn claim(origin, index: T::AccountIndex) { let who = ensure_signed(origin)?; @@ -173,12 +165,11 @@ decl_module! { /// - One transfer operation. /// - One event. /// ------------------- - /// - Base Weight: 33.74 µs /// - DB Weight: /// - Reads: Indices Accounts, System Account (recipient) /// - Writes: Indices Accounts, System Account (recipient) /// # - #[weight = T::DbWeight::get().reads_writes(2, 2) + 35 * WEIGHT_PER_MICROS] + #[weight = T::WeightInfo::transfer()] fn transfer(origin, new: T::AccountId, index: T::AccountIndex) { let who = ensure_signed(origin)?; ensure!(who != new, Error::::NotTransfer); @@ -210,10 +201,9 @@ decl_module! { /// - One reserve operation. /// - One event. /// ------------------- - /// - Base Weight: 25.53 µs /// - DB Weight: 1 Read/Write (Accounts) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) + 25 * WEIGHT_PER_MICROS] + #[weight = T::WeightInfo::free()] fn free(origin, index: T::AccountIndex) { let who = ensure_signed(origin)?; @@ -244,12 +234,11 @@ decl_module! { /// - Up to one reserve operation. /// - One event. /// ------------------- - /// - Base Weight: 26.83 µs /// - DB Weight: /// - Reads: Indices Accounts, System Account (original owner) /// - Writes: Indices Accounts, System Account (original owner) /// # - #[weight = T::DbWeight::get().reads_writes(2, 2) + 25 * WEIGHT_PER_MICROS] + #[weight = T::WeightInfo::force_transfer()] fn force_transfer(origin, new: T::AccountId, index: T::AccountIndex, freeze: bool) { ensure_root(origin)?; @@ -277,10 +266,9 @@ decl_module! { /// - Up to one slash operation. /// - One event. /// ------------------- - /// - Base Weight: 30.86 µs /// - DB Weight: 1 Read/Write (Accounts) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) + 30 * WEIGHT_PER_MICROS] + #[weight = T::WeightInfo::freeze()] fn freeze(origin, index: T::AccountIndex) { let who = ensure_signed(origin)?;