Skip to content

Commit

Permalink
pass period benchmarking department funding
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 11, 2024
1 parent 86fb12f commit 53163f1
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 13 deletions.
80 changes: 80 additions & 0 deletions custom-pallets/department-funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,85 @@ mod benchmarks {
apply_jurors(RawOrigin::Signed(account2.clone()), department_id, stake)
}

#[benchmark]
fn pass_period() {
let department_id = 1;
let tipping_name = TippingName::SmallTipper;

let account1 = account::<T::AccountId>("account1", 1, SEED);

let balance = DepartmentFunding::<T>::u64_to_balance_saturated(100000000000000);

let _ = <T as pallet::Config>::Currency::deposit_creating(&account1, balance);

let funding_needed = DepartmentFunding::<T>::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!(<pallet_departments::Pallet<T>>::create_department(
RawOrigin::Signed(account1.clone()).into(),
content_department
));

let content: Content = Content::IPFS(
"bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy"
.as_bytes()
.to_vec(),
);

assert_ok!(DepartmentFunding::<T>::create_department_required_fund(
RawOrigin::Signed(account1.clone()).into(),
department_id,
content.clone(),
tipping_name,
funding_needed,
));

let start_block_number = DepartmentFunding::<T>::u64_to_block_saturated(50);

<frame_system::Pallet<T>>::set_block_number(start_block_number);
assert_ok!(DepartmentFunding::<T>::apply_staking_period(
RawOrigin::Signed(account1.clone()).into(),
department_id
));

let account2 = account::<T::AccountId>("stake-account", 2, SEED);

let balance = DepartmentFunding::<T>::u64_to_balance_saturated(100000000000000);

let _ = <T as pallet::Config>::Currency::deposit_creating(&account2, balance);

let stake = DepartmentFunding::<T>::u64_to_balance_saturated(100);

let mut accounts = vec![];

for j in 4..50 {
let account_number = account::<T::AccountId>("apply-juror-account", j, SEED);
let _ = <T as pallet::Config>::Currency::deposit_creating(&account_number, balance);
accounts.push(account_number);
}

for j in 4..30 {
let stake = DepartmentFunding::<T>::u64_to_balance_saturated(j * 100);
assert_ok!(DepartmentFunding::<T>::apply_jurors(
RawOrigin::Signed(accounts[(j) as usize].clone()).into(),
department_id.clone(),
stake
));
}

let phase_data = DepartmentFunding::<T>::get_phase_data();

<frame_system::Pallet<T>>::set_block_number(start_block_number + phase_data.staking_length);

#[extrinsic_call]
pass_period(RawOrigin::Signed(accounts[0].clone()), department_id)
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
}
57 changes: 44 additions & 13 deletions custom-pallets/department-funding/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `pallet_department_funding`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-10-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-10-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `amiya`, CPU: `12th Gen Intel(R) Core(TM) i7-12650H`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
Expand Down Expand Up @@ -40,6 +40,7 @@ pub trait WeightInfo {
fn create_department_required_fund() -> Weight;
fn apply_staking_period() -> Weight;
fn apply_jurors() -> Weight;
fn pass_period() -> Weight;
}

/// Weights for `pallet_department_funding` using the Substrate node and recommended hardware.
Expand All @@ -59,8 +60,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 27_469_000 picoseconds.
Weight::from_parts(28_838_000, 3810)
// Minimum execution time: 24_830_000 picoseconds.
Weight::from_parts(25_919_000, 3810)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -80,8 +81,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 26_581_000 picoseconds.
Weight::from_parts(27_526_000, 3771)
// Minimum execution time: 24_280_000 picoseconds.
Weight::from_parts(24_973_000, 3771)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
Expand All @@ -97,11 +98,26 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 38_811_000 picoseconds.
Weight::from_parts(40_559_000, 3908)
// Minimum execution time: 34_852_000 picoseconds.
Weight::from_parts(36_814_000, 3908)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `DepartmentFunding::ValidationBlock` (r:1 w:0)
/// Proof: `DepartmentFunding::ValidationBlock` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::PeriodName` (r:1 w:1)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::StakingStartTime` (r:1 w:0)
/// Proof: `SchellingGameShared::StakingStartTime` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn pass_period() -> Weight {
// Proof Size summary in bytes:
// Measured: `282`
// Estimated: `3747`
// Minimum execution time: 18_865_000 picoseconds.
Weight::from_parts(19_787_000, 3747)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests.
Expand All @@ -120,8 +136,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 27_469_000 picoseconds.
Weight::from_parts(28_838_000, 3810)
// Minimum execution time: 24_830_000 picoseconds.
Weight::from_parts(25_919_000, 3810)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -141,8 +157,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 26_581_000 picoseconds.
Weight::from_parts(27_526_000, 3771)
// Minimum execution time: 24_280_000 picoseconds.
Weight::from_parts(24_973_000, 3771)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
Expand All @@ -158,9 +174,24 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 38_811_000 picoseconds.
Weight::from_parts(40_559_000, 3908)
// Minimum execution time: 34_852_000 picoseconds.
Weight::from_parts(36_814_000, 3908)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: `DepartmentFunding::ValidationBlock` (r:1 w:0)
/// Proof: `DepartmentFunding::ValidationBlock` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::PeriodName` (r:1 w:1)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::StakingStartTime` (r:1 w:0)
/// Proof: `SchellingGameShared::StakingStartTime` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn pass_period() -> Weight {
// Proof Size summary in bytes:
// Measured: `282`
// Estimated: `3747`
// Minimum execution time: 18_865_000 picoseconds.
Weight::from_parts(19_787_000, 3747)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}

0 comments on commit 53163f1

Please sign in to comment.