mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 01:15:47 +00:00
Introduce cancel_proposal to rid us of those pesky proposals (#7111)
* Introduce `cancel_proposal` Also fix proposal weight. * Support proposal cancellation from runtime. * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fix benchmarks * fix benchmark * whitelisted caller weights * fix build * Fixes * Fixes * Fixes * Fixes * Update frame/democracy/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Fixes * Fixes * Fixes * Fixes * Fixes * doc updates * new weights Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -483,6 +483,7 @@ parameter_types! {
|
|||||||
// One cent: $10,000 / MB
|
// One cent: $10,000 / MB
|
||||||
pub const PreimageByteDeposit: Balance = 1 * CENTS;
|
pub const PreimageByteDeposit: Balance = 1 * CENTS;
|
||||||
pub const MaxVotes: u32 = 100;
|
pub const MaxVotes: u32 = 100;
|
||||||
|
pub const MaxProposals: u32 = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_democracy::Trait for Runtime {
|
impl pallet_democracy::Trait for Runtime {
|
||||||
@@ -508,6 +509,14 @@ impl pallet_democracy::Trait for Runtime {
|
|||||||
type FastTrackVotingPeriod = FastTrackVotingPeriod;
|
type FastTrackVotingPeriod = FastTrackVotingPeriod;
|
||||||
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
|
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
|
||||||
type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
|
type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
|
||||||
|
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
|
||||||
|
// Root must agree.
|
||||||
|
type CancelProposalOrigin = EnsureOneOf<
|
||||||
|
AccountId,
|
||||||
|
EnsureRoot<AccountId>,
|
||||||
|
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
|
||||||
|
>;
|
||||||
|
type BlacklistOrigin = EnsureRoot<AccountId>;
|
||||||
// Any single technical committee member may veto a coming council proposal, however they can
|
// Any single technical committee member may veto a coming council proposal, however they can
|
||||||
// only do it once and it lasts only for the cooloff period.
|
// only do it once and it lasts only for the cooloff period.
|
||||||
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
|
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
|
||||||
@@ -519,6 +528,7 @@ impl pallet_democracy::Trait for Runtime {
|
|||||||
type PalletsOrigin = OriginCaller;
|
type PalletsOrigin = OriginCaller;
|
||||||
type MaxVotes = MaxVotes;
|
type MaxVotes = MaxVotes;
|
||||||
type WeightInfo = weights::pallet_democracy::WeightInfo<Runtime>;
|
type WeightInfo = weights::pallet_democracy::WeightInfo<Runtime>;
|
||||||
|
type MaxProposals = MaxProposals;
|
||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
|
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -13,8 +15,12 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! Weights for the Democracy Pallet
|
//! Weights for pallet_democracy
|
||||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
|
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
|
||||||
|
//! DATE: 2020-09-24, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
|
||||||
|
|
||||||
|
#![allow(unused_parens)]
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use frame_support::{traits::Get, weights::Weight};
|
use frame_support::{traits::Get, weights::Weight};
|
||||||
use sp_std::marker::PhantomData;
|
use sp_std::marker::PhantomData;
|
||||||
@@ -22,134 +28,145 @@ use sp_std::marker::PhantomData;
|
|||||||
pub struct WeightInfo<T>(PhantomData<T>);
|
pub struct WeightInfo<T>(PhantomData<T>);
|
||||||
impl<T: frame_system::Trait> pallet_democracy::WeightInfo for WeightInfo<T> {
|
impl<T: frame_system::Trait> pallet_democracy::WeightInfo for WeightInfo<T> {
|
||||||
fn propose() -> Weight {
|
fn propose() -> Weight {
|
||||||
(49113000 as Weight)
|
(96_316_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn second(s: u32, ) -> Weight {
|
fn second(s: u32, ) -> Weight {
|
||||||
(42067000 as Weight)
|
(58_386_000 as Weight)
|
||||||
.saturating_add((220000 as Weight).saturating_mul(s as Weight))
|
.saturating_add((259_000 as Weight).saturating_mul(s as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn vote_new(r: u32, ) -> Weight {
|
fn vote_new(r: u32, ) -> Weight {
|
||||||
(54159000 as Weight)
|
(70_374_000 as Weight)
|
||||||
.saturating_add((252000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((291_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn vote_existing(r: u32, ) -> Weight {
|
fn vote_existing(r: u32, ) -> Weight {
|
||||||
(54145000 as Weight)
|
(70_097_000 as Weight)
|
||||||
.saturating_add((262000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((296_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn emergency_cancel() -> Weight {
|
fn emergency_cancel() -> Weight {
|
||||||
(31071000 as Weight)
|
(41_731_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
fn blacklist(p: u32, ) -> Weight {
|
||||||
|
(117_847_000 as Weight)
|
||||||
|
.saturating_add((871_000 as Weight).saturating_mul(p as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(6 as Weight))
|
||||||
|
}
|
||||||
fn external_propose(v: u32, ) -> Weight {
|
fn external_propose(v: u32, ) -> Weight {
|
||||||
(14282000 as Weight)
|
(20_972_000 as Weight)
|
||||||
.saturating_add((109000 as Weight).saturating_mul(v as Weight))
|
.saturating_add((114_000 as Weight).saturating_mul(v as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn external_propose_majority() -> Weight {
|
fn external_propose_majority() -> Weight {
|
||||||
(3478000 as Weight)
|
(5_030_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn external_propose_default() -> Weight {
|
fn external_propose_default() -> Weight {
|
||||||
(3442000 as Weight)
|
(4_981_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn fast_track() -> Weight {
|
fn fast_track() -> Weight {
|
||||||
(30820000 as Weight)
|
(42_801_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn veto_external(v: u32, ) -> Weight {
|
fn veto_external(v: u32, ) -> Weight {
|
||||||
(30971000 as Weight)
|
(44_115_000 as Weight)
|
||||||
.saturating_add((184000 as Weight).saturating_mul(v as Weight))
|
.saturating_add((194_000 as Weight).saturating_mul(v as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
fn cancel_proposal(p: u32, ) -> Weight {
|
||||||
|
(73_937_000 as Weight)
|
||||||
|
.saturating_add((962_000 as Weight).saturating_mul(p as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
|
}
|
||||||
fn cancel_referendum() -> Weight {
|
fn cancel_referendum() -> Weight {
|
||||||
(20431000 as Weight)
|
(25_233_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn cancel_queued(r: u32, ) -> Weight {
|
fn cancel_queued(r: u32, ) -> Weight {
|
||||||
(42438000 as Weight)
|
(48_251_000 as Weight)
|
||||||
.saturating_add((3284000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((3_590_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
fn on_initialize_base(r: u32, ) -> Weight {
|
fn on_initialize_base(r: u32, ) -> Weight {
|
||||||
(70826000 as Weight)
|
(17_597_000 as Weight)
|
||||||
.saturating_add((10716000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((7_248_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(6 as Weight))
|
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(T::DbWeight::get().writes(5 as Weight))
|
|
||||||
}
|
}
|
||||||
fn delegate(r: u32, ) -> Weight {
|
fn delegate(r: u32, ) -> Weight {
|
||||||
(72046000 as Weight)
|
(93_916_000 as Weight)
|
||||||
.saturating_add((7837000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((10_794_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
||||||
}
|
}
|
||||||
fn undelegate(r: u32, ) -> Weight {
|
fn undelegate(r: u32, ) -> Weight {
|
||||||
(41028000 as Weight)
|
(47_855_000 as Weight)
|
||||||
.saturating_add((7810000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((10_805_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
||||||
}
|
}
|
||||||
fn clear_public_proposals() -> Weight {
|
fn clear_public_proposals() -> Weight {
|
||||||
(3643000 as Weight)
|
(4_864_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn note_preimage(b: u32, ) -> Weight {
|
fn note_preimage(b: u32, ) -> Weight {
|
||||||
(46629000 as Weight)
|
(66_754_000 as Weight)
|
||||||
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((4_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn note_imminent_preimage(b: u32, ) -> Weight {
|
fn note_imminent_preimage(b: u32, ) -> Weight {
|
||||||
(31147000 as Weight)
|
(44_664_000 as Weight)
|
||||||
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn reap_preimage(b: u32, ) -> Weight {
|
fn reap_preimage(b: u32, ) -> Weight {
|
||||||
(42848000 as Weight)
|
(59_968_000 as Weight)
|
||||||
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn unlock_remove(r: u32, ) -> Weight {
|
fn unlock_remove(r: u32, ) -> Weight {
|
||||||
(45333000 as Weight)
|
(58_573_000 as Weight)
|
||||||
.saturating_add((171000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((131_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn unlock_set(r: u32, ) -> Weight {
|
fn unlock_set(r: u32, ) -> Weight {
|
||||||
(44424000 as Weight)
|
(53_831_000 as Weight)
|
||||||
.saturating_add((291000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((324_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn remove_vote(r: u32, ) -> Weight {
|
fn remove_vote(r: u32, ) -> Weight {
|
||||||
(28250000 as Weight)
|
(31_846_000 as Weight)
|
||||||
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((327_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
fn remove_other_vote(r: u32, ) -> Weight {
|
fn remove_other_vote(r: u32, ) -> Weight {
|
||||||
(28250000 as Weight)
|
(31_880_000 as Weight)
|
||||||
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((222_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,3 +219,12 @@ pub fn account<AccountId: Decode + Default>(name: &'static str, index: u32, seed
|
|||||||
pub fn whitelisted_caller<AccountId: Decode + Default>() -> AccountId {
|
pub fn whitelisted_caller<AccountId: Decode + Default>() -> AccountId {
|
||||||
account::<AccountId>("whitelisted_caller", 0, 0)
|
account::<AccountId>("whitelisted_caller", 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! whitelist_account {
|
||||||
|
($acc:ident) => {
|
||||||
|
frame_benchmarking::benchmarking::add_to_whitelist(
|
||||||
|
frame_system::Account::<T>::hashed_key_for(&$acc).into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use frame_benchmarking::{benchmarks, account};
|
use frame_benchmarking::{benchmarks, account, whitelist_account};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
IterableStorageMap,
|
IterableStorageMap,
|
||||||
traits::{Currency, Get, EnsureOrigin, OnInitialize, UnfilteredDispatchable, schedule::DispatchTime},
|
traits::{Currency, Get, EnsureOrigin, OnInitialize, UnfilteredDispatchable, schedule::DispatchTime},
|
||||||
@@ -30,7 +30,7 @@ use sp_runtime::traits::{Bounded, One};
|
|||||||
use crate::Module as Democracy;
|
use crate::Module as Democracy;
|
||||||
|
|
||||||
const SEED: u32 = 0;
|
const SEED: u32 = 0;
|
||||||
const MAX_REFERENDUMS: u32 = 100;
|
const MAX_REFERENDUMS: u32 = 99;
|
||||||
const MAX_SECONDERS: u32 = 100;
|
const MAX_SECONDERS: u32 = 100;
|
||||||
const MAX_BYTES: u32 = 16_384;
|
const MAX_BYTES: u32 = 16_384;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ fn add_proposal<T: Trait>(n: u32) -> Result<T::Hash, &'static str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_referendum<T: Trait>(n: u32) -> Result<ReferendumIndex, &'static str> {
|
fn add_referendum<T: Trait>(n: u32) -> Result<ReferendumIndex, &'static str> {
|
||||||
let proposal_hash = add_proposal::<T>(n)?;
|
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
|
||||||
let vote_threshold = VoteThreshold::SimpleMajority;
|
let vote_threshold = VoteThreshold::SimpleMajority;
|
||||||
|
|
||||||
Democracy::<T>::inject_referendum(
|
Democracy::<T>::inject_referendum(
|
||||||
@@ -100,12 +100,19 @@ benchmarks! {
|
|||||||
_ { }
|
_ { }
|
||||||
|
|
||||||
propose {
|
propose {
|
||||||
|
let p = T::MaxProposals::get();
|
||||||
|
|
||||||
|
for i in 0 .. (p - 1) {
|
||||||
|
add_proposal::<T>(i)?;
|
||||||
|
}
|
||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
|
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
|
||||||
let value = T::MinimumDeposit::get();
|
let value = T::MinimumDeposit::get();
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
|
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
|
||||||
verify {
|
verify {
|
||||||
assert_eq!(Democracy::<T>::public_props().len(), 1, "Proposals not created.");
|
assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
second {
|
second {
|
||||||
@@ -122,6 +129,7 @@ benchmarks! {
|
|||||||
|
|
||||||
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
|
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
|
||||||
assert_eq!(deposits.0.len(), (s + 1) as usize, "Seconds not recorded");
|
assert_eq!(deposits.0.len(), (s + 1) as usize, "Seconds not recorded");
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller), 0, u32::max_value())
|
}: _(RawOrigin::Signed(caller), 0, u32::max_value())
|
||||||
verify {
|
verify {
|
||||||
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
|
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
|
||||||
@@ -146,7 +154,7 @@ benchmarks! {
|
|||||||
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
||||||
|
|
||||||
let referendum_index = add_referendum::<T>(r)?;
|
let referendum_index = add_referendum::<T>(r)?;
|
||||||
|
whitelist_account!(caller);
|
||||||
}: vote(RawOrigin::Signed(caller.clone()), referendum_index, account_vote)
|
}: vote(RawOrigin::Signed(caller.clone()), referendum_index, account_vote)
|
||||||
verify {
|
verify {
|
||||||
let votes = match VotingOf::<T>::get(&caller) {
|
let votes = match VotingOf::<T>::get(&caller) {
|
||||||
@@ -179,6 +187,7 @@ benchmarks! {
|
|||||||
let referendum_index = Democracy::<T>::referendum_count() - 1;
|
let referendum_index = Democracy::<T>::referendum_count() - 1;
|
||||||
|
|
||||||
// This tests when a user changes a vote
|
// This tests when a user changes a vote
|
||||||
|
whitelist_account!(caller);
|
||||||
}: vote(RawOrigin::Signed(caller.clone()), referendum_index, new_vote)
|
}: vote(RawOrigin::Signed(caller.clone()), referendum_index, new_vote)
|
||||||
verify {
|
verify {
|
||||||
let votes = match VotingOf::<T>::get(&caller) {
|
let votes = match VotingOf::<T>::get(&caller) {
|
||||||
@@ -206,6 +215,31 @@ benchmarks! {
|
|||||||
assert!(Democracy::<T>::referendum_status(referendum_index).is_err());
|
assert!(Democracy::<T>::referendum_status(referendum_index).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blacklist {
|
||||||
|
let p in 1 .. T::MaxProposals::get();
|
||||||
|
|
||||||
|
// Place our proposal at the end to make sure it's worst case.
|
||||||
|
for i in 0 .. p - 1 {
|
||||||
|
add_proposal::<T>(i)?;
|
||||||
|
}
|
||||||
|
// We should really add a lot of seconds here, but we're not doing it elsewhere.
|
||||||
|
|
||||||
|
// Place our proposal in the external queue, too.
|
||||||
|
let hash = T::Hashing::hash_of(&0);
|
||||||
|
assert!(Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), hash.clone()).is_ok());
|
||||||
|
|
||||||
|
// Add a referendum of our proposal.
|
||||||
|
let referendum_index = add_referendum::<T>(0)?;
|
||||||
|
assert!(Democracy::<T>::referendum_status(referendum_index).is_ok());
|
||||||
|
|
||||||
|
let call = Call::<T>::blacklist(hash, Some(referendum_index));
|
||||||
|
let origin = T::BlacklistOrigin::successful_origin();
|
||||||
|
}: { call.dispatch_bypass_filter(origin)? }
|
||||||
|
verify {
|
||||||
|
// Referendum has been canceled
|
||||||
|
assert!(Democracy::<T>::referendum_status(referendum_index).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
// Worst case scenario, we external propose a previously blacklisted proposal
|
// Worst case scenario, we external propose a previously blacklisted proposal
|
||||||
external_propose {
|
external_propose {
|
||||||
let v in 1 .. MAX_VETOERS as u32;
|
let v in 1 .. MAX_VETOERS as u32;
|
||||||
@@ -287,6 +321,15 @@ benchmarks! {
|
|||||||
assert_eq!(new_vetoers.len(), (v + 1) as usize, "vetoers not added");
|
assert_eq!(new_vetoers.len(), (v + 1) as usize, "vetoers not added");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancel_proposal {
|
||||||
|
let p in 1 .. T::MaxProposals::get();
|
||||||
|
|
||||||
|
// Place our proposal at the end to make sure it's worst case.
|
||||||
|
for i in 0 .. p {
|
||||||
|
add_proposal::<T>(i)?;
|
||||||
|
}
|
||||||
|
}: _(RawOrigin::Root, 0)
|
||||||
|
|
||||||
cancel_referendum {
|
cancel_referendum {
|
||||||
let referendum_index = add_referendum::<T>(0)?;
|
let referendum_index = add_referendum::<T>(0)?;
|
||||||
}: _(RawOrigin::Root, referendum_index)
|
}: _(RawOrigin::Root, referendum_index)
|
||||||
@@ -301,7 +344,8 @@ benchmarks! {
|
|||||||
let referendum_index = add_referendum::<T>(r)?;
|
let referendum_index = add_referendum::<T>(r)?;
|
||||||
}: _(RawOrigin::Root, referendum_index)
|
}: _(RawOrigin::Root, referendum_index)
|
||||||
|
|
||||||
// Note that we have a separate benchmark for `launch_next`
|
// This measures the path of `launch_next` external. Not currently used as we simply
|
||||||
|
// assume the weight is `MaxBlockWeight` when executing.
|
||||||
#[extra]
|
#[extra]
|
||||||
on_initialize_external {
|
on_initialize_external {
|
||||||
let r in 0 .. MAX_REFERENDUMS;
|
let r in 0 .. MAX_REFERENDUMS;
|
||||||
@@ -341,6 +385,8 @@ benchmarks! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This measures the path of `launch_next` public. Not currently used as we simply
|
||||||
|
// assume the weight is `MaxBlockWeight` when executing.
|
||||||
#[extra]
|
#[extra]
|
||||||
on_initialize_public {
|
on_initialize_public {
|
||||||
let r in 1 .. MAX_REFERENDUMS;
|
let r in 1 .. MAX_REFERENDUMS;
|
||||||
@@ -352,6 +398,7 @@ benchmarks! {
|
|||||||
assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
|
assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
|
||||||
|
|
||||||
// Launch public
|
// Launch public
|
||||||
|
assert!(add_proposal::<T>(r).is_ok(), "proposal not created");
|
||||||
LastTabledWasExternal::put(true);
|
LastTabledWasExternal::put(true);
|
||||||
|
|
||||||
let block_number = T::LaunchPeriod::get();
|
let block_number = T::LaunchPeriod::get();
|
||||||
@@ -359,7 +406,7 @@ benchmarks! {
|
|||||||
}: { Democracy::<T>::on_initialize(block_number) }
|
}: { Democracy::<T>::on_initialize(block_number) }
|
||||||
verify {
|
verify {
|
||||||
// One extra because of next public
|
// One extra because of next public
|
||||||
assert_eq!(Democracy::<T>::referendum_count(), r + 1, "referenda not created");
|
assert_eq!(Democracy::<T>::referendum_count(), r + 1, "proposal not accepted");
|
||||||
|
|
||||||
// All should be finished
|
// All should be finished
|
||||||
for i in 0 .. r {
|
for i in 0 .. r {
|
||||||
@@ -437,6 +484,7 @@ benchmarks! {
|
|||||||
_ => return Err("Votes are not direct"),
|
_ => return Err("Votes are not direct"),
|
||||||
};
|
};
|
||||||
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller.clone()), new_delegate.clone(), Conviction::Locked1x, delegated_balance)
|
}: _(RawOrigin::Signed(caller.clone()), new_delegate.clone(), Conviction::Locked1x, delegated_balance)
|
||||||
verify {
|
verify {
|
||||||
let (target, balance) = match VotingOf::<T>::get(&caller) {
|
let (target, balance) = match VotingOf::<T>::get(&caller) {
|
||||||
@@ -488,6 +536,7 @@ benchmarks! {
|
|||||||
_ => return Err("Votes are not direct"),
|
_ => return Err("Votes are not direct"),
|
||||||
};
|
};
|
||||||
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller.clone()))
|
}: _(RawOrigin::Signed(caller.clone()))
|
||||||
verify {
|
verify {
|
||||||
// Voting should now be direct
|
// Voting should now be direct
|
||||||
@@ -508,6 +557,7 @@ benchmarks! {
|
|||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
let encoded_proposal = vec![1; b as usize];
|
let encoded_proposal = vec![1; b as usize];
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
|
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
|
||||||
verify {
|
verify {
|
||||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||||
@@ -529,6 +579,7 @@ benchmarks! {
|
|||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
let encoded_proposal = vec![1; b as usize];
|
let encoded_proposal = vec![1; b as usize];
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
|
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
|
||||||
verify {
|
verify {
|
||||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||||
@@ -555,6 +606,7 @@ benchmarks! {
|
|||||||
assert!(Preimages::<T>::contains_key(proposal_hash));
|
assert!(Preimages::<T>::contains_key(proposal_hash));
|
||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::max_value())
|
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::max_value())
|
||||||
verify {
|
verify {
|
||||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||||
@@ -577,6 +629,7 @@ benchmarks! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
|
whitelist_account!(caller);
|
||||||
}: unlock(RawOrigin::Signed(caller), locker.clone())
|
}: unlock(RawOrigin::Signed(caller), locker.clone())
|
||||||
verify {
|
verify {
|
||||||
// Note that we may want to add a `get_lock` api to actually verify
|
// Note that we may want to add a `get_lock` api to actually verify
|
||||||
@@ -614,6 +667,7 @@ benchmarks! {
|
|||||||
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), referendum_index)?;
|
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), referendum_index)?;
|
||||||
|
|
||||||
let caller = funded_account::<T>("caller", 0);
|
let caller = funded_account::<T>("caller", 0);
|
||||||
|
whitelist_account!(caller);
|
||||||
}: unlock(RawOrigin::Signed(caller), locker.clone())
|
}: unlock(RawOrigin::Signed(caller), locker.clone())
|
||||||
verify {
|
verify {
|
||||||
let votes = match VotingOf::<T>::get(&locker) {
|
let votes = match VotingOf::<T>::get(&locker) {
|
||||||
@@ -645,7 +699,7 @@ benchmarks! {
|
|||||||
assert_eq!(votes.len(), r as usize, "Votes not created");
|
assert_eq!(votes.len(), r as usize, "Votes not created");
|
||||||
|
|
||||||
let referendum_index = r - 1;
|
let referendum_index = r - 1;
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller.clone()), referendum_index)
|
}: _(RawOrigin::Signed(caller.clone()), referendum_index)
|
||||||
verify {
|
verify {
|
||||||
let votes = match VotingOf::<T>::get(&caller) {
|
let votes = match VotingOf::<T>::get(&caller) {
|
||||||
@@ -674,7 +728,7 @@ benchmarks! {
|
|||||||
assert_eq!(votes.len(), r as usize, "Votes not created");
|
assert_eq!(votes.len(), r as usize, "Votes not created");
|
||||||
|
|
||||||
let referendum_index = r - 1;
|
let referendum_index = r - 1;
|
||||||
|
whitelist_account!(caller);
|
||||||
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index)
|
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index)
|
||||||
verify {
|
verify {
|
||||||
let votes = match VotingOf::<T>::get(&caller) {
|
let votes = match VotingOf::<T>::get(&caller) {
|
||||||
@@ -765,6 +819,8 @@ mod tests {
|
|||||||
assert_ok!(test_benchmark_remove_other_vote::<Test>());
|
assert_ok!(test_benchmark_remove_other_vote::<Test>());
|
||||||
assert_ok!(test_benchmark_enact_proposal_execute::<Test>());
|
assert_ok!(test_benchmark_enact_proposal_execute::<Test>());
|
||||||
assert_ok!(test_benchmark_enact_proposal_slash::<Test>());
|
assert_ok!(test_benchmark_enact_proposal_slash::<Test>());
|
||||||
|
assert_ok!(test_benchmark_blacklist::<Test>());
|
||||||
|
assert_ok!(test_benchmark_cancel_proposal::<Test>());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,143 +15,156 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! Default weights for the Democracy Pallet
|
//! Weights for pallet_democracy
|
||||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
|
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
|
||||||
|
//! DATE: 2020-09-24, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
|
||||||
|
|
||||||
|
#![allow(unused_parens)]
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
|
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
|
||||||
|
|
||||||
/// Default implementation of weight, this is just from an example return, values may change
|
|
||||||
/// depending on the runtime. This is not meant to be used in production.
|
|
||||||
impl crate::WeightInfo for () {
|
impl crate::WeightInfo for () {
|
||||||
fn propose() -> Weight {
|
fn propose() -> Weight {
|
||||||
(49113000 as Weight)
|
(96_316_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn second(s: u32, ) -> Weight {
|
fn second(s: u32, ) -> Weight {
|
||||||
(42067000 as Weight)
|
(58_386_000 as Weight)
|
||||||
.saturating_add((220000 as Weight).saturating_mul(s as Weight))
|
.saturating_add((259_000 as Weight).saturating_mul(s as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(1 as Weight))
|
.saturating_add(DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn vote_new(r: u32, ) -> Weight {
|
fn vote_new(r: u32, ) -> Weight {
|
||||||
(54159000 as Weight)
|
(70_374_000 as Weight)
|
||||||
.saturating_add((252000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((291_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(3 as Weight))
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn vote_existing(r: u32, ) -> Weight {
|
fn vote_existing(r: u32, ) -> Weight {
|
||||||
(54145000 as Weight)
|
(70_097_000 as Weight)
|
||||||
.saturating_add((262000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((296_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(3 as Weight))
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn emergency_cancel() -> Weight {
|
fn emergency_cancel() -> Weight {
|
||||||
(31071000 as Weight)
|
(41_731_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
fn blacklist(p: u32, ) -> Weight {
|
||||||
|
(117_847_000 as Weight)
|
||||||
|
.saturating_add((871_000 as Weight).saturating_mul(p as Weight))
|
||||||
|
.saturating_add(DbWeight::get().reads(5 as Weight))
|
||||||
|
.saturating_add(DbWeight::get().writes(6 as Weight))
|
||||||
|
}
|
||||||
fn external_propose(v: u32, ) -> Weight {
|
fn external_propose(v: u32, ) -> Weight {
|
||||||
(14282000 as Weight)
|
(20_972_000 as Weight)
|
||||||
.saturating_add((109000 as Weight).saturating_mul(v as Weight))
|
.saturating_add((114_000 as Weight).saturating_mul(v as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn external_propose_majority() -> Weight {
|
fn external_propose_majority() -> Weight {
|
||||||
(3478000 as Weight)
|
(5_030_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn external_propose_default() -> Weight {
|
fn external_propose_default() -> Weight {
|
||||||
(3442000 as Weight)
|
(4_981_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn fast_track() -> Weight {
|
fn fast_track() -> Weight {
|
||||||
(30820000 as Weight)
|
(42_801_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn veto_external(v: u32, ) -> Weight {
|
fn veto_external(v: u32, ) -> Weight {
|
||||||
(30971000 as Weight)
|
(44_115_000 as Weight)
|
||||||
.saturating_add((184000 as Weight).saturating_mul(v as Weight))
|
.saturating_add((194_000 as Weight).saturating_mul(v as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
fn cancel_proposal(p: u32, ) -> Weight {
|
||||||
|
(73_937_000 as Weight)
|
||||||
|
.saturating_add((962_000 as Weight).saturating_mul(p as Weight))
|
||||||
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
|
}
|
||||||
fn cancel_referendum() -> Weight {
|
fn cancel_referendum() -> Weight {
|
||||||
(20431000 as Weight)
|
(25_233_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn cancel_queued(r: u32, ) -> Weight {
|
fn cancel_queued(r: u32, ) -> Weight {
|
||||||
(42438000 as Weight)
|
(48_251_000 as Weight)
|
||||||
.saturating_add((3284000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((3_590_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
fn on_initialize_base(r: u32, ) -> Weight {
|
fn on_initialize_base(r: u32, ) -> Weight {
|
||||||
(70826000 as Weight)
|
(17_597_000 as Weight)
|
||||||
.saturating_add((10716000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((7_248_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(6 as Weight))
|
.saturating_add(DbWeight::get().reads(5 as Weight))
|
||||||
.saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(DbWeight::get().writes(5 as Weight))
|
|
||||||
}
|
}
|
||||||
fn delegate(r: u32, ) -> Weight {
|
fn delegate(r: u32, ) -> Weight {
|
||||||
(72046000 as Weight)
|
(93_916_000 as Weight)
|
||||||
.saturating_add((7837000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((10_794_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(4 as Weight))
|
.saturating_add(DbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(DbWeight::get().writes(4 as Weight))
|
.saturating_add(DbWeight::get().writes(4 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
||||||
}
|
}
|
||||||
fn undelegate(r: u32, ) -> Weight {
|
fn undelegate(r: u32, ) -> Weight {
|
||||||
(41028000 as Weight)
|
(47_855_000 as Weight)
|
||||||
.saturating_add((7810000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((10_805_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
|
||||||
}
|
}
|
||||||
fn clear_public_proposals() -> Weight {
|
fn clear_public_proposals() -> Weight {
|
||||||
(3643000 as Weight)
|
(4_864_000 as Weight)
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn note_preimage(b: u32, ) -> Weight {
|
fn note_preimage(b: u32, ) -> Weight {
|
||||||
(46629000 as Weight)
|
(66_754_000 as Weight)
|
||||||
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((4_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(1 as Weight))
|
.saturating_add(DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn note_imminent_preimage(b: u32, ) -> Weight {
|
fn note_imminent_preimage(b: u32, ) -> Weight {
|
||||||
(31147000 as Weight)
|
(44_664_000 as Weight)
|
||||||
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(1 as Weight))
|
.saturating_add(DbWeight::get().reads(1 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn reap_preimage(b: u32, ) -> Weight {
|
fn reap_preimage(b: u32, ) -> Weight {
|
||||||
(42848000 as Weight)
|
(59_968_000 as Weight)
|
||||||
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
|
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(1 as Weight))
|
.saturating_add(DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn unlock_remove(r: u32, ) -> Weight {
|
fn unlock_remove(r: u32, ) -> Weight {
|
||||||
(45333000 as Weight)
|
(58_573_000 as Weight)
|
||||||
.saturating_add((171000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((131_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(3 as Weight))
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn unlock_set(r: u32, ) -> Weight {
|
fn unlock_set(r: u32, ) -> Weight {
|
||||||
(44424000 as Weight)
|
(53_831_000 as Weight)
|
||||||
.saturating_add((291000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((324_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(3 as Weight))
|
.saturating_add(DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(3 as Weight))
|
.saturating_add(DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn remove_vote(r: u32, ) -> Weight {
|
fn remove_vote(r: u32, ) -> Weight {
|
||||||
(28250000 as Weight)
|
(31_846_000 as Weight)
|
||||||
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((327_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
fn remove_other_vote(r: u32, ) -> Weight {
|
fn remove_other_vote(r: u32, ) -> Weight {
|
||||||
(28250000 as Weight)
|
(31_880_000 as Weight)
|
||||||
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
|
.saturating_add((222_000 as Weight).saturating_mul(r as Weight))
|
||||||
.saturating_add(DbWeight::get().reads(2 as Weight))
|
.saturating_add(DbWeight::get().reads(2 as Weight))
|
||||||
.saturating_add(DbWeight::get().writes(2 as Weight))
|
.saturating_add(DbWeight::get().writes(2 as Weight))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
DispatchResult, DispatchError, RuntimeDebug,
|
DispatchResult, DispatchError, RuntimeDebug,
|
||||||
traits::{Zero, Hash, Dispatchable, Saturating},
|
traits::{Zero, Hash, Dispatchable, Saturating, Bounded},
|
||||||
};
|
};
|
||||||
use codec::{Encode, Decode, Input};
|
use codec::{Encode, Decode, Input};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
@@ -208,12 +208,14 @@ pub trait WeightInfo {
|
|||||||
fn vote_new(r: u32, ) -> Weight;
|
fn vote_new(r: u32, ) -> Weight;
|
||||||
fn vote_existing(r: u32, ) -> Weight;
|
fn vote_existing(r: u32, ) -> Weight;
|
||||||
fn emergency_cancel() -> Weight;
|
fn emergency_cancel() -> Weight;
|
||||||
|
fn blacklist(p: u32, ) -> Weight;
|
||||||
fn external_propose(v: u32, ) -> Weight;
|
fn external_propose(v: u32, ) -> Weight;
|
||||||
fn external_propose_majority() -> Weight;
|
fn external_propose_majority() -> Weight;
|
||||||
fn external_propose_default() -> Weight;
|
fn external_propose_default() -> Weight;
|
||||||
fn fast_track() -> Weight;
|
fn fast_track() -> Weight;
|
||||||
fn veto_external(v: u32, ) -> Weight;
|
fn veto_external(v: u32, ) -> Weight;
|
||||||
fn cancel_referendum() -> Weight;
|
fn cancel_referendum() -> Weight;
|
||||||
|
fn cancel_proposal(p: u32, ) -> Weight;
|
||||||
fn cancel_queued(r: u32, ) -> Weight;
|
fn cancel_queued(r: u32, ) -> Weight;
|
||||||
fn on_initialize_base(r: u32, ) -> Weight;
|
fn on_initialize_base(r: u32, ) -> Weight;
|
||||||
fn delegate(r: u32, ) -> Weight;
|
fn delegate(r: u32, ) -> Weight;
|
||||||
@@ -285,6 +287,12 @@ pub trait Trait: frame_system::Trait + Sized {
|
|||||||
/// Origin from which any referendum may be cancelled in an emergency.
|
/// Origin from which any referendum may be cancelled in an emergency.
|
||||||
type CancellationOrigin: EnsureOrigin<Self::Origin>;
|
type CancellationOrigin: EnsureOrigin<Self::Origin>;
|
||||||
|
|
||||||
|
/// Origin from which proposals may be blacklisted.
|
||||||
|
type BlacklistOrigin: EnsureOrigin<Self::Origin>;
|
||||||
|
|
||||||
|
/// Origin from which a proposal may be cancelled and its backers slashed.
|
||||||
|
type CancelProposalOrigin: EnsureOrigin<Self::Origin>;
|
||||||
|
|
||||||
/// Origin for anyone able to veto proposals.
|
/// Origin for anyone able to veto proposals.
|
||||||
///
|
///
|
||||||
/// # Warning
|
/// # Warning
|
||||||
@@ -319,6 +327,9 @@ pub trait Trait: frame_system::Trait + Sized {
|
|||||||
|
|
||||||
/// Weight information for extrinsics in this pallet.
|
/// Weight information for extrinsics in this pallet.
|
||||||
type WeightInfo: WeightInfo;
|
type WeightInfo: WeightInfo;
|
||||||
|
|
||||||
|
/// The maximum number of public proposals that can exist at any time.
|
||||||
|
type MaxProposals: Get<u32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Encode, Decode, RuntimeDebug)]
|
#[derive(Clone, Encode, Decode, RuntimeDebug)]
|
||||||
@@ -414,8 +425,7 @@ decl_storage! {
|
|||||||
|
|
||||||
/// A record of who vetoed what. Maps proposal hash to a possible existent block number
|
/// A record of who vetoed what. Maps proposal hash to a possible existent block number
|
||||||
/// (until when it may not be resubmitted) and who vetoed it.
|
/// (until when it may not be resubmitted) and who vetoed it.
|
||||||
pub Blacklist get(fn blacklist):
|
pub Blacklist: map hasher(identity) T::Hash => Option<(T::BlockNumber, Vec<T::AccountId>)>;
|
||||||
map hasher(identity) T::Hash => Option<(T::BlockNumber, Vec<T::AccountId>)>;
|
|
||||||
|
|
||||||
/// Record of all proposals that have been subject to emergency cancellation.
|
/// Record of all proposals that have been subject to emergency cancellation.
|
||||||
pub Cancellations: map hasher(identity) T::Hash => bool;
|
pub Cancellations: map hasher(identity) T::Hash => bool;
|
||||||
@@ -472,6 +482,8 @@ decl_event! {
|
|||||||
PreimageReaped(Hash, AccountId, Balance, AccountId),
|
PreimageReaped(Hash, AccountId, Balance, AccountId),
|
||||||
/// An \[account\] has been unlocked successfully.
|
/// An \[account\] has been unlocked successfully.
|
||||||
Unlocked(AccountId),
|
Unlocked(AccountId),
|
||||||
|
/// A proposal \[hash\] has been blacklisted permanently.
|
||||||
|
Blacklisted(Hash),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,6 +556,10 @@ decl_error! {
|
|||||||
WrongUpperBound,
|
WrongUpperBound,
|
||||||
/// Maximum number of votes reached.
|
/// Maximum number of votes reached.
|
||||||
MaxVotesReached,
|
MaxVotesReached,
|
||||||
|
/// The provided witness data is wrong.
|
||||||
|
InvalidWitness,
|
||||||
|
/// Maximum number of proposals reached.
|
||||||
|
TooManyProposals,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,19 +607,28 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `Proposed`.
|
/// Emits `Proposed`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(p)`
|
||||||
/// - Complexity: `O(1)`
|
|
||||||
/// - Db reads: `PublicPropCount`, `PublicProps`
|
|
||||||
/// - Db writes: `PublicPropCount`, `PublicProps`, `DepositOf`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::propose()]
|
#[weight = T::WeightInfo::propose()]
|
||||||
fn propose(origin, proposal_hash: T::Hash, #[compact] value: BalanceOf<T>) {
|
fn propose(origin,
|
||||||
|
proposal_hash: T::Hash,
|
||||||
|
#[compact] value: BalanceOf<T>,
|
||||||
|
) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
ensure!(value >= T::MinimumDeposit::get(), Error::<T>::ValueLow);
|
ensure!(value >= T::MinimumDeposit::get(), Error::<T>::ValueLow);
|
||||||
|
|
||||||
T::Currency::reserve(&who, value)?;
|
|
||||||
|
|
||||||
let index = Self::public_prop_count();
|
let index = Self::public_prop_count();
|
||||||
|
let real_prop_count = PublicProps::<T>::decode_len().unwrap_or(0) as u32;
|
||||||
|
let max_proposals = T::MaxProposals::get();
|
||||||
|
ensure!(real_prop_count < max_proposals, Error::<T>::TooManyProposals);
|
||||||
|
|
||||||
|
if let Some((until, _)) = <Blacklist<T>>::get(proposal_hash) {
|
||||||
|
ensure!(
|
||||||
|
<frame_system::Module<T>>::block_number() >= until,
|
||||||
|
Error::<T>::ProposalBlacklisted,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
T::Currency::reserve(&who, value)?;
|
||||||
PublicPropCount::put(index + 1);
|
PublicPropCount::put(index + 1);
|
||||||
<DepositOf<T>>::insert(index, (&[&who][..], value));
|
<DepositOf<T>>::insert(index, (&[&who][..], value));
|
||||||
|
|
||||||
@@ -621,11 +646,7 @@ decl_module! {
|
|||||||
/// - `seconds_upper_bound`: an upper bound on the current number of seconds on this
|
/// - `seconds_upper_bound`: an upper bound on the current number of seconds on this
|
||||||
/// proposal. Extrinsic is weighted according to this value with no refund.
|
/// proposal. Extrinsic is weighted according to this value with no refund.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(S)` where S is the number of seconds a proposal already has.
|
||||||
/// - Complexity: `O(S)` where S is the number of seconds a proposal already has.
|
|
||||||
/// - Db reads: `DepositOf`
|
|
||||||
/// - Db writes: `DepositOf`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::second(*seconds_upper_bound)]
|
#[weight = T::WeightInfo::second(*seconds_upper_bound)]
|
||||||
fn second(origin, #[compact] proposal: PropIndex, #[compact] seconds_upper_bound: u32) {
|
fn second(origin, #[compact] proposal: PropIndex, #[compact] seconds_upper_bound: u32) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
@@ -648,12 +669,7 @@ decl_module! {
|
|||||||
/// - `ref_index`: The index of the referendum to vote for.
|
/// - `ref_index`: The index of the referendum to vote for.
|
||||||
/// - `vote`: The vote configuration.
|
/// - `vote`: The vote configuration.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R)` where R is the number of referendums the voter has voted on.
|
||||||
/// - Complexity: `O(R)` where R is the number of referendums the voter has voted on.
|
|
||||||
/// weight is charged as if maximum votes.
|
|
||||||
/// - Db reads: `ReferendumInfoOf`, `VotingOf`, `balances locks`
|
|
||||||
/// - Db writes: `ReferendumInfoOf`, `VotingOf`, `balances locks`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::vote_new(T::MaxVotes::get())
|
#[weight = T::WeightInfo::vote_new(T::MaxVotes::get())
|
||||||
.max(T::WeightInfo::vote_existing(T::MaxVotes::get()))]
|
.max(T::WeightInfo::vote_existing(T::MaxVotes::get()))]
|
||||||
fn vote(origin,
|
fn vote(origin,
|
||||||
@@ -671,11 +687,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// -`ref_index`: The index of the referendum to cancel.
|
/// -`ref_index`: The index of the referendum to cancel.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(1)`.
|
||||||
/// - Complexity: `O(1)`.
|
|
||||||
/// - Db reads: `ReferendumInfoOf`, `Cancellations`
|
|
||||||
/// - Db writes: `ReferendumInfoOf`, `Cancellations`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = (T::WeightInfo::emergency_cancel(), DispatchClass::Operational)]
|
#[weight = (T::WeightInfo::emergency_cancel(), DispatchClass::Operational)]
|
||||||
fn emergency_cancel(origin, ref_index: ReferendumIndex) {
|
fn emergency_cancel(origin, ref_index: ReferendumIndex) {
|
||||||
T::CancellationOrigin::ensure_origin(origin)?;
|
T::CancellationOrigin::ensure_origin(origin)?;
|
||||||
@@ -695,12 +707,8 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// - `proposal_hash`: The preimage hash of the proposal.
|
/// - `proposal_hash`: The preimage hash of the proposal.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(V)` with V number of vetoers in the blacklist of proposal.
|
||||||
/// - Complexity `O(V)` with V number of vetoers in the blacklist of proposal.
|
|
||||||
/// Decoding vec of length V. Charged as maximum
|
/// Decoding vec of length V. Charged as maximum
|
||||||
/// - Db reads: `NextExternal`, `Blacklist`
|
|
||||||
/// - Db writes: `NextExternal`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::external_propose(MAX_VETOERS)]
|
#[weight = T::WeightInfo::external_propose(MAX_VETOERS)]
|
||||||
fn external_propose(origin, proposal_hash: T::Hash) {
|
fn external_propose(origin, proposal_hash: T::Hash) {
|
||||||
T::ExternalOrigin::ensure_origin(origin)?;
|
T::ExternalOrigin::ensure_origin(origin)?;
|
||||||
@@ -724,10 +732,7 @@ decl_module! {
|
|||||||
/// Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
/// Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
||||||
/// pre-scheduled `external_propose` call.
|
/// pre-scheduled `external_propose` call.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(1)`
|
||||||
/// - Complexity: `O(1)`
|
|
||||||
/// - Db write: `NextExternal`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::external_propose_majority()]
|
#[weight = T::WeightInfo::external_propose_majority()]
|
||||||
fn external_propose_majority(origin, proposal_hash: T::Hash) {
|
fn external_propose_majority(origin, proposal_hash: T::Hash) {
|
||||||
T::ExternalMajorityOrigin::ensure_origin(origin)?;
|
T::ExternalMajorityOrigin::ensure_origin(origin)?;
|
||||||
@@ -744,10 +749,7 @@ decl_module! {
|
|||||||
/// Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
/// Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
||||||
/// pre-scheduled `external_propose` call.
|
/// pre-scheduled `external_propose` call.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(1)`
|
||||||
/// - Complexity: `O(1)`
|
|
||||||
/// - Db write: `NextExternal`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::external_propose_default()]
|
#[weight = T::WeightInfo::external_propose_default()]
|
||||||
fn external_propose_default(origin, proposal_hash: T::Hash) {
|
fn external_propose_default(origin, proposal_hash: T::Hash) {
|
||||||
T::ExternalDefaultOrigin::ensure_origin(origin)?;
|
T::ExternalDefaultOrigin::ensure_origin(origin)?;
|
||||||
@@ -768,12 +770,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `Started`.
|
/// Emits `Started`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(1)`
|
||||||
/// - Complexity: `O(1)`
|
|
||||||
/// - Db reads: `NextExternal`, `ReferendumCount`
|
|
||||||
/// - Db writes: `NextExternal`, `ReferendumCount`, `ReferendumInfoOf`
|
|
||||||
/// - Base Weight: 30.1 µs
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::fast_track()]
|
#[weight = T::WeightInfo::fast_track()]
|
||||||
fn fast_track(origin,
|
fn fast_track(origin,
|
||||||
proposal_hash: T::Hash,
|
proposal_hash: T::Hash,
|
||||||
@@ -818,12 +815,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `Vetoed`.
|
/// Emits `Vetoed`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(V + log(V))` where V is number of `existing vetoers`
|
||||||
/// - Complexity: `O(V + log(V))` where V is number of `existing vetoers`
|
|
||||||
/// Performs a binary search on `existing_vetoers` which should not be very large.
|
|
||||||
/// - Db reads: `NextExternal`, `Blacklist`
|
|
||||||
/// - Db writes: `NextExternal`, `Blacklist`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::veto_external(MAX_VETOERS)]
|
#[weight = T::WeightInfo::veto_external(MAX_VETOERS)]
|
||||||
fn veto_external(origin, proposal_hash: T::Hash) {
|
fn veto_external(origin, proposal_hash: T::Hash) {
|
||||||
let who = T::VetoOrigin::ensure_origin(origin)?;
|
let who = T::VetoOrigin::ensure_origin(origin)?;
|
||||||
@@ -854,10 +846,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// - `ref_index`: The index of the referendum to cancel.
|
/// - `ref_index`: The index of the referendum to cancel.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// # Weight: `O(1)`.
|
||||||
/// - Complexity: `O(1)`.
|
|
||||||
/// - Db writes: `ReferendumInfoOf`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::cancel_referendum()]
|
#[weight = T::WeightInfo::cancel_referendum()]
|
||||||
fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) {
|
fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
@@ -870,11 +859,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// - `which`: The index of the referendum to cancel.
|
/// - `which`: The index of the referendum to cancel.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(D)` where `D` is the items in the dispatch queue. Weighted as `D = 10`.
|
||||||
/// - `O(D)` where `D` is the items in the dispatch queue. Weighted as `D = 10`.
|
|
||||||
/// - Db reads: `scheduler lookup`, scheduler agenda`
|
|
||||||
/// - Db writes: `scheduler lookup`, scheduler agenda`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = (T::WeightInfo::cancel_queued(10), DispatchClass::Operational)]
|
#[weight = (T::WeightInfo::cancel_queued(10), DispatchClass::Operational)]
|
||||||
fn cancel_queued(origin, which: ReferendumIndex) {
|
fn cancel_queued(origin, which: ReferendumIndex) {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
@@ -908,16 +893,10 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `Delegated`.
|
/// Emits `Delegated`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R)` where R is the number of referendums the voter delegating to has
|
||||||
/// - Complexity: `O(R)` where R is the number of referendums the voter delegating to has
|
|
||||||
/// voted on. Weight is charged as if maximum votes.
|
/// voted on. Weight is charged as if maximum votes.
|
||||||
/// - Db reads: 3*`VotingOf`, `origin account locks`
|
|
||||||
/// - Db writes: 3*`VotingOf`, `origin account locks`
|
|
||||||
/// - Db reads per votes: `ReferendumInfoOf`
|
|
||||||
/// - Db writes per votes: `ReferendumInfoOf`
|
|
||||||
// NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure
|
// NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure
|
||||||
// because a valid delegation cover decoding a direct voting with max votes.
|
// because a valid delegation cover decoding a direct voting with max votes.
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::delegate(T::MaxVotes::get())]
|
#[weight = T::WeightInfo::delegate(T::MaxVotes::get())]
|
||||||
pub fn delegate(
|
pub fn delegate(
|
||||||
origin,
|
origin,
|
||||||
@@ -941,16 +920,10 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `Undelegated`.
|
/// Emits `Undelegated`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R)` where R is the number of referendums the voter delegating to has
|
||||||
/// - Complexity: `O(R)` where R is the number of referendums the voter delegating to has
|
|
||||||
/// voted on. Weight is charged as if maximum votes.
|
/// voted on. Weight is charged as if maximum votes.
|
||||||
/// - Db reads: 2*`VotingOf`
|
|
||||||
/// - Db writes: 2*`VotingOf`
|
|
||||||
/// - Db reads per votes: `ReferendumInfoOf`
|
|
||||||
/// - Db writes per votes: `ReferendumInfoOf`
|
|
||||||
// NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure
|
// NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure
|
||||||
// because a valid delegation cover decoding a direct voting with max votes.
|
// because a valid delegation cover decoding a direct voting with max votes.
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::undelegate(T::MaxVotes::get().into())]
|
#[weight = T::WeightInfo::undelegate(T::MaxVotes::get().into())]
|
||||||
fn undelegate(origin) -> DispatchResultWithPostInfo {
|
fn undelegate(origin) -> DispatchResultWithPostInfo {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
@@ -962,10 +935,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// The dispatch origin of this call must be _Root_.
|
/// The dispatch origin of this call must be _Root_.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(1)`.
|
||||||
/// - `O(1)`.
|
|
||||||
/// - Db writes: `PublicProps`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::clear_public_proposals()]
|
#[weight = T::WeightInfo::clear_public_proposals()]
|
||||||
fn clear_public_proposals(origin) {
|
fn clear_public_proposals(origin) {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
@@ -981,11 +951,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `PreimageNoted`.
|
/// Emits `PreimageNoted`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit).
|
||||||
/// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit).
|
|
||||||
/// - Db reads: `Preimages`
|
|
||||||
/// - Db writes: `Preimages`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::note_preimage(encoded_proposal.len() as u32)]
|
#[weight = T::WeightInfo::note_preimage(encoded_proposal.len() as u32)]
|
||||||
fn note_preimage(origin, encoded_proposal: Vec<u8>) {
|
fn note_preimage(origin, encoded_proposal: Vec<u8>) {
|
||||||
Self::note_preimage_inner(ensure_signed(origin)?, encoded_proposal)?;
|
Self::note_preimage_inner(ensure_signed(origin)?, encoded_proposal)?;
|
||||||
@@ -1012,11 +978,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `PreimageNoted`.
|
/// Emits `PreimageNoted`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit).
|
||||||
/// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit).
|
|
||||||
/// - Db reads: `Preimages`
|
|
||||||
/// - Db writes: `Preimages`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32)]
|
#[weight = T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32)]
|
||||||
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) -> DispatchResultWithPostInfo {
|
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) -> DispatchResultWithPostInfo {
|
||||||
Self::note_imminent_preimage_inner(ensure_signed(origin)?, encoded_proposal)?;
|
Self::note_imminent_preimage_inner(ensure_signed(origin)?, encoded_proposal)?;
|
||||||
@@ -1052,11 +1014,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// Emits `PreimageReaped`.
|
/// Emits `PreimageReaped`.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(D)` where D is length of proposal.
|
||||||
/// - Complexity: `O(D)` where D is length of proposal.
|
|
||||||
/// - Db reads: `Preimages`, provider account data
|
|
||||||
/// - Db writes: `Preimages` provider account data
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::reap_preimage(*proposal_len_upper_bound)]
|
#[weight = T::WeightInfo::reap_preimage(*proposal_len_upper_bound)]
|
||||||
fn reap_preimage(origin, proposal_hash: T::Hash, #[compact] proposal_len_upper_bound: u32) {
|
fn reap_preimage(origin, proposal_hash: T::Hash, #[compact] proposal_len_upper_bound: u32) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
@@ -1090,11 +1048,7 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// - `target`: The account to remove the lock on.
|
/// - `target`: The account to remove the lock on.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R)` with R number of vote of target.
|
||||||
/// - Complexity `O(R)` with R number of vote of target.
|
|
||||||
/// - Db reads: `VotingOf`, `balances locks`, `target account`
|
|
||||||
/// - Db writes: `VotingOf`, `balances locks`, `target account`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::unlock_set(T::MaxVotes::get())
|
#[weight = T::WeightInfo::unlock_set(T::MaxVotes::get())
|
||||||
.max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))]
|
.max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))]
|
||||||
fn unlock(origin, target: T::AccountId) {
|
fn unlock(origin, target: T::AccountId) {
|
||||||
@@ -1127,12 +1081,8 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// - `index`: The index of referendum of the vote to be removed.
|
/// - `index`: The index of referendum of the vote to be removed.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
||||||
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
|
||||||
/// Weight is calculated for the maximum number of vote.
|
/// Weight is calculated for the maximum number of vote.
|
||||||
/// - Db reads: `ReferendumInfoOf`, `VotingOf`
|
|
||||||
/// - Db writes: `ReferendumInfoOf`, `VotingOf`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::remove_vote(T::MaxVotes::get())]
|
#[weight = T::WeightInfo::remove_vote(T::MaxVotes::get())]
|
||||||
fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
|
fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
@@ -1152,12 +1102,8 @@ decl_module! {
|
|||||||
/// referendum `index`.
|
/// referendum `index`.
|
||||||
/// - `index`: The index of referendum of the vote to be removed.
|
/// - `index`: The index of referendum of the vote to be removed.
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
||||||
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
|
||||||
/// Weight is calculated for the maximum number of vote.
|
/// Weight is calculated for the maximum number of vote.
|
||||||
/// - Db reads: `ReferendumInfoOf`, `VotingOf`
|
|
||||||
/// - Db writes: `ReferendumInfoOf`, `VotingOf`
|
|
||||||
/// # </weight>
|
|
||||||
#[weight = T::WeightInfo::remove_other_vote(T::MaxVotes::get())]
|
#[weight = T::WeightInfo::remove_other_vote(T::MaxVotes::get())]
|
||||||
fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult {
|
fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
@@ -1172,6 +1118,80 @@ decl_module! {
|
|||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
Self::do_enact_proposal(proposal_hash, index)
|
Self::do_enact_proposal(proposal_hash, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Permanently place a proposal into the blacklist. This prevents it from ever being
|
||||||
|
/// proposed again.
|
||||||
|
///
|
||||||
|
/// If called on a queued public or external proposal, then this will result in it being
|
||||||
|
/// removed. If the `ref_index` supplied is an active referendum with the proposal hash,
|
||||||
|
/// then it will be cancelled.
|
||||||
|
///
|
||||||
|
/// The dispatch origin of this call must be `BlacklistOrigin`.
|
||||||
|
///
|
||||||
|
/// - `proposal_hash`: The proposal hash to blacklist permanently.
|
||||||
|
/// - `ref_index`: An ongoing referendum whose hash is `proposal_hash`, which will be
|
||||||
|
/// cancelled.
|
||||||
|
///
|
||||||
|
/// Weight: `O(p)` (though as this is an high-privilege dispatch, we assume it has a
|
||||||
|
/// reasonable value).
|
||||||
|
#[weight = (T::WeightInfo::blacklist(T::MaxProposals::get()), DispatchClass::Operational)]
|
||||||
|
fn blacklist(origin,
|
||||||
|
proposal_hash: T::Hash,
|
||||||
|
maybe_ref_index: Option<ReferendumIndex>,
|
||||||
|
) {
|
||||||
|
T::BlacklistOrigin::ensure_origin(origin)?;
|
||||||
|
|
||||||
|
// Insert the proposal into the blacklist.
|
||||||
|
let permanent = (T::BlockNumber::max_value(), Vec::<T::AccountId>::new());
|
||||||
|
Blacklist::<T>::insert(&proposal_hash, permanent);
|
||||||
|
|
||||||
|
// Remove the queued proposal, if it's there.
|
||||||
|
PublicProps::<T>::mutate(|props| {
|
||||||
|
if let Some(index) = props.iter().position(|p| p.1 == proposal_hash) {
|
||||||
|
let (prop_index, ..) = props.remove(index);
|
||||||
|
if let Some((whos, amount)) = DepositOf::<T>::take(prop_index) {
|
||||||
|
for who in whos.into_iter() {
|
||||||
|
T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove the external queued referendum, if it's there.
|
||||||
|
if matches!(NextExternal::<T>::get(), Some((h, ..)) if h == proposal_hash) {
|
||||||
|
NextExternal::<T>::kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the referendum, if it's there.
|
||||||
|
if let Some(ref_index) = maybe_ref_index {
|
||||||
|
if let Ok(status) = Self::referendum_status(ref_index) {
|
||||||
|
if status.proposal_hash == proposal_hash {
|
||||||
|
Self::internal_cancel_referendum(ref_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::deposit_event(RawEvent::Blacklisted(proposal_hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove a proposal.
|
||||||
|
///
|
||||||
|
/// The dispatch origin of this call must be `CancelProposalOrigin`.
|
||||||
|
///
|
||||||
|
/// - `prop_index`: The index of the proposal to cancel.
|
||||||
|
///
|
||||||
|
/// Weight: `O(p)` where `p = PublicProps::<T>::decode_len()`
|
||||||
|
#[weight = T::WeightInfo::cancel_proposal(T::MaxProposals::get())]
|
||||||
|
fn cancel_proposal(origin, #[compact] prop_index: PropIndex) {
|
||||||
|
T::CancelProposalOrigin::ensure_origin(origin)?;
|
||||||
|
|
||||||
|
PublicProps::<T>::mutate(|props| props.retain(|p| p.0 != prop_index));
|
||||||
|
if let Some((whos, amount)) = DepositOf::<T>::take(prop_index) {
|
||||||
|
for who in whos.into_iter() {
|
||||||
|
T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1608,7 +1628,7 @@ impl<T: Trait> Module<T> {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # <weight>
|
/// # <weight>
|
||||||
/// If a referendum is launched or maturing take full block weight. Otherwise:
|
/// If a referendum is launched or maturing, this will take full block weight. Otherwise:
|
||||||
/// - Complexity: `O(R)` where `R` is the number of unbaked referenda.
|
/// - Complexity: `O(R)` where `R` is the number of unbaked referenda.
|
||||||
/// - Db reads: `LastTabledWasExternal`, `NextExternal`, `PublicProps`, `account`,
|
/// - Db reads: `LastTabledWasExternal`, `NextExternal`, `PublicProps`, `account`,
|
||||||
/// `ReferendumCount`, `LowestUnbaked`
|
/// `ReferendumCount`, `LowestUnbaked`
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ const NAY: Vote = Vote { aye: false, conviction: Conviction::None };
|
|||||||
const BIG_AYE: Vote = Vote { aye: true, conviction: Conviction::Locked1x };
|
const BIG_AYE: Vote = Vote { aye: true, conviction: Conviction::Locked1x };
|
||||||
const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x };
|
const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x };
|
||||||
|
|
||||||
|
const MAX_PROPOSALS: u32 = 100;
|
||||||
|
|
||||||
impl_outer_origin! {
|
impl_outer_origin! {
|
||||||
pub enum Origin for Test where system = frame_system {}
|
pub enum Origin for Test where system = frame_system {}
|
||||||
}
|
}
|
||||||
@@ -151,6 +153,7 @@ parameter_types! {
|
|||||||
pub const EnactmentPeriod: u64 = 2;
|
pub const EnactmentPeriod: u64 = 2;
|
||||||
pub const CooloffPeriod: u64 = 2;
|
pub const CooloffPeriod: u64 = 2;
|
||||||
pub const MaxVotes: u32 = 100;
|
pub const MaxVotes: u32 = 100;
|
||||||
|
pub const MaxProposals: u32 = MAX_PROPOSALS;
|
||||||
}
|
}
|
||||||
ord_parameter_types! {
|
ord_parameter_types! {
|
||||||
pub const One: u64 = 1;
|
pub const One: u64 = 1;
|
||||||
@@ -194,6 +197,8 @@ impl super::Trait for Test {
|
|||||||
type ExternalDefaultOrigin = EnsureSignedBy<One, u64>;
|
type ExternalDefaultOrigin = EnsureSignedBy<One, u64>;
|
||||||
type FastTrackOrigin = EnsureSignedBy<Five, u64>;
|
type FastTrackOrigin = EnsureSignedBy<Five, u64>;
|
||||||
type CancellationOrigin = EnsureSignedBy<Four, u64>;
|
type CancellationOrigin = EnsureSignedBy<Four, u64>;
|
||||||
|
type BlacklistOrigin = EnsureRoot<u64>;
|
||||||
|
type CancelProposalOrigin = EnsureRoot<u64>;
|
||||||
type VetoOrigin = EnsureSignedBy<OneToFive, u64>;
|
type VetoOrigin = EnsureSignedBy<OneToFive, u64>;
|
||||||
type CooloffPeriod = CooloffPeriod;
|
type CooloffPeriod = CooloffPeriod;
|
||||||
type PreimageByteDeposit = PreimageByteDeposit;
|
type PreimageByteDeposit = PreimageByteDeposit;
|
||||||
@@ -205,6 +210,7 @@ impl super::Trait for Test {
|
|||||||
type OperationalPreimageOrigin = EnsureSignedBy<Six, u64>;
|
type OperationalPreimageOrigin = EnsureSignedBy<Six, u64>;
|
||||||
type PalletsOrigin = OriginCaller;
|
type PalletsOrigin = OriginCaller;
|
||||||
type WeightInfo = ();
|
type WeightInfo = ();
|
||||||
|
type MaxProposals = MaxProposals;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||||
|
|||||||
@@ -79,6 +79,32 @@ fn veto_external_works() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn external_blacklisting_should_work() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
System::set_block_number(0);
|
||||||
|
|
||||||
|
assert_ok!(Democracy::external_propose(
|
||||||
|
Origin::signed(2),
|
||||||
|
set_balance_proposal_hash_and_note(2),
|
||||||
|
));
|
||||||
|
|
||||||
|
let hash = set_balance_proposal_hash(2);
|
||||||
|
assert_ok!(Democracy::blacklist(Origin::root(), hash, None));
|
||||||
|
|
||||||
|
fast_forward_to(2);
|
||||||
|
assert!(Democracy::referendum_status(0).is_err());
|
||||||
|
|
||||||
|
assert_noop!(
|
||||||
|
Democracy::external_propose(
|
||||||
|
Origin::signed(2),
|
||||||
|
set_balance_proposal_hash_and_note(2),
|
||||||
|
),
|
||||||
|
Error::<Test>::ProposalBlacklisted,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn external_referendum_works() {
|
fn external_referendum_works() {
|
||||||
new_test_ext().execute_with(|| {
|
new_test_ext().execute_with(|| {
|
||||||
|
|||||||
@@ -96,6 +96,45 @@ fn invalid_seconds_upper_bound_should_not_work() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cancel_proposal_should_work() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
System::set_block_number(0);
|
||||||
|
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||||
|
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||||
|
assert_noop!(Democracy::cancel_proposal(Origin::signed(1), 0), BadOrigin);
|
||||||
|
assert_ok!(Democracy::cancel_proposal(Origin::root(), 0));
|
||||||
|
assert_eq!(Democracy::backing_for(0), None);
|
||||||
|
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blacklisting_should_work() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
System::set_block_number(0);
|
||||||
|
let hash = set_balance_proposal_hash(2);
|
||||||
|
|
||||||
|
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||||
|
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||||
|
|
||||||
|
assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None), BadOrigin);
|
||||||
|
assert_ok!(Democracy::blacklist(Origin::root(), hash, None));
|
||||||
|
|
||||||
|
assert_eq!(Democracy::backing_for(0), None);
|
||||||
|
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||||
|
|
||||||
|
assert_noop!(propose_set_balance_and_note(1, 2, 2), Error::<Test>::ProposalBlacklisted);
|
||||||
|
|
||||||
|
fast_forward_to(2);
|
||||||
|
|
||||||
|
let hash = set_balance_proposal_hash(4);
|
||||||
|
assert!(Democracy::referendum_status(0).is_ok());
|
||||||
|
assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0)));
|
||||||
|
assert!(Democracy::referendum_status(0).is_err());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn runners_up_should_come_after() {
|
fn runners_up_should_come_after() {
|
||||||
new_test_ext().execute_with(|| {
|
new_test_ext().execute_with(|| {
|
||||||
|
|||||||
@@ -23,20 +23,12 @@ use testing_utils::*;
|
|||||||
|
|
||||||
use sp_runtime::traits::One;
|
use sp_runtime::traits::One;
|
||||||
use frame_system::RawOrigin;
|
use frame_system::RawOrigin;
|
||||||
pub use frame_benchmarking::{benchmarks, account, whitelisted_caller};
|
pub use frame_benchmarking::{benchmarks, account, whitelisted_caller, whitelist_account};
|
||||||
const SEED: u32 = 0;
|
const SEED: u32 = 0;
|
||||||
const MAX_SPANS: u32 = 100;
|
const MAX_SPANS: u32 = 100;
|
||||||
const MAX_VALIDATORS: u32 = 1000;
|
const MAX_VALIDATORS: u32 = 1000;
|
||||||
const MAX_SLASHES: u32 = 1000;
|
const MAX_SLASHES: u32 = 1000;
|
||||||
|
|
||||||
macro_rules! do_whitelist {
|
|
||||||
($acc:ident) => {
|
|
||||||
frame_benchmarking::benchmarking::add_to_whitelist(
|
|
||||||
frame_system::Account::<T>::hashed_key_for(&$acc).into()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
|
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
|
||||||
// read and write operations.
|
// read and write operations.
|
||||||
fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
|
fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
|
||||||
@@ -120,7 +112,7 @@ benchmarks! {
|
|||||||
let controller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(controller.clone());
|
let controller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(controller.clone());
|
||||||
let reward_destination = RewardDestination::Staked;
|
let reward_destination = RewardDestination::Staked;
|
||||||
let amount = T::Currency::minimum_balance() * 10.into();
|
let amount = T::Currency::minimum_balance() * 10.into();
|
||||||
do_whitelist!(stash);
|
whitelist_account!(stash);
|
||||||
}: _(RawOrigin::Signed(stash.clone()), controller_lookup, amount, reward_destination)
|
}: _(RawOrigin::Signed(stash.clone()), controller_lookup, amount, reward_destination)
|
||||||
verify {
|
verify {
|
||||||
assert!(Bonded::<T>::contains_key(stash));
|
assert!(Bonded::<T>::contains_key(stash));
|
||||||
@@ -132,7 +124,7 @@ benchmarks! {
|
|||||||
let max_additional = T::Currency::minimum_balance() * 10.into();
|
let max_additional = T::Currency::minimum_balance() * 10.into();
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
||||||
let original_bonded: BalanceOf<T> = ledger.active;
|
let original_bonded: BalanceOf<T> = ledger.active;
|
||||||
do_whitelist!(stash);
|
whitelist_account!(stash);
|
||||||
}: _(RawOrigin::Signed(stash), max_additional)
|
}: _(RawOrigin::Signed(stash), max_additional)
|
||||||
verify {
|
verify {
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
||||||
@@ -145,7 +137,7 @@ benchmarks! {
|
|||||||
let amount = T::Currency::minimum_balance() * 10.into();
|
let amount = T::Currency::minimum_balance() * 10.into();
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
||||||
let original_bonded: BalanceOf<T> = ledger.active;
|
let original_bonded: BalanceOf<T> = ledger.active;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller.clone()), amount)
|
}: _(RawOrigin::Signed(controller.clone()), amount)
|
||||||
verify {
|
verify {
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
||||||
@@ -164,7 +156,7 @@ benchmarks! {
|
|||||||
CurrentEra::put(EraIndex::max_value());
|
CurrentEra::put(EraIndex::max_value());
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
||||||
let original_total: BalanceOf<T> = ledger.total;
|
let original_total: BalanceOf<T> = ledger.total;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s)
|
}: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s)
|
||||||
verify {
|
verify {
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
||||||
@@ -183,7 +175,7 @@ benchmarks! {
|
|||||||
CurrentEra::put(EraIndex::max_value());
|
CurrentEra::put(EraIndex::max_value());
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
|
||||||
let original_total: BalanceOf<T> = ledger.total;
|
let original_total: BalanceOf<T> = ledger.total;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s)
|
}: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s)
|
||||||
verify {
|
verify {
|
||||||
assert!(!Ledger::<T>::contains_key(controller));
|
assert!(!Ledger::<T>::contains_key(controller));
|
||||||
@@ -192,7 +184,7 @@ benchmarks! {
|
|||||||
validate {
|
validate {
|
||||||
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
||||||
let prefs = ValidatorPrefs::default();
|
let prefs = ValidatorPrefs::default();
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller), prefs)
|
}: _(RawOrigin::Signed(controller), prefs)
|
||||||
verify {
|
verify {
|
||||||
assert!(Validators::<T>::contains_key(stash));
|
assert!(Validators::<T>::contains_key(stash));
|
||||||
@@ -203,7 +195,7 @@ benchmarks! {
|
|||||||
let n in 1 .. MAX_NOMINATIONS as u32;
|
let n in 1 .. MAX_NOMINATIONS as u32;
|
||||||
let (stash, controller) = create_stash_controller::<T>(n + 1, 100, Default::default())?;
|
let (stash, controller) = create_stash_controller::<T>(n + 1, 100, Default::default())?;
|
||||||
let validators = create_validators::<T>(n, 100)?;
|
let validators = create_validators::<T>(n, 100)?;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller), validators)
|
}: _(RawOrigin::Signed(controller), validators)
|
||||||
verify {
|
verify {
|
||||||
assert!(Nominators::<T>::contains_key(stash));
|
assert!(Nominators::<T>::contains_key(stash));
|
||||||
@@ -211,13 +203,13 @@ benchmarks! {
|
|||||||
|
|
||||||
chill {
|
chill {
|
||||||
let (_, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
let (_, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller))
|
}: _(RawOrigin::Signed(controller))
|
||||||
|
|
||||||
set_payee {
|
set_payee {
|
||||||
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
||||||
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Staked);
|
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Staked);
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller), RewardDestination::Controller)
|
}: _(RawOrigin::Signed(controller), RewardDestination::Controller)
|
||||||
verify {
|
verify {
|
||||||
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Controller);
|
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Controller);
|
||||||
@@ -227,7 +219,7 @@ benchmarks! {
|
|||||||
let (stash, _) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
let (stash, _) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
||||||
let new_controller = create_funded_user::<T>("new_controller", USER_SEED, 100);
|
let new_controller = create_funded_user::<T>("new_controller", USER_SEED, 100);
|
||||||
let new_controller_lookup = T::Lookup::unlookup(new_controller.clone());
|
let new_controller_lookup = T::Lookup::unlookup(new_controller.clone());
|
||||||
do_whitelist!(stash);
|
whitelist_account!(stash);
|
||||||
}: _(RawOrigin::Signed(stash), new_controller_lookup)
|
}: _(RawOrigin::Signed(stash), new_controller_lookup)
|
||||||
verify {
|
verify {
|
||||||
assert!(Ledger::<T>::contains_key(&new_controller));
|
assert!(Ledger::<T>::contains_key(&new_controller));
|
||||||
@@ -350,7 +342,7 @@ benchmarks! {
|
|||||||
}
|
}
|
||||||
Ledger::<T>::insert(controller.clone(), staking_ledger.clone());
|
Ledger::<T>::insert(controller.clone(), staking_ledger.clone());
|
||||||
let original_bonded: BalanceOf<T> = staking_ledger.active;
|
let original_bonded: BalanceOf<T> = staking_ledger.active;
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller.clone()), (l + 100).into())
|
}: _(RawOrigin::Signed(controller.clone()), (l + 100).into())
|
||||||
verify {
|
verify {
|
||||||
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created after")?;
|
||||||
@@ -381,7 +373,7 @@ benchmarks! {
|
|||||||
let (stash, controller) = create_stash_controller::<T>(0, 100, Default::default())?;
|
let (stash, controller) = create_stash_controller::<T>(0, 100, Default::default())?;
|
||||||
add_slashing_spans::<T>(&stash, s);
|
add_slashing_spans::<T>(&stash, s);
|
||||||
T::Currency::make_free_balance_be(&stash, 0.into());
|
T::Currency::make_free_balance_be(&stash, 0.into());
|
||||||
do_whitelist!(controller);
|
whitelist_account!(controller);
|
||||||
}: _(RawOrigin::Signed(controller), stash.clone(), s)
|
}: _(RawOrigin::Signed(controller), stash.clone(), s)
|
||||||
verify {
|
verify {
|
||||||
assert!(!Bonded::<T>::contains_key(&stash));
|
assert!(!Bonded::<T>::contains_key(&stash));
|
||||||
@@ -516,7 +508,7 @@ benchmarks! {
|
|||||||
|
|
||||||
let era = <Staking<T>>::current_era().unwrap_or(0);
|
let era = <Staking<T>>::current_era().unwrap_or(0);
|
||||||
let caller: T::AccountId = account("caller", n, SEED);
|
let caller: T::AccountId = account("caller", n, SEED);
|
||||||
do_whitelist!(caller);
|
whitelist_account!(caller);
|
||||||
}: {
|
}: {
|
||||||
let result = <Staking<T>>::submit_election_solution(
|
let result = <Staking<T>>::submit_election_solution(
|
||||||
RawOrigin::Signed(caller.clone()).into(),
|
RawOrigin::Signed(caller.clone()).into(),
|
||||||
@@ -584,7 +576,7 @@ benchmarks! {
|
|||||||
|
|
||||||
let era = <Staking<T>>::current_era().unwrap_or(0);
|
let era = <Staking<T>>::current_era().unwrap_or(0);
|
||||||
let caller: T::AccountId = account("caller", n, SEED);
|
let caller: T::AccountId = account("caller", n, SEED);
|
||||||
do_whitelist!(caller);
|
whitelist_account!(caller);
|
||||||
|
|
||||||
// submit a very bad solution on-chain
|
// submit a very bad solution on-chain
|
||||||
{
|
{
|
||||||
@@ -638,7 +630,7 @@ benchmarks! {
|
|||||||
<EraElectionStatus<T>>::put(ElectionStatus::Open(T::BlockNumber::from(1u32)));
|
<EraElectionStatus<T>>::put(ElectionStatus::Open(T::BlockNumber::from(1u32)));
|
||||||
let era = <Staking<T>>::current_era().unwrap_or(0);
|
let era = <Staking<T>>::current_era().unwrap_or(0);
|
||||||
let caller: T::AccountId = account("caller", n, SEED);
|
let caller: T::AccountId = account("caller", n, SEED);
|
||||||
do_whitelist!(caller);
|
whitelist_account!(caller);
|
||||||
|
|
||||||
// submit a seq-phragmen with all the good stuff on chain.
|
// submit a seq-phragmen with all the good stuff on chain.
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user