Skip to content

Commit

Permalink
commit vote positive externality benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 2, 2024
1 parent 34e4569 commit cad359c
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 25 deletions.
2 changes: 1 addition & 1 deletion custom-pallets/positive-externality/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ trait-shared-storage = { workspace = true }
pallet-schelling-game-shared = { workspace = true }
trait-schelling-game-shared = { workspace = true }
pallet-sortition-sum-game = { 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
64 changes: 64 additions & 0 deletions custom-pallets/positive-externality/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,69 @@ mod benchmarks {
draw_jurors(RawOrigin::Signed(accounts[1].clone()), account1.clone(), 5);
}

#[benchmark]
fn commit_vote() {
let account1 = account::<T::AccountId>("set-validate", 1, SEED);
assert_ok!(PositiveExternality::<T>::set_validate_positive_externality(
RawOrigin::Signed(account1.clone()).into(),
true
));
let account2 = account::<T::AccountId>("stake-account", 2, SEED);

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

let _ = <T as pallet::Config>::Currency::deposit_creating(&account2, balance);
assert_ok!(PositiveExternality::<T>::apply_staking_period(
RawOrigin::Signed(account2.clone()).into(),
account1.clone()
));

let account3 = account::<T::AccountId>("apply-juror-account", 3, SEED);

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

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

let mut accounts = vec![];

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

assert_ok!(PositiveExternality::<T>::apply_jurors(
RawOrigin::Signed(account_number).into(),
account1.clone(),
(j * 100).into()
));
}

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

let now = <frame_system::Pallet<T>>::block_number();

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

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

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

assert_ok!(PositiveExternality::<T>::pass_period(
RawOrigin::Signed(accounts[0].clone()).into(),
account1.clone()
));
let hash = sp_io::hashing::keccak_256("1salt".as_bytes());

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

impl_benchmark_test_suite!(PositiveExternality, crate::mock::new_test_ext(), crate::mock::Test);
}
83 changes: 59 additions & 24 deletions custom-pallets/positive-externality/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub trait WeightInfo {
fn apply_jurors() -> Weight;
fn pass_period() -> Weight;
fn draw_jurors() -> Weight;
fn commit_vote() -> Weight;
}

/// Weights for `pallet_positive_externality` using the Substrate node and recommended hardware.
Expand All @@ -60,8 +61,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3477`
// Minimum execution time: 8_451_000 picoseconds.
Weight::from_parts(8_707_000, 3477)
// Minimum execution time: 8_703_000 picoseconds.
Weight::from_parts(9_149_000, 3477)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -71,8 +72,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_241_000 picoseconds.
Weight::from_parts(3_468_000, 0)
// Minimum execution time: 2_915_000 picoseconds.
Weight::from_parts(3_135_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::Validate` (r:1 w:0)
Expand All @@ -93,8 +94,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `220`
// Estimated: `3685`
// Minimum execution time: 36_598_000 picoseconds.
Weight::from_parts(37_733_000, 3685)
// Minimum execution time: 37_921_000 picoseconds.
Weight::from_parts(39_227_000, 3685)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(6_u64))
}
Expand All @@ -114,8 +115,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `584`
// Estimated: `4049`
// Minimum execution time: 42_221_000 picoseconds.
Weight::from_parts(43_722_000, 4049)
// Minimum execution time: 44_121_000 picoseconds.
Weight::from_parts(45_602_000, 4049)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -129,8 +130,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `351`
// Estimated: `3816`
// Minimum execution time: 21_238_000 picoseconds.
Weight::from_parts(22_268_000, 3816)
// Minimum execution time: 20_655_000 picoseconds.
Weight::from_parts(21_700_000, 3816)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -152,11 +153,28 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `184048`
// Estimated: `187513`
// Minimum execution time: 3_418_748_000 picoseconds.
Weight::from_parts(3_594_238_000, 187513)
// Minimum execution time: 3_421_943_000 picoseconds.
Weight::from_parts(3_539_433_000, 187513)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
/// Storage: `PositiveExternality::ValidationBlock` (r:1 w:0)
/// Proof: `PositiveExternality::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::ScoreVoteCommits` (r:0 w:1)
/// Proof: `SchellingGameShared::ScoreVoteCommits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn commit_vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `682`
// Estimated: `4147`
// Minimum execution time: 22_619_000 picoseconds.
Weight::from_parts(23_582_000, 4147)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests.
Expand All @@ -173,8 +191,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3477`
// Minimum execution time: 8_451_000 picoseconds.
Weight::from_parts(8_707_000, 3477)
// Minimum execution time: 8_703_000 picoseconds.
Weight::from_parts(9_149_000, 3477)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -184,8 +202,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_241_000 picoseconds.
Weight::from_parts(3_468_000, 0)
// Minimum execution time: 2_915_000 picoseconds.
Weight::from_parts(3_135_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::Validate` (r:1 w:0)
Expand All @@ -206,8 +224,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `220`
// Estimated: `3685`
// Minimum execution time: 36_598_000 picoseconds.
Weight::from_parts(37_733_000, 3685)
// Minimum execution time: 37_921_000 picoseconds.
Weight::from_parts(39_227_000, 3685)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(6_u64))
}
Expand All @@ -227,8 +245,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `584`
// Estimated: `4049`
// Minimum execution time: 42_221_000 picoseconds.
Weight::from_parts(43_722_000, 4049)
// Minimum execution time: 44_121_000 picoseconds.
Weight::from_parts(45_602_000, 4049)
.saturating_add(RocksDbWeight::get().reads(6_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -242,8 +260,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `351`
// Estimated: `3816`
// Minimum execution time: 21_238_000 picoseconds.
Weight::from_parts(22_268_000, 3816)
// Minimum execution time: 20_655_000 picoseconds.
Weight::from_parts(21_700_000, 3816)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -265,9 +283,26 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `184048`
// Estimated: `187513`
// Minimum execution time: 3_418_748_000 picoseconds.
Weight::from_parts(3_594_238_000, 187513)
// Minimum execution time: 3_421_943_000 picoseconds.
Weight::from_parts(3_539_433_000, 187513)
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
/// Storage: `PositiveExternality::ValidationBlock` (r:1 w:0)
/// Proof: `PositiveExternality::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::ScoreVoteCommits` (r:0 w:1)
/// Proof: `SchellingGameShared::ScoreVoteCommits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn commit_vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `682`
// Estimated: `4147`
// Minimum execution time: 22_619_000 picoseconds.
Weight::from_parts(23_582_000, 4147)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}

0 comments on commit cad359c

Please sign in to comment.