mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 06:31:09 +00:00
Benchmark Democracy Pallet (#5257)
* Add origin bounds to benchmark macro. * Add democracy benchmark. * Fix tests * Remove collective from frame/benchmarking, partially use EnsureOrigin. * Remove collective stuff. * Make previous benches compile again. * Remove comments. * Make prev bench to work again. * Add remove votes. * Add new proxy calls. * Add runtime-benchmarks guard to EnsureOrigin and implementations. * Refactor. * Add missing import. * Remove duplicated import * Fix features. * Add some missing features. * Update frame/collective/Cargo.toml Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/democracy/src/benchmarking.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/democracy/src/benchmarking.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add referendums to state. * populate vecs before call * Update weight docs * More fixes and weight docs * More updates Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Generated
+1
@@ -4170,6 +4170,7 @@ dependencies = [
|
||||
name = "pallet-democracy"
|
||||
version = "2.0.0-alpha.5"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"hex-literal",
|
||||
|
||||
@@ -134,16 +134,20 @@ std = [
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking",
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-collective/runtime-benchmarks",
|
||||
"pallet-elections-phragmen/runtime-benchmarks",
|
||||
"pallet-identity/runtime-benchmarks",
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"pallet-treasury/runtime-benchmarks",
|
||||
"pallet-session-benchmarking",
|
||||
"pallet-staking/runtime-benchmarks",
|
||||
"pallet-vesting/runtime-benchmarks",
|
||||
"pallet-collective/runtime-benchmarks",
|
||||
"pallet-session-benchmarking",
|
||||
"pallet-staking/runtime-benchmarks",
|
||||
"pallet-society/runtime-benchmarks",
|
||||
"pallet-im-online/runtime-benchmarks",
|
||||
"pallet-democracy/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -919,6 +919,13 @@ impl_runtime_apis! {
|
||||
steps,
|
||||
repeat,
|
||||
),
|
||||
b"pallet-democracy" | b"democracy" => Democracy::run_benchmark(
|
||||
extrinsic,
|
||||
lowest_range_values,
|
||||
highest_range_values,
|
||||
steps,
|
||||
repeat,
|
||||
),
|
||||
b"pallet-collective" | b"collective" => Council::run_benchmark(
|
||||
extrinsic,
|
||||
lowest_range_values,
|
||||
|
||||
@@ -31,9 +31,12 @@ std = [
|
||||
"sp-std/std",
|
||||
"serde",
|
||||
"sp-io/std",
|
||||
"frame-benchmarking/std",
|
||||
"frame-support/std",
|
||||
"sp-runtime/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
runtime-benchmarks = ["frame-benchmarking"]
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -434,7 +434,7 @@ where
|
||||
pub struct EnsureMember<AccountId, I=DefaultInstance>(sp_std::marker::PhantomData<(AccountId, I)>);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
|
||||
AccountId,
|
||||
AccountId: Default,
|
||||
I,
|
||||
> EnsureOrigin<O> for EnsureMember<AccountId, I> {
|
||||
type Success = AccountId;
|
||||
@@ -444,6 +444,11 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Member(Default::default()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureMembers<N: U32, AccountId, I=DefaultInstance>(sp_std::marker::PhantomData<(N, AccountId, I)>);
|
||||
@@ -460,6 +465,11 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Members(N::VALUE, N::VALUE))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureProportionMoreThan<N: U32, D: U32, AccountId, I=DefaultInstance>(
|
||||
@@ -479,6 +489,11 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Members(1u32, 0u32))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureProportionAtLeast<N: U32, D: U32, AccountId, I=DefaultInstance>(
|
||||
@@ -498,6 +513,11 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Members(0u32, 0u32))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -14,6 +14,7 @@ codec = { package = "parity-scale-codec", version = "1.2.0", default-features =
|
||||
sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" }
|
||||
sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" }
|
||||
sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" }
|
||||
frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking", optional = true }
|
||||
frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" }
|
||||
frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" }
|
||||
|
||||
@@ -30,7 +31,13 @@ std = [
|
||||
"codec/std",
|
||||
"sp-std/std",
|
||||
"sp-io/std",
|
||||
"frame-benchmarking/std",
|
||||
"frame-support/std",
|
||||
"sp-runtime/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Democracy pallet benchmarking.
|
||||
|
||||
use super::*;
|
||||
|
||||
use frame_benchmarking::{benchmarks, account};
|
||||
use frame_support::traits::{Currency, Get};
|
||||
use frame_system::{RawOrigin, Module as System, self};
|
||||
use sp_runtime::traits::{Bounded, EnsureOrigin, One};
|
||||
|
||||
use crate::Module as Democracy;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
const MAX_USERS: u32 = 1000;
|
||||
const MAX_REFERENDUMS: u32 = 100;
|
||||
const MAX_PROPOSALS: u32 = 100;
|
||||
|
||||
fn funded_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
|
||||
let caller: T::AccountId = account(name, index, SEED);
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
caller
|
||||
}
|
||||
|
||||
fn add_proposal<T: Trait>(n: u32) -> Result<T::Hash, &'static str> {
|
||||
let other = funded_account::<T>("proposer", n);
|
||||
let value = T::MinimumDeposit::get();
|
||||
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
|
||||
|
||||
Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal_hash, value.into())?;
|
||||
|
||||
Ok(proposal_hash)
|
||||
}
|
||||
|
||||
fn add_referendum<T: Trait>(n: u32) -> Result<ReferendumIndex, &'static str> {
|
||||
let proposal_hash = add_proposal::<T>(n)?;
|
||||
let vote_threshold = VoteThreshold::SimpleMajority;
|
||||
|
||||
Democracy::<T>::inject_referendum(
|
||||
0.into(),
|
||||
proposal_hash,
|
||||
vote_threshold,
|
||||
0.into(),
|
||||
);
|
||||
let referendum_index: ReferendumIndex = ReferendumCount::get() - 1;
|
||||
Ok(referendum_index)
|
||||
}
|
||||
|
||||
fn account_vote<T: Trait>() -> AccountVote<BalanceOf<T>> {
|
||||
let v = Vote {
|
||||
aye: true,
|
||||
conviction: Conviction::Locked1x,
|
||||
};
|
||||
|
||||
AccountVote::Standard {
|
||||
vote: v,
|
||||
balance: BalanceOf::<T>::one(),
|
||||
}
|
||||
}
|
||||
|
||||
fn open_activate_proxy<T: Trait>(u: u32) -> Result<T::AccountId, &'static str> {
|
||||
let caller = funded_account::<T>("caller", u);
|
||||
let proxy = funded_account::<T>("proxy", u);
|
||||
|
||||
Democracy::<T>::open_proxy(RawOrigin::Signed(proxy.clone()).into(), caller.clone())?;
|
||||
Democracy::<T>::activate_proxy(RawOrigin::Signed(caller).into(), proxy.clone())?;
|
||||
|
||||
Ok(proxy)
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
_ { }
|
||||
|
||||
propose {
|
||||
let p in 1 .. MAX_PROPOSALS;
|
||||
|
||||
// Add p proposals
|
||||
for i in 0..p {
|
||||
add_proposal::<T>(i)?;
|
||||
}
|
||||
|
||||
let caller = funded_account::<T>("caller", 0);
|
||||
let proposal_hash: T::Hash = T::Hashing::hash_of(&p);
|
||||
let value = T::MinimumDeposit::get();
|
||||
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
|
||||
|
||||
second {
|
||||
let s in 0 .. 100;
|
||||
|
||||
// Create s existing "seconds"
|
||||
for i in 0..s {
|
||||
let seconder = funded_account::<T>("seconder", i);
|
||||
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?;
|
||||
}
|
||||
|
||||
let caller = funded_account::<T>("caller", 0);
|
||||
let proposal_hash = add_proposal::<T>(s)?;
|
||||
}: _(RawOrigin::Signed(caller), 0)
|
||||
|
||||
vote {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let caller = funded_account::<T>("caller", 0);
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let referendum_index = r - 1;
|
||||
|
||||
}: _(RawOrigin::Signed(caller), referendum_index, account_vote)
|
||||
|
||||
proxy_vote {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let caller = funded_account::<T>("caller", r);
|
||||
let proxy = open_activate_proxy::<T>(r)?;
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let referendum_index = r - 1;
|
||||
|
||||
}: _(RawOrigin::Signed(proxy), referendum_index, account_vote)
|
||||
|
||||
emergency_cancel {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let referendum_index = add_referendum::<T>(u)?;
|
||||
let origin = T::CancellationOrigin::successful_origin();
|
||||
let call = Call::<T>::emergency_cancel(referendum_index);
|
||||
}: {
|
||||
let _ = call.dispatch(origin)?;
|
||||
}
|
||||
|
||||
external_propose {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let origin = T::ExternalOrigin::successful_origin();
|
||||
let proposal_hash = T::Hashing::hash_of(&u);
|
||||
let call = Call::<T>::external_propose(proposal_hash);
|
||||
}: {
|
||||
let _ = call.dispatch(origin)?;
|
||||
}
|
||||
|
||||
external_propose_majority {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let origin = T::ExternalMajorityOrigin::successful_origin();
|
||||
let proposal_hash = T::Hashing::hash_of(&u);
|
||||
let call = Call::<T>::external_propose_majority(proposal_hash);
|
||||
|
||||
}: {
|
||||
let _ = call.dispatch(origin)?;
|
||||
}
|
||||
|
||||
external_propose_default {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let origin = T::ExternalDefaultOrigin::successful_origin();
|
||||
let proposal_hash = T::Hashing::hash_of(&u);
|
||||
let call = Call::<T>::external_propose_default(proposal_hash);
|
||||
|
||||
}: {
|
||||
let _ = call.dispatch(origin)?;
|
||||
}
|
||||
|
||||
fast_track {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
|
||||
let proposal_hash: T::Hash = T::Hashing::hash_of(&u);
|
||||
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;
|
||||
|
||||
let origin_fast_track = T::FastTrackOrigin::successful_origin();
|
||||
let voting_period = T::FastTrackVotingPeriod::get();
|
||||
let delay = 0;
|
||||
let call = Call::<T>::fast_track(proposal_hash, voting_period.into(), delay.into());
|
||||
|
||||
}: {
|
||||
let _ = call.dispatch(origin_fast_track)?;
|
||||
}
|
||||
|
||||
veto_external {
|
||||
// Existing veto-ers
|
||||
let v in 0 .. 100;
|
||||
|
||||
let proposal_hash: T::Hash = T::Hashing::hash_of(&v);
|
||||
|
||||
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
|
||||
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;
|
||||
|
||||
let mut vetoers: Vec<T::AccountId> = Vec::new();
|
||||
for i in 0..v {
|
||||
vetoers.push(account("vetoer", i, SEED));
|
||||
}
|
||||
Blacklist::<T>::insert(proposal_hash, (T::BlockNumber::zero(), vetoers));
|
||||
|
||||
let call = Call::<T>::veto_external(proposal_hash);
|
||||
let origin = T::VetoOrigin::successful_origin();
|
||||
}: {
|
||||
let _ = call.dispatch(origin)?;
|
||||
}
|
||||
|
||||
cancel_referendum {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let referendum_index = add_referendum::<T>(u)?;
|
||||
}: _(RawOrigin::Root, referendum_index)
|
||||
|
||||
cancel_queued {
|
||||
let d in 0 .. 100;
|
||||
|
||||
let referendum_index = add_referendum::<T>(d)?;
|
||||
let block_number: T::BlockNumber = 0.into();
|
||||
let hash: T::Hash = T::Hashing::hash_of(&d);
|
||||
<DispatchQueue<T>>::put(vec![(block_number, hash, referendum_index.clone()); d as usize]);
|
||||
}: _(RawOrigin::Root, referendum_index)
|
||||
|
||||
open_proxy {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let caller: T::AccountId = funded_account::<T>("caller", u);
|
||||
let proxy: T::AccountId = funded_account::<T>("proxy", u);
|
||||
|
||||
}: _(RawOrigin::Signed(proxy), caller)
|
||||
|
||||
activate_proxy {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let caller: T::AccountId = funded_account::<T>("caller", u);
|
||||
let proxy: T::AccountId = funded_account::<T>("proxy", u);
|
||||
Democracy::<T>::open_proxy(RawOrigin::Signed(proxy.clone()).into(), caller.clone())?;
|
||||
|
||||
}: _(RawOrigin::Signed(caller), proxy)
|
||||
|
||||
close_proxy {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let proxy = open_activate_proxy::<T>(u)?;
|
||||
|
||||
}: _(RawOrigin::Signed(proxy))
|
||||
|
||||
deactivate_proxy {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let caller = funded_account::<T>("caller", u);
|
||||
let proxy = open_activate_proxy::<T>(u)?;
|
||||
|
||||
}: _(RawOrigin::Signed(caller), proxy)
|
||||
|
||||
delegate {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let caller = funded_account::<T>("caller", u);
|
||||
let d: T::AccountId = funded_account::<T>("delegate", u);
|
||||
let balance = 1u32;
|
||||
|
||||
}: _(RawOrigin::Signed(caller), d.into(), Conviction::Locked1x, balance.into())
|
||||
|
||||
undelegate {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let other = funded_account::<T>("other", 0);
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(other.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let delegator = funded_account::<T>("delegator", r);
|
||||
let conviction = Conviction::Locked1x;
|
||||
let balance = 1u32;
|
||||
|
||||
Democracy::<T>::delegate(RawOrigin::Signed(delegator.clone()).into(), other.clone().into(), conviction, balance.into())?;
|
||||
|
||||
}: _(RawOrigin::Signed(delegator))
|
||||
|
||||
clear_public_proposals {
|
||||
let p in 0 .. 100;
|
||||
for i in 0 .. p {
|
||||
add_proposal::<T>(i)?;
|
||||
}
|
||||
}: _(RawOrigin::Root)
|
||||
|
||||
note_preimage {
|
||||
// Num of bytes in encoded proposal
|
||||
let b in 0 .. 16_384;
|
||||
|
||||
let caller = funded_account::<T>("caller", b);
|
||||
let encoded_proposal = vec![0; b as usize];
|
||||
}: _(RawOrigin::Signed(caller), encoded_proposal)
|
||||
|
||||
note_imminent_preimage {
|
||||
// Num of bytes in encoded proposal
|
||||
let b in 0 .. 16_384;
|
||||
// Length of dispatch queue
|
||||
let d in 0 .. 100;
|
||||
|
||||
let mut dispatch_queue = Vec::new();
|
||||
// d + 1 to include the one we are testing
|
||||
for i in 0 .. d + 1 {
|
||||
let encoded_proposal = vec![0; i as usize];
|
||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||
let block_number = T::BlockNumber::zero();
|
||||
let referendum_index: ReferendumIndex = 0;
|
||||
dispatch_queue.push((block_number, proposal_hash, referendum_index))
|
||||
}
|
||||
<DispatchQueue<T>>::put(dispatch_queue);
|
||||
|
||||
let caller = funded_account::<T>("caller", b);
|
||||
let encoded_proposal = vec![0; d as usize];
|
||||
}: _(RawOrigin::Signed(caller), encoded_proposal)
|
||||
|
||||
reap_preimage {
|
||||
// Num of bytes in encoded proposal
|
||||
let b in 0 .. 16_384;
|
||||
// Length of dispatch queue
|
||||
let d in 0 .. 100;
|
||||
|
||||
let mut dispatch_queue = Vec::new();
|
||||
for i in 0 .. d {
|
||||
let encoded_proposal = vec![0; i as usize];
|
||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||
let block_number = T::BlockNumber::zero();
|
||||
let referendum_index: ReferendumIndex = 0;
|
||||
dispatch_queue.push((block_number, proposal_hash, referendum_index))
|
||||
}
|
||||
<DispatchQueue<T>>::put(dispatch_queue);
|
||||
|
||||
let caller = funded_account::<T>("caller", d);
|
||||
let encoded_proposal = vec![0; d as usize];
|
||||
Democracy::<T>::note_preimage(RawOrigin::Signed(caller.clone()).into(), encoded_proposal.clone())?;
|
||||
|
||||
// We need to set this otherwise we get `Early` error.
|
||||
let block_number = T::VotingPeriod::get() + T::EnactmentPeriod::get() + T::BlockNumber::one();
|
||||
System::<T>::set_block_number(block_number.into());
|
||||
|
||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||
|
||||
}: _(RawOrigin::Signed(caller), proposal_hash)
|
||||
|
||||
unlock {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let caller = funded_account::<T>("caller", u);
|
||||
let locked_until = T::BlockNumber::zero();
|
||||
Locks::<T>::insert(&caller, locked_until);
|
||||
|
||||
T::Currency::extend_lock(
|
||||
DEMOCRACY_ID,
|
||||
&caller,
|
||||
Bounded::max_value(),
|
||||
WithdrawReason::Transfer.into()
|
||||
);
|
||||
|
||||
let other = caller.clone();
|
||||
|
||||
}: _(RawOrigin::Signed(caller), other)
|
||||
|
||||
remove_vote {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let caller = funded_account::<T>("caller", 0);
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let referendum_index = r - 1;
|
||||
|
||||
}: _(RawOrigin::Signed(caller), referendum_index)
|
||||
|
||||
remove_other_vote {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let other = funded_account::<T>("other", r);
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(other.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let referendum_index = r - 1;
|
||||
ReferendumInfoOf::<T>::insert(
|
||||
referendum_index,
|
||||
ReferendumInfo::Finished { end: T::BlockNumber::zero(), approved: true }
|
||||
);
|
||||
let caller = funded_account::<T>("caller", r);
|
||||
|
||||
System::<T>::set_block_number(T::EnactmentPeriod::get() * 10u32.into());
|
||||
|
||||
}: _(RawOrigin::Signed(caller), other, referendum_index)
|
||||
|
||||
proxy_delegate {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let other: T::AccountId = account("other", u, SEED);
|
||||
let proxy = open_activate_proxy::<T>(u)?;
|
||||
let conviction = Conviction::Locked1x;
|
||||
let balance = 1u32;
|
||||
|
||||
}: _(RawOrigin::Signed(proxy), other, conviction, balance.into())
|
||||
|
||||
proxy_undelegate {
|
||||
let r in 1 .. MAX_REFERENDUMS;
|
||||
|
||||
let other = funded_account::<T>("other", 0);
|
||||
let account_vote = account_vote::<T>();
|
||||
|
||||
for i in 0 .. r {
|
||||
let ref_idx = add_referendum::<T>(i)?;
|
||||
Democracy::<T>::vote(RawOrigin::Signed(other.clone()).into(), ref_idx, account_vote.clone())?;
|
||||
}
|
||||
|
||||
let proxy = open_activate_proxy::<T>(r)?;
|
||||
let conviction = Conviction::Locked1x;
|
||||
let balance = 1u32;
|
||||
Democracy::<T>::proxy_delegate(RawOrigin::Signed(proxy.clone()).into(), other, conviction, balance.into())?;
|
||||
|
||||
}: _(RawOrigin::Signed(proxy))
|
||||
|
||||
proxy_remove_vote {
|
||||
let u in 1 .. MAX_USERS;
|
||||
|
||||
let referendum_index = add_referendum::<T>(u)?;
|
||||
let account_vote = account_vote::<T>();
|
||||
let proxy = open_activate_proxy::<T>(u)?;
|
||||
|
||||
Democracy::<T>::proxy_vote(RawOrigin::Signed(proxy.clone()).into(), referendum_index, account_vote)?;
|
||||
|
||||
}: _(RawOrigin::Signed(proxy), referendum_index)
|
||||
}
|
||||
@@ -190,6 +190,9 @@ pub use types::{ReferendumInfo, ReferendumStatus, ProxyState, Tally, UnvoteScope
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub mod benchmarking;
|
||||
|
||||
const DEMOCRACY_ID: LockIdentifier = *b"democrac";
|
||||
|
||||
/// A proposal index.
|
||||
@@ -516,7 +519,8 @@ decl_module! {
|
||||
/// Emits `Proposed`.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// - `O(P)`
|
||||
/// - P is the number proposals in the `PublicProps` vec.
|
||||
/// - Two DB changes, one DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
|
||||
@@ -546,7 +550,8 @@ decl_module! {
|
||||
/// - `proposal`: The index of the proposal to second.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// - `O(S)`.
|
||||
/// - S is the number of seconds a proposal already has.
|
||||
/// - One DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
|
||||
@@ -568,7 +573,8 @@ decl_module! {
|
||||
/// - `vote`: The vote configuration.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// - `O(R)`.
|
||||
/// - R is the number of referendums the voter has voted on.
|
||||
/// - One DB change, one DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
|
||||
@@ -610,7 +616,7 @@ decl_module! {
|
||||
/// -`ref_index`: The index of the referendum to cancel.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Depends on size of storage vec `VotersFor` for this referendum.
|
||||
/// - `O(1)`.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(500_000)]
|
||||
fn emergency_cancel(origin, ref_index: ReferendumIndex) {
|
||||
@@ -756,6 +762,7 @@ decl_module! {
|
||||
/// - One DB clear.
|
||||
/// - Performs a binary search on `existing_vetoers` which should not
|
||||
/// be very large.
|
||||
/// - O(log v), v is number of `existing_vetoers`
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
|
||||
fn veto_external(origin, proposal_hash: T::Hash) {
|
||||
@@ -804,6 +811,7 @@ decl_module! {
|
||||
///
|
||||
/// # <weight>
|
||||
/// - One DB change.
|
||||
/// - O(d) where d is the items in the dispatch queue.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(10_000)]
|
||||
fn cancel_queued(origin, which: ReferendumIndex) {
|
||||
@@ -993,7 +1001,7 @@ decl_module! {
|
||||
/// Emits `PreimageNoted`.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Dependent on the size of `encoded_proposal`.
|
||||
/// - Dependent on the size of `encoded_proposal` and length of dispatch queue.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
|
||||
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) {
|
||||
|
||||
@@ -34,3 +34,7 @@ std = [
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -1145,6 +1145,12 @@ impl<T: Trait> EnsureOrigin<T::Origin> for EnsureFounder<T> {
|
||||
(r, _) => Err(T::Origin::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> T::Origin {
|
||||
let founder = Founder::<T>::get().expect("society founder should exist");
|
||||
T::Origin::from(system::RawOrigin::Signed(founder))
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick an item at pseudo-random from the slice, given the `rng`. `None` iff the slice is empty.
|
||||
|
||||
@@ -54,5 +54,4 @@ std = [
|
||||
runtime-benchmarks = [
|
||||
"rand_chacha",
|
||||
"frame-benchmarking",
|
||||
"frame-system/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -14,7 +14,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.2.0", default-features = false, features = ["derive"] }
|
||||
frame-metadata = { version = "11.0.0-alpha.5", default-features = false, path = "../metadata" }
|
||||
sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" }
|
||||
sp-io = { path = "../../primitives/io", default-features = false , version = "2.0.0-alpha.5"}
|
||||
sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" }
|
||||
sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" }
|
||||
sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" }
|
||||
sp-arithmetic = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/arithmetic" }
|
||||
|
||||
@@ -36,7 +36,7 @@ std = [
|
||||
"sp-runtime/std",
|
||||
"sp-version/std",
|
||||
]
|
||||
runtime-benchmarks = []
|
||||
runtime-benchmarks = ["sp-runtime/runtime-benchmarks"]
|
||||
|
||||
[[bench]]
|
||||
name = "bench"
|
||||
|
||||
@@ -578,12 +578,17 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Root)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureSigned<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
||||
AccountId,
|
||||
AccountId: Default,
|
||||
> EnsureOrigin<O> for EnsureSigned<AccountId> {
|
||||
type Success = AccountId;
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
@@ -592,13 +597,18 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Signed(Default::default()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureSignedBy<Who, AccountId>(sp_std::marker::PhantomData<(Who, AccountId)>);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
||||
Who: Contains<AccountId>,
|
||||
AccountId: PartialEq + Clone + Ord,
|
||||
AccountId: PartialEq + Clone + Ord + Default,
|
||||
> EnsureOrigin<O> for EnsureSignedBy<Who, AccountId> {
|
||||
type Success = AccountId;
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
@@ -607,6 +617,13 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
let caller: AccountId = Default::default();
|
||||
// Who::add(&caller);
|
||||
O::from(RawOrigin::Signed(caller))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureNone<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
||||
@@ -621,6 +638,11 @@ impl<
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::None)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureNever<T>(sp_std::marker::PhantomData<T>);
|
||||
@@ -629,6 +651,11 @@ impl<O, T> EnsureOrigin<O> for EnsureNever<T> {
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
Err(o)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the origin `o` represents a signed extrinsic (i.e. transaction).
|
||||
|
||||
@@ -36,4 +36,4 @@ std = [
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
runtime-benchmarks = ["frame-benchmarking", "frame-system/runtime-benchmarks"]
|
||||
runtime-benchmarks = ["frame-benchmarking"]
|
||||
|
||||
@@ -32,6 +32,7 @@ rand = "0.7.2"
|
||||
|
||||
[features]
|
||||
bench = []
|
||||
runtime-benchmarks = []
|
||||
default = ["std"]
|
||||
std = [
|
||||
"sp-application-crypto/std",
|
||||
|
||||
@@ -157,6 +157,12 @@ pub trait EnsureOrigin<OuterOrigin> {
|
||||
}
|
||||
/// Perform the origin check.
|
||||
fn try_origin(o: OuterOrigin) -> result::Result<Self::Success, OuterOrigin>;
|
||||
|
||||
/// Returns an outer origin capable of passing `try_origin` check.
|
||||
///
|
||||
/// ** Should be used for benchmarking only!!! **
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> OuterOrigin;
|
||||
}
|
||||
|
||||
/// An error that indicates that a lookup failed.
|
||||
|
||||
Reference in New Issue
Block a user