diff --git a/custom-pallets/department-funding/Cargo.toml b/custom-pallets/department-funding/Cargo.toml index ed58bce..0037bd4 100644 --- a/custom-pallets/department-funding/Cargo.toml +++ b/custom-pallets/department-funding/Cargo.toml @@ -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 } diff --git a/custom-pallets/department-funding/src/benchmarking.rs b/custom-pallets/department-funding/src/benchmarking.rs index dff7ccd..44d6495 100644 --- a/custom-pallets/department-funding/src/benchmarking.rs +++ b/custom-pallets/department-funding/src/benchmarking.rs @@ -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::("account1", 1, SEED); + + let balance = DepartmentFunding::::u64_to_balance_saturated(100000000000000); + + let _ = ::Currency::deposit_creating(&account1, balance); + + 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(), + ); + + assert_ok!(DepartmentFunding::::create_department_required_fund( + RawOrigin::Signed(account1.clone()).into(), + department_id, + content.clone(), + tipping_name, + funding_needed, + )); + + let start_block_number = DepartmentFunding::::u64_to_block_saturated(50); + + >::set_block_number(start_block_number); + assert_ok!(DepartmentFunding::::apply_staking_period( + RawOrigin::Signed(account1.clone()).into(), + department_id + )); + + let account2 = account::("stake-account", 2, SEED); + + let balance = DepartmentFunding::::u64_to_balance_saturated(100000000000000); + + let _ = ::Currency::deposit_creating(&account2, balance); + + let stake = DepartmentFunding::::u64_to_balance_saturated(100); + + let mut accounts = vec![]; + + for j in 4..50 { + let account_number = account::("apply-juror-account", j, SEED); + let _ = ::Currency::deposit_creating(&account_number, balance); + accounts.push(account_number); + } + + for j in 4..30 { + let stake = DepartmentFunding::::u64_to_balance_saturated(j * 100); + assert_ok!(DepartmentFunding::::apply_jurors( + RawOrigin::Signed(accounts[(j) as usize].clone()).into(), + department_id.clone(), + stake + )); + } + + let phase_data = DepartmentFunding::::get_phase_data(); + + >::set_block_number(start_block_number + phase_data.staking_length); + + assert_ok!(DepartmentFunding::::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::("account1", 1, SEED); + + let balance = DepartmentFunding::::u64_to_balance_saturated(100000000000000); + + let _ = ::Currency::deposit_creating(&account1, balance); + + 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(), + ); + + assert_ok!(DepartmentFunding::::create_department_required_fund( + RawOrigin::Signed(account1.clone()).into(), + department_id, + content.clone(), + tipping_name, + funding_needed, + )); + + let start_block_number = DepartmentFunding::::u64_to_block_saturated(50); + + >::set_block_number(start_block_number); + assert_ok!(DepartmentFunding::::apply_staking_period( + RawOrigin::Signed(account1.clone()).into(), + department_id + )); + + let account2 = account::("stake-account", 2, SEED); + + let balance = DepartmentFunding::::u64_to_balance_saturated(100000000000000); + + let _ = ::Currency::deposit_creating(&account2, balance); + + let stake = DepartmentFunding::::u64_to_balance_saturated(100); + + let mut accounts = vec![]; + + for j in 4..50 { + let account_number = account::("apply-juror-account", j, SEED); + let _ = ::Currency::deposit_creating(&account_number, balance); + accounts.push(account_number); + } + + for j in 4..30 { + let stake = DepartmentFunding::::u64_to_balance_saturated(j * 100); + assert_ok!(DepartmentFunding::::apply_jurors( + RawOrigin::Signed(accounts[(j) as usize].clone()).into(), + department_id.clone(), + stake + )); + } + + let phase_data = DepartmentFunding::::get_phase_data(); + + >::set_block_number(start_block_number + phase_data.staking_length); + + assert_ok!(DepartmentFunding::::pass_period( + RawOrigin::Signed(accounts[0].clone()).into(), + department_id + )); + + assert_ok!(DepartmentFunding::::draw_jurors( + RawOrigin::Signed(accounts[1].clone()).into(), + department_id, + 5 + )); + + assert_ok!(DepartmentFunding::::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); } diff --git a/custom-pallets/department-funding/src/weights.rs b/custom-pallets/department-funding/src/weights.rs index 03816e6..f6a5da5 100644 --- a/custom-pallets/department-funding/src/weights.rs +++ b/custom-pallets/department-funding/src/weights.rs @@ -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. @@ -60,8 +62,8 @@ impl WeightInfo for SubstrateWeight { // 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)) } @@ -81,8 +83,8 @@ impl WeightInfo for SubstrateWeight { // 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)) } @@ -98,8 +100,8 @@ impl WeightInfo for SubstrateWeight { // 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)) } @@ -113,8 +115,48 @@ impl WeightInfo for SubstrateWeight { // 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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) }