Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 17, 2022
1 parent 7695f7f commit f691c91
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 63 deletions.
9 changes: 8 additions & 1 deletion pallets/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@

use core::mem;
use frame_support::dispatch::{DispatchError, DispatchResult};
use frame_support::traits::Get;
use frame_support::traits::{Get, StorageInfo, StorageInfoTrait};
use frame_support::{decl_error, decl_module, ensure};
pub use polymesh_common_utilities::traits::base::{Config, Event};
use polymesh_primitives::checked_inc::CheckedInc;
use sp_std::vec::Vec;

decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
Expand Down Expand Up @@ -105,3 +106,9 @@ pub fn try_next_post<T: Config, I: CheckedInc>(seq: &mut I) -> Result<I, Dispatc
}

impl<T: Config> frame_support::traits::IntegrityTest for Module<T> {}

impl<T: Config> StorageInfoTrait for Module<T> {
fn storage_info() -> Vec<StorageInfo> {
Vec::new()
}
}
8 changes: 4 additions & 4 deletions pallets/committee/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
{
let bytes: [u8; 4] = n.to_be_bytes();
let padding = bytes.repeat(PROPOSAL_PADDING_WORDS);
let proposal = frame_system::Call::<T>::remark(padding).into();
let proposal = frame_system::Call::<T>::remark { remark: padding }.into();
let hash = <T as frame_system::Config>::Hashing::hash_of(&proposal);
(proposal, hash)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ benchmarks_instance! {
let n = 1;
let d = 2;
let origin = T::CommitteeOrigin::successful_origin();
let call = Call::<T, I>::set_vote_threshold(n, d);
let call = Call::<T, I>::set_vote_threshold { n, d };
}: {
call.dispatch_bypass_filter(origin).unwrap();
}
Expand All @@ -154,7 +154,7 @@ benchmarks_instance! {
let coordinator = dids.last().unwrap().clone();
Module::<T, I>::change_members_sorted(&dids, &[], &dids);
let origin = T::CommitteeOrigin::successful_origin();
let call = Call::<T, I>::set_release_coordinator(coordinator);
let call = Call::<T, I>::set_release_coordinator { id: coordinator };
}: {
call.dispatch_bypass_filter(origin).unwrap();
}
Expand All @@ -168,7 +168,7 @@ benchmarks_instance! {
set_expires_after {
let maybe_block = MaybeBlock::Some(1u32.into());
let origin = T::CommitteeOrigin::successful_origin();
let call = Call::<T, I>::set_expires_after(maybe_block);
let call = Call::<T, I>::set_expires_after { expiry: maybe_block };
}: {
call.dispatch_bypass_filter(origin).unwrap();
}
Expand Down
8 changes: 4 additions & 4 deletions pallets/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ use polymesh_common_utilities::{
traits::identity::{
AuthorizationNonce, Config, IdentityFnTrait, RawEvent, SecondaryKeyWithAuth,
},
SystematicIssuers, GC_DID, SYSTEMATIC_ISSUERS,
SystematicIssuers, GC_DID,
};
use polymesh_primitives::{
investor_zkproof_data::v1::InvestorZKProofData, secondary_key::api::LegacyPermissions,
Expand All @@ -127,7 +127,7 @@ use polymesh_primitives::{
Signatory, Ticker,
};
use sp_runtime::traits::Hash;
use sp_std::{convert::TryFrom, iter, prelude::*, vec};
use sp_std::{convert::TryFrom, prelude::*};

pub type Event<T> = polymesh_common_utilities::traits::identity::Event<T>;

Expand Down Expand Up @@ -197,7 +197,7 @@ decl_storage! {
// Secondary keys of identities at genesis. `identities` have to be initialised.
config(secondary_keys): Vec<(T::AccountId, IdentityId)>;
build(|config: &GenesisConfig<T>| {
SYSTEMATIC_ISSUERS
polymesh_common_utilities::SYSTEMATIC_ISSUERS
.iter()
.copied()
.for_each(<Module<T>>::register_systematic_id);
Expand Down Expand Up @@ -234,7 +234,7 @@ decl_storage! {
<Module<T>>::link_account_key_to_did(secondary_account_id, did);
let sk = SecondaryKey::from_account_id(secondary_account_id.clone());
<DidRecords<T>>::mutate(did, |record| {
(*record).add_secondary_keys(iter::once(sk.clone()));
(*record).add_secondary_keys(core::iter::once(sk.clone()));
});
<Module<T>>::deposit_event(RawEvent::SecondaryKeysAdded(did, vec![sk.into()]));
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/multisig/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use polymesh_common_utilities::{

pub type MultiSig<T> = crate::Module<T>;
pub type Identity<T> = identity::Module<T>;
pub type Timestamp<T> = pallet_timestamp::Module<T>;
pub type Timestamp<T> = pallet_timestamp::Pallet<T>;

fn generate_signers<T: Config + TestUtilsFn<AccountIdOf<T>>>(
signers: &mut Vec<Signatory<T::AccountId>>,
Expand Down Expand Up @@ -134,7 +134,7 @@ fn generate_multisig_and_proposal_for_alice<T: Config + TestUtilsFn<AccountIdOf<
let (alice, multisig, signers, signer_origin, _) =
generate_multisig_for_alice::<T>(total_signers, signers_required).unwrap();
let proposal_id = <MultiSig<T>>::ms_tx_done(multisig.clone());
let proposal = Box::new(frame_system::Call::<T>::remark(vec![]).into());
let proposal = Box::new(frame_system::Call::<T>::remark { remark: vec![] }.into());
Ok((
alice,
multisig.clone(),
Expand Down
38 changes: 21 additions & 17 deletions pallets/pips/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn zeroize_deposit<T: Config>() {
/// Makes a proposal.
fn make_proposal<T: Config>() -> (Box<T::Proposal>, Url, PipDescription) {
let content = vec![b'X'; PROPOSAL_PADDING_LEN];
let proposal = Box::new(frame_system::Call::<T>::remark(content).into());
let proposal = Box::new(frame_system::Call::<T>::remark { remark: content }.into());
let url = Url::try_from(vec![b'X'; URL_LEN].as_slice()).unwrap();
let description = PipDescription::try_from(vec![b'X'; DESCRIPTION_LEN].as_slice()).unwrap();
(proposal, url, description)
Expand Down Expand Up @@ -151,14 +151,13 @@ fn enact_call<T: Config>(num_approves: usize, num_rejects: usize, num_skips: usi
.chain(iter::repeat(SnapshotResult::Skip).take(num_skips))
.collect();
snapshot_results.shuffle(&mut rng);
Call::<T>::enact_snapshot_results(
Module::<T>::snapshot_queue()
.iter()
.rev()
.map(|s| s.id)
.zip(snapshot_results.into_iter())
.collect(),
)
let results = Module::<T>::snapshot_queue()
.iter()
.rev()
.map(|s| s.id)
.zip(snapshot_results.into_iter())
.collect();
Call::<T>::enact_snapshot_results { results }
}

fn propose_verify<T: Config>(url: Url, description: PipDescription) -> DispatchResult {
Expand Down Expand Up @@ -257,7 +256,7 @@ benchmarks! {
zeroize_deposit::<T>();
let some_url = Some(url.clone());
let some_desc = Some(description.clone());
let call = Call::<T>::propose(proposal, 0u32.into(), some_url, some_desc);
let call = Call::<T>::propose { proposal, deposit: 0u32.into(), url: some_url, description: some_desc };
}: {
call.dispatch_bypass_filter(origin).unwrap();
}
Expand Down Expand Up @@ -301,11 +300,16 @@ benchmarks! {
let proposer_did = SystematicIssuers::Committee.as_id();
identity::CurrentDid::put(proposer_did);
zeroize_deposit::<T>();
let propose_call = Call::<T>::propose(proposal, 0u32.into(), Some(url.clone()), Some(description.clone()));
let propose_call = Call::<T>::propose {
proposal,
deposit: 0u32.into(),
url: Some(url.clone()),
description: Some(description.clone())
};
propose_call.dispatch_bypass_filter(proposer_origin).unwrap();
let origin = T::VotingMajorityOrigin::successful_origin();
let id = PipId(0);
let call = Call::<T>::approve_committee_proposal(id);
let call = Call::<T>::approve_committee_proposal { id };
}: {
call.dispatch_bypass_filter(origin).unwrap();
}
Expand All @@ -330,7 +334,7 @@ benchmarks! {
let id = PipId(0);
assert_eq!(deposit, Deposits::<T>::get(id, &user.account()).amount, "incorrect deposit in reject_proposal");
let vmo_origin = T::VotingMajorityOrigin::successful_origin();
let call = Call::<T>::reject_proposal(id);
let call = Call::<T>::reject_proposal { id };
}: {
call.dispatch_bypass_filter(vmo_origin).unwrap();
}
Expand All @@ -353,9 +357,9 @@ benchmarks! {
).unwrap();
let id = PipId(0);
let vmo_origin = T::VotingMajorityOrigin::successful_origin();
let reject_call = Call::<T>::reject_proposal(id);
let reject_call = Call::<T>::reject_proposal { id };
reject_call.dispatch_bypass_filter(vmo_origin.clone()).unwrap();
let call = Call::<T>::prune_proposal(id);
let call = Call::<T>::prune_proposal { id };
}: {
call.dispatch_bypass_filter(vmo_origin).unwrap();
}
Expand All @@ -380,9 +384,9 @@ benchmarks! {
T::GovernanceCommittee::bench_set_release_coordinator(user.did());
Module::<T>::snapshot(user.origin().into()).unwrap();
let vmo_origin = T::VotingMajorityOrigin::successful_origin();
let enact_call = Call::<T>::enact_snapshot_results(vec![(id, SnapshotResult::Approve)]);
let enact_call = Call::<T>::enact_snapshot_results { results: vec![(id, SnapshotResult::Approve)] };
enact_call.dispatch_bypass_filter(vmo_origin).unwrap();
let future_block = frame_system::Module::<T>::block_number() + 100u32.into();
let future_block = frame_system::Pallet::<T>::block_number() + 100u32.into();
let origin = user.origin();
}: _(origin, id, Some(future_block))
verify {
Expand Down
1 change: 0 additions & 1 deletion pallets/protocol-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use polymesh_common_utilities::protocol_fee::ProtocolOp;
use polymesh_primitives::PosRatio;
use sp_std::prelude::*;

benchmarks! {
change_coefficient {
Expand Down
1 change: 0 additions & 1 deletion pallets/relayer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use polymesh_common_utilities::{
benchs::{user, AccountIdOf, User},
traits::{relayer::Config, TestUtilsFn},
};
use sp_std::prelude::*;

type Relayer<T> = crate::Module<T>;

Expand Down
14 changes: 7 additions & 7 deletions pallets/runtime/develop/src/benchmarks/pallet_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
// Modified by Polymath Inc - 4th January 2021
// - It uses our Staking pallet.

#![cfg_attr(not(feature = "std"), no_std)]

use core::convert::TryInto;
use frame_benchmarking::benchmarks;
use frame_support::traits::{Currency, OnInitialize};
use frame_system::RawOrigin;
use pallet_session::{Module as Session, *};
use pallet_session::{Call, Pallet as Session};
use pallet_staking::{
benchmarking::create_validator_with_nominators_with_balance, MAX_NOMINATIONS,
};
Expand All @@ -37,15 +35,15 @@ use sp_std::vec;

use polymesh_common_utilities::constants::currency::POLY;

pub struct Module<T: Config>(pallet_session::Module<T>);
pub struct Pallet<T: Config>(Session<T>);
pub trait Config:
pallet_session::Config + pallet_session::historical::Config + pallet_staking::Config
{
}

impl<T: Config> OnInitialize<T::BlockNumber> for Module<T> {
impl<T: Config> OnInitialize<T::BlockNumber> for Pallet<T> {
fn on_initialize(n: T::BlockNumber) -> frame_support::weights::Weight {
pallet_session::Module::<T>::on_initialize(n)
Session::<T>::on_initialize(n)
}
}

Expand Down Expand Up @@ -99,8 +97,10 @@ benchmarks! {
set_keys {
let n = MAX_NOMINATIONS as u32;
let validator = ValidatorInfo::<T>::build(n).unwrap();
let proof = validator.proof.clone();
let keys = validator.keys.clone();

}: _(RawOrigin::Signed(validator.controller), validator.keys, validator.proof)
}: _(RawOrigin::Signed(validator.controller), keys, proof)

purge_keys {
let n = MAX_NOMINATIONS as u32;
Expand Down
Loading

0 comments on commit f691c91

Please sign in to comment.