Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

WeightInfo for Pallet Indices #7137

Merged
1 commit merged into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 52 additions & 0 deletions bin/node/runtime/src/weights/pallet_indices.rs
Original file line number Diff line number Diff line change
@@ -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))
}
}
24 changes: 7 additions & 17 deletions frame/indices/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::max_value());
}: _(RawOrigin::Signed(caller.clone()), account_index)
Expand All @@ -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::<T>::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::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
Expand All @@ -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::<T>::max_value());
Expand All @@ -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::<T>::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::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;
Expand All @@ -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::<T>::max_value());
Expand Down
51 changes: 51 additions & 0 deletions frame/indices/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -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))
}
}
36 changes: 12 additions & 24 deletions frame/indices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,25 @@ 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;

mod mock;
pub mod address;
mod tests;
mod benchmarking;
mod default_weights;

pub type Address<T> = RawAddress<<T as frame_system::Trait>::AccountId, <T as Trait>::AccountIndex>;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::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.
Expand Down Expand Up @@ -142,10 +135,9 @@ decl_module! {
/// - One reserve operation.
/// - One event.
/// -------------------
/// - Base Weight: 28.69 µs
/// - DB Weight: 1 Read/Write (Accounts)
/// # </weight>
#[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)?;

Expand Down Expand Up @@ -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>
#[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::<T>::NotTransfer);
Expand Down Expand Up @@ -210,10 +201,9 @@ decl_module! {
/// - One reserve operation.
/// - One event.
/// -------------------
/// - Base Weight: 25.53 µs
/// - DB Weight: 1 Read/Write (Accounts)
/// # </weight>
#[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)?;

Expand Down Expand Up @@ -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>
#[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)?;

Expand Down Expand Up @@ -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>
#[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)?;

Expand Down