Skip to content

Commit

Permalink
commit votes benchmarking department-funding
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 11, 2024
1 parent 53163f1 commit 1198448
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 17 deletions.
3 changes: 2 additions & 1 deletion custom-pallets/department-funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ trait-schelling-game-shared = { workspace = true }
pallet-sortition-sum-game = { workspace = true }
trait-departments = { workspace = true }
pallet-departments = { workspace = true }
sp-io = { workspace = true }


[dev-dependencies]
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
frame-support-test = { workspace = true }

Expand Down
183 changes: 183 additions & 0 deletions custom-pallets/department-funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,188 @@ mod benchmarks {
pass_period(RawOrigin::Signed(accounts[0].clone()), department_id)
}

#[benchmark]
fn draw_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);

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);

assert_ok!(DepartmentFunding::<T>::pass_period(
RawOrigin::Signed(accounts[0].clone()).into(),
department_id
));

#[extrinsic_call]
draw_jurors(RawOrigin::Signed(accounts[1].clone()), department_id, 5);
}

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

assert_ok!(DepartmentFunding::<T>::pass_period(
RawOrigin::Signed(accounts[0].clone()).into(),
department_id
));

assert_ok!(DepartmentFunding::<T>::draw_jurors(
RawOrigin::Signed(accounts[1].clone()).into(),
department_id,
5
));

assert_ok!(DepartmentFunding::<T>::pass_period(
RawOrigin::Signed(accounts[0].clone()).into(),
department_id
));

let hash = sp_io::hashing::keccak_256("1salt".as_bytes());

#[extrinsic_call]
commit_vote(RawOrigin::Signed(accounts[4].clone()), department_id, hash);
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
}
114 changes: 98 additions & 16 deletions custom-pallets/department-funding/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub trait WeightInfo {
fn apply_staking_period() -> Weight;
fn apply_jurors() -> Weight;
fn pass_period() -> Weight;
fn draw_jurors() -> Weight;
fn commit_vote() -> Weight;
}

/// Weights for `pallet_department_funding` using the Substrate node and recommended hardware.
Expand All @@ -60,8 +62,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 24_830_000 picoseconds.
Weight::from_parts(25_919_000, 3810)
// Minimum execution time: 26_489_000 picoseconds.
Weight::from_parts(29_241_000, 3810)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -81,8 +83,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 24_280_000 picoseconds.
Weight::from_parts(24_973_000, 3771)
// Minimum execution time: 27_247_000 picoseconds.
Weight::from_parts(28_378_000, 3771)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
Expand All @@ -98,8 +100,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 34_852_000 picoseconds.
Weight::from_parts(36_814_000, 3908)
// Minimum execution time: 36_855_000 picoseconds.
Weight::from_parts(39_169_000, 3908)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -113,8 +115,48 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `282`
// Estimated: `3747`
// Minimum execution time: 18_865_000 picoseconds.
Weight::from_parts(19_787_000, 3747)
// Minimum execution time: 20_613_000 picoseconds.
Weight::from_parts(21_229_000, 3747)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_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: `SchellingGameShared::DrawsInRound` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawsInRound` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::Nonce` (r:1 w:1)
/// Proof: `SchellingGameShared::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0)
/// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawnJurors` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn draw_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `2734`
// Estimated: `6199`
// Minimum execution time: 163_900_000 picoseconds.
Weight::from_parts(170_151_000, 6199)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(4_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: `SchellingGameShared::DrawnJurors` (r:1 w:0)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::VoteCommits` (r:0 w:1)
/// Proof: `SchellingGameShared::VoteCommits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn commit_vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `613`
// Estimated: `4078`
// Minimum execution time: 22_024_000 picoseconds.
Weight::from_parts(22_581_000, 4078)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -136,8 +178,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 24_830_000 picoseconds.
Weight::from_parts(25_919_000, 3810)
// Minimum execution time: 26_489_000 picoseconds.
Weight::from_parts(29_241_000, 3810)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -157,8 +199,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `3771`
// Minimum execution time: 24_280_000 picoseconds.
Weight::from_parts(24_973_000, 3771)
// Minimum execution time: 27_247_000 picoseconds.
Weight::from_parts(28_378_000, 3771)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
Expand All @@ -174,8 +216,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `443`
// Estimated: `3908`
// Minimum execution time: 34_852_000 picoseconds.
Weight::from_parts(36_814_000, 3908)
// Minimum execution time: 36_855_000 picoseconds.
Weight::from_parts(39_169_000, 3908)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -189,8 +231,48 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `282`
// Estimated: `3747`
// Minimum execution time: 18_865_000 picoseconds.
Weight::from_parts(19_787_000, 3747)
// Minimum execution time: 20_613_000 picoseconds.
Weight::from_parts(21_229_000, 3747)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_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: `SchellingGameShared::DrawsInRound` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawsInRound` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::Nonce` (r:1 w:1)
/// Proof: `SchellingGameShared::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0)
/// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawnJurors` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn draw_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `2734`
// Estimated: `6199`
// Minimum execution time: 163_900_000 picoseconds.
Weight::from_parts(170_151_000, 6199)
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().writes(4_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: `SchellingGameShared::DrawnJurors` (r:1 w:0)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::VoteCommits` (r:0 w:1)
/// Proof: `SchellingGameShared::VoteCommits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn commit_vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `613`
// Estimated: `4078`
// Minimum execution time: 22_024_000 picoseconds.
Weight::from_parts(22_581_000, 4078)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand Down

0 comments on commit 1198448

Please sign in to comment.