Skip to content

Commit

Permalink
apply jurors benchmark department-funding
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 10, 2024
1 parent 3eb9c45 commit 86fb12f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 8 deletions.
59 changes: 59 additions & 0 deletions custom-pallets/department-funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,64 @@ mod benchmarks {
apply_staking_period(RawOrigin::Signed(account1), department_id)
}

#[benchmark]
fn apply_jurors() {
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);

#[extrinsic_call]
apply_jurors(RawOrigin::Signed(account2.clone()), department_id, stake)
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
}
51 changes: 43 additions & 8 deletions custom-pallets/department-funding/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use core::marker::PhantomData;
pub trait WeightInfo {
fn create_department_required_fund() -> Weight;
fn apply_staking_period() -> Weight;
fn apply_jurors() -> Weight;
}

/// Weights for `pallet_department_funding` using the Substrate node and recommended hardware.
Expand All @@ -58,8 +59,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 28_476_000 picoseconds.
Weight::from_parts(29_780_000, 3810)
// Minimum execution time: 27_469_000 picoseconds.
Weight::from_parts(28_838_000, 3810)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -79,11 +80,28 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 26_841_000 picoseconds.
Weight::from_parts(28_235_000, 3771)
// Minimum execution time: 26_581_000 picoseconds.
Weight::from_parts(27_526_000, 3771)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(5_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:0)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn apply_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 38_811_000 picoseconds.
Weight::from_parts(40_559_000, 3908)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
}

// For backwards compatibility and tests.
Expand All @@ -102,8 +120,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 28_476_000 picoseconds.
Weight::from_parts(29_780_000, 3810)
// Minimum execution time: 27_469_000 picoseconds.
Weight::from_parts(28_838_000, 3810)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -123,9 +141,26 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 26_841_000 picoseconds.
Weight::from_parts(28_235_000, 3771)
// Minimum execution time: 26_581_000 picoseconds.
Weight::from_parts(27_526_000, 3771)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(5_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:0)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn apply_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 38_811_000 picoseconds.
Weight::from_parts(40_559_000, 3908)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
}

0 comments on commit 86fb12f

Please sign in to comment.