-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement democracy benchmarks (#348)
Co-authored-by: brenzi <brenzi@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use crate::{Pallet as EncointerDemocracy, *}; | ||
use codec::Encode; | ||
use encointer_primitives::{ | ||
ceremonies::Reputation, | ||
communities::CommunityIdentifier, | ||
democracy::{ProposalState, Tally, Vote}, | ||
storage::{current_ceremony_index_key, global_reputation_count, participant_reputation}, | ||
}; | ||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; | ||
use frame_support::{assert_ok, traits::OnInitialize, BoundedVec}; | ||
use frame_system::RawOrigin; | ||
#[cfg(not(feature = "std"))] | ||
use sp_std::vec; | ||
|
||
fn advance_n_blocks<T: Config>(n: u64) { | ||
for _ in 0..n { | ||
frame_system::Pallet::<T>::set_block_number( | ||
frame_system::Pallet::<T>::block_number() + 1u32.into(), | ||
); | ||
frame_system::Pallet::<T>::on_initialize(frame_system::Pallet::<T>::block_number()); | ||
} | ||
} | ||
|
||
benchmarks! { | ||
|
||
submit_proposal { | ||
let zoran = account("zoran", 1, 1); | ||
let proposal_action = ProposalAction::SetInactivityTimeout(8); | ||
assert!(<Proposals<T>>::iter().next().is_none()); | ||
}: _(RawOrigin::Signed(zoran), proposal_action) | ||
verify { | ||
assert!(<Proposals<T>>::iter().next().is_some()); | ||
} | ||
|
||
vote { | ||
frame_support::storage::unhashed::put_raw(¤t_ceremony_index_key(), &7u32.encode()); | ||
|
||
let zoran = account::<T::AccountId>("zoran", 1, 1); | ||
let cid = CommunityIdentifier::default(); | ||
|
||
let proposal_action = ProposalAction::SetInactivityTimeout(8); | ||
assert_ok!(EncointerDemocracy::<T>::submit_proposal( | ||
RawOrigin::Signed(zoran.clone()).into(), | ||
proposal_action | ||
)); | ||
|
||
frame_support::storage::unhashed::put_raw(&participant_reputation((cid, 3), &zoran), &Reputation::VerifiedUnlinked.encode()); | ||
frame_support::storage::unhashed::put_raw(&participant_reputation((cid, 4), &zoran), &Reputation::VerifiedUnlinked.encode()); | ||
frame_support::storage::unhashed::put_raw(&participant_reputation((cid, 5), &zoran), &Reputation::VerifiedUnlinked.encode()); | ||
let reputation_vec: ReputationVecOf<T> = BoundedVec::try_from(vec![ | ||
(cid, 3), | ||
(cid, 4), | ||
(cid, 5), | ||
]).unwrap(); | ||
|
||
assert!(<VoteEntries<T>>::iter().next().is_none()); | ||
}: _(RawOrigin::Signed(zoran.clone()), | ||
1, | ||
Vote::Aye, | ||
reputation_vec) | ||
verify { | ||
assert!(<VoteEntries<T>>::iter().next().is_some()); | ||
} | ||
|
||
update_proposal_state { | ||
frame_support::storage::unhashed::put_raw(¤t_ceremony_index_key(), &7u32.encode()); | ||
let zoran = account::<T::AccountId>("zoran", 1, 1); | ||
let cid = CommunityIdentifier::default(); | ||
|
||
let proposal_action = ProposalAction::SetInactivityTimeout(8); | ||
assert_ok!(EncointerDemocracy::<T>::submit_proposal( | ||
RawOrigin::Signed(zoran.clone()).into(), | ||
proposal_action | ||
)); | ||
|
||
|
||
Tallies::<T>::insert(1, Tally { turnout: 3, ayes: 3 }); | ||
|
||
frame_support::storage::unhashed::put_raw(&global_reputation_count(5), &3u128.encode()); | ||
assert_eq!(EncointerDemocracy::<T>::proposals(1).unwrap().state, ProposalState::Ongoing); | ||
EncointerDemocracy::<T>::update_proposal_state(RawOrigin::Signed(zoran.clone()).into(), 1).ok(); | ||
assert!(<EnactmentQueue<T>>::iter().next().is_none()); | ||
advance_n_blocks::<T>(21); | ||
|
||
}: _(RawOrigin::Signed(zoran), 1) | ||
verify { | ||
assert!(<EnactmentQueue<T>>::iter().next().is_some()); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2022 Encointer | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
//! Autogenerated weights for pallet_encointer_democracy with reference hardware: | ||
//! * 2.3 GHz 8-Core Intel Core i9 | ||
//! * 16 GB 2400 MHz DDR4 | ||
//! * SSD | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2023-09-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// target/release/encointer-node-notee | ||
// benchmark | ||
// pallet | ||
// --chain=dev | ||
// --steps=50 | ||
// --repeat=20 | ||
// --pallet=pallet_encointer_democracy | ||
// --extrinsic=* | ||
// --wasm-execution=compiled | ||
// --heap-pages=4096 | ||
// --output=runtime/src/weights/pallet_encointer_democracy.rs | ||
// --template=/Users/pigu/Documents/code/encointer/encointer-node/scripts/frame-weight-template-full-info.hbs | ||
|
||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{ | ||
traits::Get, | ||
weights::{constants::RocksDbWeight, Weight}, | ||
}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weight functions needed for pallet_encointer_democracy. | ||
pub trait WeightInfo { | ||
fn submit_proposal() -> Weight; | ||
fn vote() -> Weight; | ||
fn update_proposal_state() -> Weight; | ||
} | ||
|
||
/// Weights for pallet_encointer_democracy using the Encointer solo chain node and recommended hardware. | ||
pub struct EncointerWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> WeightInfo for EncointerWeight<T> { | ||
fn submit_proposal() -> Weight { | ||
Weight::from_parts(40_000_000, 0) | ||
.saturating_add(T::DbWeight::get().reads(3)) | ||
.saturating_add(T::DbWeight::get().writes(3)) | ||
} | ||
fn vote() -> Weight { | ||
Weight::from_parts(168_000_000, 0) | ||
.saturating_add(T::DbWeight::get().reads(16)) | ||
.saturating_add(T::DbWeight::get().writes(5)) | ||
} | ||
fn update_proposal_state() -> Weight { | ||
Weight::from_parts(116_000_000, 0) | ||
.saturating_add(T::DbWeight::get().reads(9)) | ||
.saturating_add(T::DbWeight::get().writes(3)) | ||
} | ||
} | ||
|
||
// For tests | ||
impl WeightInfo for () { | ||
fn submit_proposal() -> Weight { | ||
Weight::from_parts(40_000_000, 0) | ||
.saturating_add(RocksDbWeight::get().reads(3)) | ||
.saturating_add(RocksDbWeight::get().writes(3)) | ||
} | ||
fn vote() -> Weight { | ||
Weight::from_parts(168_000_000, 0) | ||
.saturating_add(RocksDbWeight::get().reads(16)) | ||
.saturating_add(RocksDbWeight::get().writes(5)) | ||
} | ||
fn update_proposal_state() -> Weight { | ||
Weight::from_parts(116_000_000, 0) | ||
.saturating_add(RocksDbWeight::get().reads(9)) | ||
.saturating_add(RocksDbWeight::get().writes(3)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters