From db96b68ae0cbef0364069ee96664b75626447fb7 Mon Sep 17 00:00:00 2001 From: Amiya Behera Date: Wed, 9 Oct 2024 20:49:40 +0530 Subject: [PATCH] department-funding benchmarking create_department_required_fund --- .../department-funding/src/benchmarking.rs | 58 ++++++--- custom-pallets/department-funding/src/lib.rs | 4 +- .../department-funding/src/weights.rs | 111 +++++++++--------- .../positive-externality/src/lib.rs | 28 ----- notes | 10 ++ runtime/src/lib.rs | 1 + 6 files changed, 110 insertions(+), 102 deletions(-) diff --git a/custom-pallets/department-funding/src/benchmarking.rs b/custom-pallets/department-funding/src/benchmarking.rs index 5a26241..1345e38 100644 --- a/custom-pallets/department-funding/src/benchmarking.rs +++ b/custom-pallets/department-funding/src/benchmarking.rs @@ -3,32 +3,60 @@ use super::*; #[allow(unused)] -use crate::Pallet as Template; +use crate::Pallet as DepartmentFunding; use frame_benchmarking::v2::*; use frame_system::RawOrigin; +use pallet_support::Content; +const SEED: u32 = 0; +use frame_support::{assert_noop, assert_ok}; +#[benchmarks( + where T: pallet_departments::Config + frame_system::Config +)] #[benchmarks] mod benchmarks { use super::*; #[benchmark] - fn do_something() { - let value = 100u32.into(); - let caller: T::AccountId = whitelisted_caller(); - #[extrinsic_call] - do_something(RawOrigin::Signed(caller), value); + fn create_department_required_fund() { + let account_id = 1; + let department_id = 1; + let tipping_name = TippingName::SmallTipper; - assert_eq!(Something::::get(), Some(value)); - } + let account1 = account::("account1", 1, SEED); - #[benchmark] - fn cause_error() { - Something::::put(100u32); - let caller: T::AccountId = whitelisted_caller(); - #[extrinsic_call] - cause_error(RawOrigin::Signed(caller)); + let balance = DepartmentFunding::::u64_to_balance_saturated(100000000000000); + + let _ = ::Currency::deposit_creating(&account1, balance); - assert_eq!(Something::::get(), Some(101u32)); + let funding_needed = DepartmentFunding::::u64_to_balance_saturated(10_000u64); + // Dispatch a signed extrinsic. + let department_account_id = 5; + let content_department: Content = Content::IPFS( + "bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy" + .as_bytes() + .to_vec(), + ); + + assert_ok!(>::create_department( + RawOrigin::Signed(account1.clone()).into(), + content_department + )); + + let content: Content = Content::IPFS( + "bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy" + .as_bytes() + .to_vec(), + ); + + #[extrinsic_call] + create_department_required_fund( + RawOrigin::Signed(account1), + department_id, + content.clone(), + tipping_name, + funding_needed, + ); } impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/custom-pallets/department-funding/src/lib.rs b/custom-pallets/department-funding/src/lib.rs index 061bc57..483809d 100644 --- a/custom-pallets/department-funding/src/lib.rs +++ b/custom-pallets/department-funding/src/lib.rs @@ -13,8 +13,8 @@ mod mock; #[cfg(test)] mod tests; -// #[cfg(feature = "runtime-benchmarks")] -// mod benchmarking; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; pub mod weights; pub use weights::*; diff --git a/custom-pallets/department-funding/src/weights.rs b/custom-pallets/department-funding/src/weights.rs index e8fbc09..2f0aad0 100644 --- a/custom-pallets/department-funding/src/weights.rs +++ b/custom-pallets/department-funding/src/weights.rs @@ -1,91 +1,88 @@ -//! Autogenerated weights for pallet_template +//! Autogenerated weights for `pallet_department_funding` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-10-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Alexs-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `amiya`, CPU: `12th Gen Intel(R) Core(TM) i7-12650H` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ../../target/release/node-template +// target/release/node-template // benchmark // pallet // --chain // dev +// --wasm-execution +// compiled // --pallet -// pallet_template +// pallet-department-funding // --extrinsic // * -// --steps=50 -// --repeat=20 -// --execution=wasm -// --wasm-execution=compiled +// --steps +// 50 +// --repeat +// 20 // --output -// pallets/template/src/weights.rs -// --template -// ../../.maintain/frame-weight-template.hbs +// custom-pallets/department-funding/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for pallet_template. +/// Weight functions needed for `pallet_department_funding`. pub trait WeightInfo { - fn do_something() -> Weight; - fn cause_error() -> Weight; + fn create_department_required_fund() -> Weight; } -/// Weights for pallet_template using the Substrate node and recommended hardware. +/// Weights for `pallet_department_funding` using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn do_something() -> Weight { + /// Storage: `Departments::Departments` (r:1 w:0) + /// Proof: `Departments::Departments` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `DepartmentFunding::NextDepartmentRequiredFundId` (r:1 w:1) + /// Proof: `DepartmentFunding::NextDepartmentRequiredFundId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `DepartmentFunding::DepartmentRequiredFunds` (r:0 w:1) + /// Proof: `DepartmentFunding::DepartmentRequiredFunds` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn create_department_required_fund() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn cause_error() -> Weight { - // Proof Size summary in bytes: - // Measured: `32` - // Estimated: `1489` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 1489) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `345` + // Estimated: `3810` + // Minimum execution time: 26_415_000 picoseconds. + Weight::from_parts(27_367_000, 3810) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } -// For backwards compatibility and tests +// For backwards compatibility and tests. impl WeightInfo for () { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn do_something() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn cause_error() -> Weight { + /// Storage: `Departments::Departments` (r:1 w:0) + /// Proof: `Departments::Departments` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `DepartmentFunding::NextDepartmentRequiredFundId` (r:1 w:1) + /// Proof: `DepartmentFunding::NextDepartmentRequiredFundId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `DepartmentFunding::DepartmentRequiredFunds` (r:0 w:1) + /// Proof: `DepartmentFunding::DepartmentRequiredFunds` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn create_department_required_fund() -> Weight { // Proof Size summary in bytes: - // Measured: `32` - // Estimated: `1489` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 1489) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `345` + // Estimated: `3810` + // Minimum execution time: 26_415_000 picoseconds. + Weight::from_parts(27_367_000, 3810) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } } diff --git a/custom-pallets/positive-externality/src/lib.rs b/custom-pallets/positive-externality/src/lib.rs index 72f3116..b13dff3 100644 --- a/custom-pallets/positive-externality/src/lib.rs +++ b/custom-pallets/positive-externality/src/lib.rs @@ -609,33 +609,5 @@ pub mod pallet { } Ok(()) } - - // #[pallet::call_index(9)] - // #[pallet::weight(0)] - // pub fn get_incentives( - // origin: OriginFor, - // user_to_calculate: T::AccountId, - // ) -> DispatchResult { - // let _who = ensure_signed(origin)?; - // let pe_block_number = >::get(user_to_calculate.clone()); - - // let key = SumTreeName::PositiveExternality { - // user_address: user_to_calculate.clone(), - // block_number: pe_block_number.clone(), - // }; - - // let phase_data = Self::get_phase_data(); - // T::SchellingGameSharedSource::get_incentives_score_schelling_helper_link( - // key.clone(), - // phase_data, - // RangePoint::ZeroToFive, - // )?; - - // let score = T::SchellingGameSharedSource::get_mean_value_link(key.clone())?; - // // println!("Score {:?}", score); - // T::SharedStorageSource::set_positive_externality_link(user_to_calculate, score)?; - - // Ok(()) - // } } } diff --git a/notes b/notes index 48e718c..7f845cb 100644 --- a/notes +++ b/notes @@ -29,6 +29,16 @@ cargo run --release --features runtime-benchmarks -- benchmark pallet \ --repeat 20 \ --output custom-pallets/positive-externality/src/weights.rs --template=./.maintain/frame-weight-template.hbs + +cargo run --release --features runtime-benchmarks -- benchmark pallet \ + --chain dev \ + --wasm-execution compiled \ + --pallet "pallet-department-funding" \ + --extrinsic "*" \ + --steps 50 \ + --repeat 20 \ + --output custom-pallets/department-funding/src/weights.rs --template=./.maintain/frame-weight-template.hbs + cargo run --release --features runtime-benchmarks -- benchmark pallet \ diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 09f9887..89e45a2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -438,6 +438,7 @@ mod benches { [pallet_template, TemplateModule] [pallet_project_tips, ProjectTips] [pallet_positive_externality, PositiveExternality] + [pallet_department_funding, DepartmentFunding] ); }