Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
feat: add benchmarks for pallet_treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
José Molina committed Dec 14, 2023
1 parent 846255c commit 8f098de
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 4 deletions.
36 changes: 32 additions & 4 deletions runtime/trappist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ use frame_support::{
dispatch::DispatchClass,
parameter_types,
traits::{
tokens::{PayFromAccount,UnityAssetBalanceConversion}, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32,
ConstU64, Contains, EitherOfDiverse, EqualPrivilegeOnly, InsideBoth,
tokens::{PayFromAccount, UnityAssetBalanceConversion},
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Contains, EitherOfDiverse,
EqualPrivilegeOnly, InsideBoth,
},
weights::{constants::RocksDbWeight, ConstantMultiplier, Weight},
PalletId,
Expand Down Expand Up @@ -643,6 +644,33 @@ parameter_types! {
pub const MaxBalance: Balance = Balance::max_value();
}

#[cfg(feature = "runtime-benchmarks")]
pub mod treasury_benchmark_helper {
use crate::constants::currency::EXISTENTIAL_DEPOSIT;
use crate::{Balances, RuntimeOrigin};
use pallet_treasury::ArgumentsFactory;
use parachains_common::AccountId;
use sp_core::crypto::FromEntropy;

pub struct TreasuryBenchmarkHelper;
impl ArgumentsFactory<(), AccountId> for TreasuryBenchmarkHelper {
fn create_asset_kind(_seed: u32) -> () {
()
}
fn create_beneficiary(seed: [u8; 32]) -> AccountId {
let beneficiary = AccountId::from_entropy(&mut seed.as_slice()).unwrap();
// make sure the account has enough funds
Balances::force_set_balance(
RuntimeOrigin::root(),
sp_runtime::MultiAddress::Id(beneficiary.clone()),
EXISTENTIAL_DEPOSIT,
)
.expect("Failure transferring the existential deposit");
beneficiary
}
}
}

impl pallet_treasury::Config for Runtime {
type Currency = Balances;
type ApproveOrigin = TreasuryApproveCancelOrigin;
Expand All @@ -656,7 +684,7 @@ impl pallet_treasury::Config for Runtime {
type Burn = ();
type PalletId = TreasuryPalletId;
type BurnDestination = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
type SpendFunds = ();
type MaxApprovals = MaxApprovals;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
Expand All @@ -667,7 +695,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = treasury_benchmark_helper::TreasuryBenchmarkHelper;
}

impl pallet_withdraw_teleport::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions runtime/trappist/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod pallet_safe_mode;
pub mod pallet_scheduler;
pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_treasury;
pub mod pallet_tx_pause;
pub mod pallet_uniques;
pub mod pallet_utility;
Expand Down
204 changes: 204 additions & 0 deletions runtime/trappist/src/weights/pallet_treasury.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// This file is part of Trappist.

// Copyright (C) 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.

//! Autogenerated weights for `pallet_treasury`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 29.0.0
//! DATE: 2023-12-14, STEPS: `10`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `PAR03651`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
// Executed Command:
// ./target/debug/trappist-node
// benchmark
// pallet
// --chain=dev
// --steps=10
// --repeat=10
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --pallet=pallet_treasury
// --extrinsic=*
// --wasm-execution=compiled
// --header=./templates/file_header.txt
// --output=./runtime/trappist/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `pallet_treasury`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_treasury::WeightInfo for WeightInfo<T> {
/// Storage: `Treasury::ProposalCount` (r:1 w:1)
/// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Approvals` (r:1 w:1)
/// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Proposals` (r:0 w:1)
/// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`)
fn spend_local() -> Weight {
// Proof Size summary in bytes:
// Measured: `6`
// Estimated: `1887`
// Minimum execution time: 107_000_000 picoseconds.
Weight::from_parts(108_000_000, 0)
.saturating_add(Weight::from_parts(0, 1887))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Treasury::ProposalCount` (r:1 w:1)
/// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Proposals` (r:0 w:1)
/// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`)
fn propose_spend() -> Weight {
// Proof Size summary in bytes:
// Measured: `107`
// Estimated: `1489`
// Minimum execution time: 261_000_000 picoseconds.
Weight::from_parts(280_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Treasury::Proposals` (r:1 w:1)
/// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn reject_proposal() -> Weight {
// Proof Size summary in bytes:
// Measured: `368`
// Estimated: `6196`
// Minimum execution time: 433_000_000 picoseconds.
Weight::from_parts(451_000_000, 0)
.saturating_add(Weight::from_parts(0, 6196))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Treasury::Proposals` (r:1 w:0)
/// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Approvals` (r:1 w:1)
/// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
/// The range of component `p` is `[0, 99]`.
fn approve_proposal(p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `467 + p * (7 ±0)`
// Estimated: `3573`
// Minimum execution time: 85_000_000 picoseconds.
Weight::from_parts(107_472_727, 0)
.saturating_add(Weight::from_parts(0, 3573))
// Standard Error: 33_226
.saturating_add(Weight::from_parts(74_288, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Treasury::Approvals` (r:1 w:1)
/// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
fn remove_approval() -> Weight {
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `1887`
// Minimum execution time: 64_000_000 picoseconds.
Weight::from_parts(65_000_000, 0)
.saturating_add(Weight::from_parts(0, 1887))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `System::Account` (r:99 w:99)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Deactivated` (r:1 w:1)
/// Proof: `Treasury::Deactivated` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`)
/// Storage: `Balances::InactiveIssuance` (r:1 w:1)
/// Proof: `Balances::InactiveIssuance` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Approvals` (r:1 w:1)
/// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Proposals` (r:99 w:49)
/// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`)
/// The range of component `p` is `[0, 99]`.
fn on_initialize_proposals(p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `972 + p * (208 ±0)`
// Estimated: `61332 + p * (2583 ±168)`
// Minimum execution time: 201_000_000 picoseconds.
Weight::from_parts(4_531_251_515, 0)
.saturating_add(Weight::from_parts(0, 61332))
// Standard Error: 12_545_509
.saturating_add(Weight::from_parts(227_187_511, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads(26))
.saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(p.into())))
.saturating_add(T::DbWeight::get().writes(37))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into())))
.saturating_add(Weight::from_parts(0, 2583).saturating_mul(p.into()))
}
/// Storage: `Treasury::SpendCount` (r:1 w:1)
/// Proof: `Treasury::SpendCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Treasury::Spends` (r:0 w:1)
/// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn spend() -> Weight {
// Proof Size summary in bytes:
// Measured: `6`
// Estimated: `1489`
// Minimum execution time: 97_000_000 picoseconds.
Weight::from_parts(97_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Treasury::Spends` (r:1 w:1)
/// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn payout() -> Weight {
// Proof Size summary in bytes:
// Measured: `330`
// Estimated: `6196`
// Minimum execution time: 621_000_000 picoseconds.
Weight::from_parts(633_000_000, 0)
.saturating_add(Weight::from_parts(0, 6196))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Treasury::Spends` (r:1 w:1)
/// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn check_status() -> Weight {
// Proof Size summary in bytes:
// Measured: `124`
// Estimated: `3534`
// Minimum execution time: 118_000_000 picoseconds.
Weight::from_parts(127_000_000, 0)
.saturating_add(Weight::from_parts(0, 3534))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Treasury::Spends` (r:1 w:1)
/// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn void_spend() -> Weight {
// Proof Size summary in bytes:
// Measured: `124`
// Estimated: `3534`
// Minimum execution time: 109_000_000 picoseconds.
Weight::from_parts(127_000_000, 0)
.saturating_add(Weight::from_parts(0, 3534))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}

0 comments on commit 8f098de

Please sign in to comment.