Bound uses of Call (#11649)

* Introduce preimages module in traits

* Multisize Preimages

* Len not actually necessary

* Tweaks to the preimage API

* Fixes

* Get Scheduler building with new API

* Scheduler tests pass

* Bounded Scheduler 🎉

* Use Agenda holes and introduce IncompleteSince to avoid need to reschedule

* Tests pass with new weight system

* New benchmarks

* Add missing file

* Drop preimage when permenantly overeight

* Drop preimage when permenantly overeight

* Referenda uses latest preimage API

* Testing ok

* Adding tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add preimage migration

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

* Remove dbg

* Refactor Democracy

* Refactor Democracy

* Add final MEL

* Remove silly maps

* Fixes

* Minor refactor

* Formatting

* Fixes

* Fixes

* Fixes

* Update frame/preimage/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Add migrations to Democracy

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Resolve conflicts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Resolve conflicts"

This reverts commit 734d66d69e54553471ffa54fa52e3e304dc8f106.

* Undo wrong resolves...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* massage clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy annoyance

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy annoyance

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* add missing file

* Test <Preimage as QueryPreimage>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy harassment

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixup tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove old stuff

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test <Scheduler as Anon> trait functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet-ui tests

Why is this needed? Should not be the case unless master is broken...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More scheduler trait test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Apply review suggestion

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add Scheduler test migration_v3_to_v4_works

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Merge fixup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Keep referenda benchmarks instantiatable

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use new scheduler weight functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use new democracy weight functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use weight compare functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet-ui tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More renaming…

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More renaming…

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add comment

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Implement OnRuntimeUpgrade for scheduler::v3_to_v4 migration

Put the migration into a proper `MigrateToV4` struct and implement
the OnRuntimeUpgrade hooks for it. Also move the test to use that
instead.

This should make it easier for adding it to Polkadot.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Handle undecodable Agendas

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove trash

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use new OnRuntimeUpgrade functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix BoundedSlice::truncate_from

Co-authored-by: jakoblell

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix pre_upgrade hook return values

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add more error logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Find too large preimages in the pre_upgrade hook

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test that too large Calls in agendas are ignored

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use new OnRuntimeUpgrade hooks

Why did the CI not catch this?!

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* works fine - just more logs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix staking migration

Causing issues on Kusama...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix UI tests

No idea why this is needed. This is actually undoing an earlier change.
Maybe the CI has different rustc versions!?

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove multisig's Calls (#12072)

* Remove multisig's Calls

* Multisig: Fix tests and re-introduce reserve logic (#12241)

* Fix tests and re-introduce reserve logic

* fix benches

* add todo

* remove irrelevant bench

* [Feature] Add a migration that drains and refunds stored calls (#12313)

* [Feature] Add a migration that drains and refunds stored calls

* migration fixes

* fixes

* address review comments

* consume the whole block weight

* fix assertions

* license header

* fix interface

Co-authored-by: parity-processbot <>

Co-authored-by: parity-processbot <>
Co-authored-by: Roman Useinov <roman.useinov@gmail.com>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix multisig benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/bench-bot.sh" pallet dev pallet_democracy

* ".git/.scripts/bench-bot.sh" pallet dev pallet_scheduler

* ".git/.scripts/bench-bot.sh" pallet dev pallet_preimage

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: parity-processbot <>
Co-authored-by: Roman Useinov <roman.useinov@gmail.com>
This commit is contained in:
Gavin Wood
2022-10-05 19:21:37 +01:00
committed by GitHub
parent 24f0c3601c
commit 93e8ffed55
67 changed files with 5089 additions and 3488 deletions
+123 -275
View File
@@ -22,24 +22,16 @@ use super::*;
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_support::{
assert_noop, assert_ok,
codec::Decode,
traits::{
schedule::DispatchTime, Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable,
},
traits::{Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable},
};
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::{BadOrigin, Bounded, One};
use frame_system::RawOrigin;
use sp_core::H256;
use sp_runtime::{traits::Bounded, BoundedVec};
use crate::Pallet as Democracy;
const REFERENDUM_COUNT_HINT: u32 = 10;
const SEED: u32 = 0;
const MAX_REFERENDUMS: u32 = 99;
const MAX_SECONDERS: u32 = 100;
const MAX_BYTES: u32 = 16_384;
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}
fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let caller: T::AccountId = account(name, index, SEED);
@@ -49,37 +41,32 @@ fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
caller
}
fn add_proposal<T: Config>(n: u32) -> Result<T::Hash, &'static str> {
let other = funded_account::<T>("proposer", n);
let value = T::MinimumDeposit::get();
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal_hash, value)?;
Ok(proposal_hash)
fn make_proposal<T: Config>(n: u32) -> BoundedCallOf<T> {
let call: CallOf<T> = frame_system::Call::remark { remark: n.encode() }.into();
<T as Config>::Preimages::bound(call).unwrap()
}
fn add_referendum<T: Config>(n: u32) -> Result<ReferendumIndex, &'static str> {
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
let vote_threshold = VoteThreshold::SimpleMajority;
fn add_proposal<T: Config>(n: u32) -> Result<H256, &'static str> {
let other = funded_account::<T>("proposer", n);
let value = T::MinimumDeposit::get();
let proposal = make_proposal::<T>(n);
Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal.clone(), value)?;
Ok(proposal.hash())
}
Democracy::<T>::inject_referendum(
T::LaunchPeriod::get(),
proposal_hash,
vote_threshold,
0u32.into(),
);
let referendum_index: ReferendumIndex = ReferendumCount::<T>::get() - 1;
T::Scheduler::schedule_named(
(DEMOCRACY_ID, referendum_index).encode(),
DispatchTime::At(2u32.into()),
None,
63,
frame_system::RawOrigin::Root.into(),
Call::enact_proposal { proposal_hash, index: referendum_index }.into(),
fn add_referendum<T: Config>(n: u32) -> (ReferendumIndex, H256) {
let vote_threshold = VoteThreshold::SimpleMajority;
let proposal = make_proposal::<T>(n);
let hash = proposal.hash();
(
Democracy::<T>::inject_referendum(
T::LaunchPeriod::get(),
proposal,
vote_threshold,
0u32.into(),
),
hash,
)
.map_err(|_| "failed to schedule named")?;
Ok(referendum_index)
}
fn account_vote<T: Config>(b: BalanceOf<T>) -> AccountVote<BalanceOf<T>> {
@@ -97,95 +84,90 @@ benchmarks! {
}
let caller = funded_account::<T>("caller", 0);
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
let proposal = make_proposal::<T>(0);
let value = T::MinimumDeposit::get();
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal_hash, value)
}: _(RawOrigin::Signed(caller), proposal, value)
verify {
assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created.");
}
second {
let s in 0 .. MAX_SECONDERS;
let caller = funded_account::<T>("caller", 0);
let proposal_hash = add_proposal::<T>(s)?;
add_proposal::<T>(0)?;
// Create s existing "seconds"
for i in 0 .. s {
// we must reserve one deposit for the `proposal` and one for our benchmarked `second` call.
for i in 0 .. T::MaxDeposits::get() - 2 {
let seconder = funded_account::<T>("seconder", i);
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0, u32::MAX)?;
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?;
}
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(), (T::MaxDeposits::get() - 1) as usize, "Seconds not recorded");
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), 0, u32::MAX)
}: _(RawOrigin::Signed(caller), 0)
verify {
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
assert_eq!(deposits.0.len(), (s + 2) as usize, "`second` benchmark did not work");
assert_eq!(deposits.0.len(), (T::MaxDeposits::get()) as usize, "`second` benchmark did not work");
}
vote_new {
let r in 1 .. MAX_REFERENDUMS;
let caller = funded_account::<T>("caller", 0);
let account_vote = account_vote::<T>(100u32.into());
// We need to create existing direct votes
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
for i in 0 .. T::MaxVotes::get() - 1 {
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct".into()),
};
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
assert_eq!(votes.len(), (T::MaxVotes::get() - 1) as usize, "Votes were not recorded.");
let referendum_index = add_referendum::<T>(r)?;
let ref_index = add_referendum::<T>(T::MaxVotes::get() - 1).0;
whitelist_account!(caller);
}: vote(RawOrigin::Signed(caller.clone()), referendum_index, account_vote)
}: vote(RawOrigin::Signed(caller.clone()), ref_index, account_vote)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct".into()),
};
assert_eq!(votes.len(), (r + 1) as usize, "Vote was not recorded.");
assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Vote was not recorded.");
}
vote_existing {
let r in 1 .. MAX_REFERENDUMS;
let caller = funded_account::<T>("caller", 0);
let account_vote = account_vote::<T>(100u32.into());
// We need to create existing direct votes
for i in 0 ..=r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
for i in 0..T::MaxVotes::get() {
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct".into()),
};
assert_eq!(votes.len(), (r + 1) as usize, "Votes were not recorded.");
assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Votes were not recorded.");
// Change vote from aye to nay
let nay = Vote { aye: false, conviction: Conviction::Locked1x };
let new_vote = AccountVote::Standard { vote: nay, balance: 1000u32.into() };
let referendum_index = Democracy::<T>::referendum_count() - 1;
let ref_index = Democracy::<T>::referendum_count() - 1;
// 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()), ref_index, new_vote)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct".into()),
};
assert_eq!(votes.len(), (r + 1) as usize, "Vote was incorrectly added");
let referendum_info = Democracy::<T>::referendum_info(referendum_index)
assert_eq!(votes.len(), T::MaxVotes::get() as usize, "Vote was incorrectly added");
let referendum_info = Democracy::<T>::referendum_info(ref_index)
.ok_or("referendum doesn't exist")?;
let tally = match referendum_info {
ReferendumInfo::Ongoing(r) => r.tally,
@@ -196,61 +178,55 @@ benchmarks! {
emergency_cancel {
let origin = T::CancellationOrigin::successful_origin();
let referendum_index = add_referendum::<T>(0)?;
assert_ok!(Democracy::<T>::referendum_status(referendum_index));
}: _<T::RuntimeOrigin>(origin, referendum_index)
let ref_index = add_referendum::<T>(0).0;
assert_ok!(Democracy::<T>::referendum_status(ref_index));
}: _<T::RuntimeOrigin>(origin, ref_index)
verify {
// Referendum has been canceled
assert_noop!(
Democracy::<T>::referendum_status(referendum_index),
Democracy::<T>::referendum_status(ref_index),
Error::<T>::ReferendumInvalid,
);
}
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 {
for i in 0 .. T::MaxProposals::get() - 1 {
add_proposal::<T>(i)?;
}
// We should really add a lot of seconds here, but we're not doing it elsewhere.
// Add a referendum of our proposal.
let (ref_index, hash) = add_referendum::<T>(0);
assert_ok!(Democracy::<T>::referendum_status(ref_index));
// Place our proposal in the external queue, too.
let hash = T::Hashing::hash_of(&0);
assert_ok!(
Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), hash)
Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), make_proposal::<T>(0))
);
let origin = T::BlacklistOrigin::successful_origin();
// Add a referendum of our proposal.
let referendum_index = add_referendum::<T>(0)?;
assert_ok!(Democracy::<T>::referendum_status(referendum_index));
}: _<T::RuntimeOrigin>(origin, hash, Some(referendum_index))
}: _<T::RuntimeOrigin>(origin, hash, Some(ref_index))
verify {
// Referendum has been canceled
assert_noop!(
Democracy::<T>::referendum_status(referendum_index),
Democracy::<T>::referendum_status(ref_index),
Error::<T>::ReferendumInvalid
);
}
// Worst case scenario, we external propose a previously blacklisted proposal
external_propose {
let v in 1 .. MAX_VETOERS as u32;
let origin = T::ExternalOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&0);
let proposal = make_proposal::<T>(0);
// Add proposal to blacklist with block number 0
let addresses = (0..v)
let addresses: BoundedVec<_, _> = (0..(T::MaxBlacklisted::get() - 1))
.into_iter()
.map(|i| account::<T::AccountId>("blacklist", i, SEED))
.collect::<Vec<_>>();
Blacklist::<T>::insert(
proposal_hash,
(T::BlockNumber::zero(), addresses),
);
}: _<T::RuntimeOrigin>(origin, proposal_hash)
.collect::<Vec<_>>()
.try_into()
.unwrap();
Blacklist::<T>::insert(proposal.hash(), (T::BlockNumber::zero(), addresses));
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
@@ -258,8 +234,8 @@ benchmarks! {
external_propose_majority {
let origin = T::ExternalMajorityOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&0);
}: _<T::RuntimeOrigin>(origin, proposal_hash)
let proposal = make_proposal::<T>(0);
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
@@ -267,8 +243,8 @@ benchmarks! {
external_propose_default {
let origin = T::ExternalDefaultOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&0);
}: _<T::RuntimeOrigin>(origin, proposal_hash)
let proposal = make_proposal::<T>(0);
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
@@ -276,8 +252,9 @@ benchmarks! {
fast_track {
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
Democracy::<T>::external_propose_default(origin_propose, proposal_hash)?;
let proposal = make_proposal::<T>(0);
let proposal_hash = proposal.hash();
Democracy::<T>::external_propose_default(origin_propose, proposal)?;
// NOTE: Instant origin may invoke a little bit more logic, but may not always succeed.
let origin_fast_track = T::FastTrackOrigin::successful_origin();
@@ -289,17 +266,15 @@ benchmarks! {
}
veto_external {
// Existing veto-ers
let v in 0 .. MAX_VETOERS as u32;
let proposal_hash: T::Hash = T::Hashing::hash_of(&v);
let proposal = make_proposal::<T>(0);
let proposal_hash = proposal.hash();
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
Democracy::<T>::external_propose_default(origin_propose, proposal_hash)?;
Democracy::<T>::external_propose_default(origin_propose, proposal)?;
let mut vetoers: Vec<T::AccountId> = Vec::new();
for i in 0 .. v {
vetoers.push(account::<T::AccountId>("vetoer", i, SEED));
let mut vetoers: BoundedVec<T::AccountId, _> = Default::default();
for i in 0 .. (T::MaxBlacklisted::get() - 1) {
vetoers.try_push(account::<T::AccountId>("vetoer", i, SEED)).unwrap();
}
vetoers.sort();
Blacklist::<T>::insert(proposal_hash, (T::BlockNumber::zero(), vetoers));
@@ -310,42 +285,27 @@ benchmarks! {
verify {
assert!(NextExternal::<T>::get().is_none());
let (_, new_vetoers) = <Blacklist<T>>::get(&proposal_hash).ok_or("no blacklist")?;
assert_eq!(new_vetoers.len(), (v + 1) as usize, "vetoers not added");
assert_eq!(new_vetoers.len(), T::MaxBlacklisted::get() 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 {
for i in 0 .. T::MaxProposals::get() {
add_proposal::<T>(i)?;
}
let cancel_origin = T::CancelProposalOrigin::successful_origin();
}: _<T::RuntimeOrigin>(cancel_origin, 0)
cancel_referendum {
let referendum_index = add_referendum::<T>(0)?;
}: _(RawOrigin::Root, referendum_index)
let ref_index = add_referendum::<T>(0).0;
}: _(RawOrigin::Root, ref_index)
cancel_queued {
let r in 1 .. MAX_REFERENDUMS;
for i in 0..r {
add_referendum::<T>(i)?; // This add one element in the scheduler
}
let referendum_index = add_referendum::<T>(r)?;
}: _(RawOrigin::Root, referendum_index)
// This measures the path of `launch_next` external. Not currently used as we simply
// assume the weight is `MaxBlockWeight` when executing.
#[extra]
on_initialize_external {
let r in 0 .. MAX_REFERENDUMS;
let r in 0 .. REFERENDUM_COUNT_HINT;
for i in 0..r {
add_referendum::<T>(i)?;
add_referendum::<T>(i);
}
assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
@@ -354,8 +314,8 @@ benchmarks! {
LastTabledWasExternal::<T>::put(false);
let origin = T::ExternalMajorityOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&r);
let call = Call::<T>::external_propose_majority { proposal_hash };
let proposal = make_proposal::<T>(r);
let call = Call::<T>::external_propose_majority { proposal };
call.dispatch_bypass_filter(origin)?;
// External proposal created
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
@@ -379,14 +339,12 @@ benchmarks! {
}
}
// This measures the path of `launch_next` public. Not currently used as we simply
// assume the weight is `MaxBlockWeight` when executing.
#[extra]
on_initialize_public {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
for i in 0..r {
add_referendum::<T>(i)?;
add_referendum::<T>(i);
}
assert_eq!(Democracy::<T>::referendum_count(), r, "referenda not created");
@@ -415,10 +373,10 @@ benchmarks! {
// No launch no maturing referenda.
on_initialize_base {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
for i in 0..r {
add_referendum::<T>(i)?;
add_referendum::<T>(i);
}
for (key, mut info) in ReferendumInfoOf::<T>::iter() {
@@ -445,10 +403,10 @@ benchmarks! {
}
on_initialize_base_with_launch_period {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
for i in 0..r {
add_referendum::<T>(i)?;
add_referendum::<T>(i);
}
for (key, mut info) in ReferendumInfoOf::<T>::iter() {
@@ -477,7 +435,7 @@ benchmarks! {
}
delegate {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
let initial_balance: BalanceOf<T> = 100u32.into();
let delegated_balance: BalanceOf<T> = 1000u32.into();
@@ -504,8 +462,8 @@ benchmarks! {
let account_vote = account_vote::<T>(initial_balance);
// We need to create existing direct votes for the `new_delegate`
for i in 0..r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(new_delegate.clone()).into(), ref_idx, account_vote)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(new_delegate.clone()).into(), ref_index, account_vote)?;
}
let votes = match VotingOf::<T>::get(&new_delegate) {
Voting::Direct { votes, .. } => votes,
@@ -529,7 +487,7 @@ benchmarks! {
}
undelegate {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
let initial_balance: BalanceOf<T> = 100u32.into();
let delegated_balance: BalanceOf<T> = 1000u32.into();
@@ -553,10 +511,10 @@ benchmarks! {
// We need to create votes direct votes for the `delegate`
let account_vote = account_vote::<T>(initial_balance);
for i in 0..r {
let ref_idx = add_referendum::<T>(i)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(
RawOrigin::Signed(the_delegate.clone()).into(),
ref_idx,
ref_index,
account_vote
)?;
}
@@ -580,71 +538,9 @@ benchmarks! {
}: _(RawOrigin::Root)
note_preimage {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
let caller = funded_account::<T>("caller", 0);
let encoded_proposal = vec![1; b as usize];
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
match Preimages::<T>::get(proposal_hash) {
Some(PreimageStatus::Available { .. }) => (),
_ => return Err("preimage not available".into())
}
}
note_imminent_preimage {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
// d + 1 to include the one we are testing
let encoded_proposal = vec![1; b as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let block_number = T::BlockNumber::one();
Preimages::<T>::insert(&proposal_hash, PreimageStatus::Missing(block_number));
let caller = funded_account::<T>("caller", 0);
let encoded_proposal = vec![1; b as usize];
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), encoded_proposal.clone())
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
match Preimages::<T>::get(proposal_hash) {
Some(PreimageStatus::Available { .. }) => (),
_ => return Err("preimage not available".into())
}
}
reap_preimage {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
let encoded_proposal = vec![1; b as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let submitter = funded_account::<T>("submitter", b);
Democracy::<T>::note_preimage(RawOrigin::Signed(submitter).into(), encoded_proposal.clone())?;
// We need to set this otherwise we get `Early` error.
let block_number = T::VotingPeriod::get() + T::EnactmentPeriod::get() + T::BlockNumber::one();
System::<T>::set_block_number(block_number);
assert!(Preimages::<T>::contains_key(proposal_hash));
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal_hash, u32::MAX)
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
assert!(!Preimages::<T>::contains_key(proposal_hash));
}
// Test when unlock will remove locks
unlock_remove {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
@@ -653,9 +549,9 @@ benchmarks! {
let small_vote = account_vote::<T>(base_balance);
// Vote and immediately unvote
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote)?;
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), ref_idx)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_index, small_vote)?;
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), ref_index)?;
}
let caller = funded_account::<T>("caller", 0);
@@ -669,7 +565,7 @@ benchmarks! {
// Test when unlock will set a new value
unlock_set {
let r in 1 .. MAX_REFERENDUMS;
let r in 0 .. (T::MaxVotes::get() - 1);
let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
@@ -677,14 +573,14 @@ benchmarks! {
let base_balance: BalanceOf<T> = 100u32.into();
let small_vote = account_vote::<T>(base_balance);
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_index, small_vote)?;
}
// Create a big vote so lock increases
let big_vote = account_vote::<T>(base_balance * 10u32.into());
let referendum_index = add_referendum::<T>(r)?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), referendum_index, big_vote)?;
let ref_index = add_referendum::<T>(r).0;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_index, big_vote)?;
let votes = match VotingOf::<T>::get(&locker) {
Voting::Direct { votes, .. } => votes,
@@ -695,7 +591,7 @@ benchmarks! {
let voting = VotingOf::<T>::get(&locker);
assert_eq!(voting.locked_balance(), base_balance * 10u32.into());
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), referendum_index)?;
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), ref_index)?;
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
@@ -709,18 +605,18 @@ benchmarks! {
let voting = VotingOf::<T>::get(&locker);
// Note that we may want to add a `get_lock` api to actually verify
assert_eq!(voting.locked_balance(), base_balance);
assert_eq!(voting.locked_balance(), if r > 0 { base_balance } else { 0u32.into() });
}
remove_vote {
let r in 1 .. MAX_REFERENDUMS;
let r in 1 .. T::MaxVotes::get();
let caller = funded_account::<T>("caller", 0);
let account_vote = account_vote::<T>(100u32.into());
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
@@ -729,9 +625,9 @@ benchmarks! {
};
assert_eq!(votes.len(), r as usize, "Votes not created");
let referendum_index = r - 1;
let ref_index = r - 1;
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), referendum_index)
}: _(RawOrigin::Signed(caller.clone()), ref_index)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
@@ -742,15 +638,15 @@ benchmarks! {
// Worst case is when target == caller and referendum is ongoing
remove_other_vote {
let r in 1 .. MAX_REFERENDUMS;
let r in 1 .. T::MaxVotes::get();
let caller = funded_account::<T>("caller", r);
let caller_lookup = T::Lookup::unlookup(caller.clone());
let account_vote = account_vote::<T>(100u32.into());
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
let ref_index = add_referendum::<T>(i).0;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_index, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
@@ -759,9 +655,9 @@ benchmarks! {
};
assert_eq!(votes.len(), r as usize, "Votes not created");
let referendum_index = r - 1;
let ref_index = r - 1;
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), caller_lookup, referendum_index)
}: _(RawOrigin::Signed(caller.clone()), caller_lookup, ref_index)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
@@ -770,54 +666,6 @@ benchmarks! {
assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed");
}
#[extra]
enact_proposal_execute {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
let proposer = funded_account::<T>("proposer", 0);
let raw_call = Call::note_preimage { encoded_proposal: vec![1; b as usize] };
let generic_call: T::Proposal = raw_call.into();
let encoded_proposal = generic_call.encode();
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
Democracy::<T>::note_preimage(RawOrigin::Signed(proposer).into(), encoded_proposal)?;
match Preimages::<T>::get(proposal_hash) {
Some(PreimageStatus::Available { .. }) => (),
_ => return Err("preimage not available".into())
}
}: enact_proposal(RawOrigin::Root, proposal_hash, 0)
verify {
// Fails due to mismatched origin
assert_last_event::<T>(Event::<T>::Executed { ref_index: 0, result: Err(BadOrigin.into()) }.into());
}
#[extra]
enact_proposal_slash {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
let proposer = funded_account::<T>("proposer", 0);
// Random invalid bytes
let encoded_proposal = vec![200; b as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
Democracy::<T>::note_preimage(RawOrigin::Signed(proposer).into(), encoded_proposal)?;
match Preimages::<T>::get(proposal_hash) {
Some(PreimageStatus::Available { .. }) => (),
_ => return Err("preimage not available".into())
}
let origin = RawOrigin::Root.into();
let call = Call::<T>::enact_proposal { proposal_hash, index: 0 }.encode();
}: {
assert_eq!(
<Call<T> as Decode>::decode(&mut &*call)
.expect("call is encoded above, encoding must be correct")
.dispatch_bypass_filter(origin),
Err(Error::<T>::PreimageInvalid.into())
);
}
impl_benchmark_test_suite!(
Democracy,
crate::tests::new_test_ext(),
+14 -2
View File
@@ -18,7 +18,7 @@
//! The conviction datatype.
use crate::types::Delegations;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Bounded, CheckedDiv, CheckedMul, Zero},
@@ -27,7 +27,19 @@ use sp_runtime::{
use sp_std::{prelude::*, result::Result};
/// A value denoting the strength of conviction of a vote.
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo)]
#[derive(
Encode,
MaxEncodedLen,
Decode,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
RuntimeDebug,
TypeInfo,
)]
pub enum Conviction {
/// 0.1x votes, unlocked.
None,
File diff suppressed because it is too large Load Diff
+236
View File
@@ -0,0 +1,236 @@
// This file is part of Substrate.
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Storage migrations for the preimage pallet.
use super::*;
use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade, BoundedVec};
use sp_core::H256;
/// The log target.
const TARGET: &'static str = "runtime::democracy::migration::v1";
/// The original data layout of the democracy pallet without a specific version number.
mod v0 {
use super::*;
#[storage_alias]
pub type PublicProps<T: Config> = StorageValue<
Pallet<T>,
Vec<(PropIndex, <T as frame_system::Config>::Hash, <T as frame_system::Config>::AccountId)>,
ValueQuery,
>;
#[storage_alias]
pub type NextExternal<T: Config> =
StorageValue<Pallet<T>, (<T as frame_system::Config>::Hash, VoteThreshold)>;
#[cfg(feature = "try-runtime")]
#[storage_alias]
pub type ReferendumInfoOf<T: Config> = StorageMap<
Pallet<T>,
frame_support::Twox64Concat,
ReferendumIndex,
ReferendumInfo<
<T as frame_system::Config>::BlockNumber,
<T as frame_system::Config>::Hash,
BalanceOf<T>,
>,
>;
}
pub mod v1 {
use super::*;
/// Migration for translating bare `Hash`es into `Bounded<Call>`s.
pub struct Migration<T>(sp_std::marker::PhantomData<T>);
impl<T: Config + frame_system::Config<Hash = H256>> OnRuntimeUpgrade for Migration<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 0, "can only upgrade from version 0");
let props_count = v0::PublicProps::<T>::get().len();
log::info!(target: TARGET, "{} public proposals will be migrated.", props_count,);
ensure!(props_count <= T::MaxProposals::get() as usize, "too many proposals");
let referenda_count = v0::ReferendumInfoOf::<T>::iter().count();
log::info!(target: TARGET, "{} referenda will be migrated.", referenda_count);
Ok((props_count as u32, referenda_count as u32).encode())
}
#[allow(deprecated)]
fn on_runtime_upgrade() -> Weight {
let mut weight = T::DbWeight::get().reads(1);
if StorageVersion::get::<Pallet<T>>() != 0 {
log::warn!(
target: TARGET,
"skipping on_runtime_upgrade: executed on wrong storage version.\
Expected version 0"
);
return weight
}
ReferendumInfoOf::<T>::translate(
|index, old: ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>| {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
log::info!(target: TARGET, "migrating referendum #{:?}", &index);
Some(match old {
ReferendumInfo::Ongoing(status) =>
ReferendumInfo::Ongoing(ReferendumStatus {
end: status.end,
proposal: Bounded::from_legacy_hash(status.proposal),
threshold: status.threshold,
delay: status.delay,
tally: status.tally,
}),
ReferendumInfo::Finished { approved, end } =>
ReferendumInfo::Finished { approved, end },
})
},
);
let props = v0::PublicProps::<T>::take()
.into_iter()
.map(|(i, hash, a)| (i, Bounded::from_legacy_hash(hash), a))
.collect::<Vec<_>>();
let bounded = BoundedVec::<_, T::MaxProposals>::truncate_from(props.clone());
PublicProps::<T>::put(bounded);
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
if props.len() as u32 > T::MaxProposals::get() {
log::error!(
target: TARGET,
"truncated {} public proposals to {}; continuing",
props.len(),
T::MaxProposals::get()
);
}
if let Some((hash, threshold)) = v0::NextExternal::<T>::take() {
log::info!(target: TARGET, "migrating next external proposal");
NextExternal::<T>::put((Bounded::from_legacy_hash(hash), threshold));
}
StorageVersion::new(1).put::<Pallet<T>>();
weight.saturating_add(T::DbWeight::get().reads_writes(1, 2))
}
#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 1, "must upgrade");
let (old_props_count, old_ref_count): (u32, u32) =
Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed");
let new_props_count = crate::PublicProps::<T>::get().len() as u32;
assert_eq!(new_props_count, old_props_count, "must migrate all public proposals");
let new_ref_count = crate::ReferendumInfoOf::<T>::iter().count() as u32;
assert_eq!(new_ref_count, old_ref_count, "must migrate all referenda");
log::info!(
target: TARGET,
"{} public proposals migrated, {} referenda migrated",
new_props_count,
new_ref_count,
);
Ok(())
}
}
}
#[cfg(test)]
#[cfg(feature = "try-runtime")]
mod test {
use super::*;
use crate::{
tests::{Test as T, *},
types::*,
};
use frame_support::bounded_vec;
#[allow(deprecated)]
#[test]
fn migration_works() {
new_test_ext().execute_with(|| {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 0);
// Insert some values into the v0 storage:
// Case 1: Ongoing referendum
let hash = H256::repeat_byte(1);
let status = ReferendumStatus {
end: 1u32.into(),
proposal: hash.clone(),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 1u32.into(),
tally: Tally { ayes: 1u32.into(), nays: 1u32.into(), turnout: 1u32.into() },
};
v0::ReferendumInfoOf::<T>::insert(1u32, ReferendumInfo::Ongoing(status));
// Case 2: Finished referendum
v0::ReferendumInfoOf::<T>::insert(
2u32,
ReferendumInfo::Finished { approved: true, end: 123u32.into() },
);
// Case 3: Public proposals
let hash2 = H256::repeat_byte(2);
v0::PublicProps::<T>::put(vec![
(3u32, hash.clone(), 123u64),
(4u32, hash2.clone(), 123u64),
]);
// Case 4: Next external
v0::NextExternal::<T>::put((hash.clone(), VoteThreshold::SuperMajorityApprove));
// Migrate.
let state = v1::Migration::<T>::pre_upgrade().unwrap();
let _weight = v1::Migration::<T>::on_runtime_upgrade();
v1::Migration::<T>::post_upgrade(state).unwrap();
// Check that all values got migrated.
// Case 1: Ongoing referendum
assert_eq!(
ReferendumInfoOf::<T>::get(1u32),
Some(ReferendumInfo::Ongoing(ReferendumStatus {
end: 1u32.into(),
proposal: Bounded::from_legacy_hash(hash),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 1u32.into(),
tally: Tally { ayes: 1u32.into(), nays: 1u32.into(), turnout: 1u32.into() },
}))
);
// Case 2: Finished referendum
assert_eq!(
ReferendumInfoOf::<T>::get(2u32),
Some(ReferendumInfo::Finished { approved: true, end: 123u32.into() })
);
// Case 3: Public proposals
let props: BoundedVec<_, <Test as Config>::MaxProposals> = bounded_vec![
(3u32, Bounded::from_legacy_hash(hash), 123u64),
(4u32, Bounded::from_legacy_hash(hash2), 123u64)
];
assert_eq!(PublicProps::<T>::get(), props);
// Case 4: Next external
assert_eq!(
NextExternal::<T>::get(),
Some((Bounded::from_legacy_hash(hash), VoteThreshold::SuperMajorityApprove))
);
});
}
}
+27 -49
View File
@@ -19,11 +19,11 @@
use super::*;
use crate as pallet_democracy;
use codec::Encode;
use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{
ConstU32, ConstU64, Contains, EqualPrivilegeOnly, GenesisBuild, OnInitialize, SortedMembers,
ConstU32, ConstU64, Contains, EqualPrivilegeOnly, GenesisBuild, OnInitialize,
SortedMembers, StorePreimage,
},
weights::Weight,
};
@@ -35,14 +35,12 @@ use sp_runtime::{
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
Perbill,
};
mod cancellation;
mod decoders;
mod delegation;
mod external_proposing;
mod fast_tracking;
mod lock_voting;
mod preimage;
mod public_proposals;
mod scheduling;
mod voting;
@@ -63,6 +61,7 @@ frame_support::construct_runtime!(
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Preimage: pallet_preimage,
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>},
}
@@ -78,13 +77,11 @@ impl Contains<RuntimeCall> for BaseFilter {
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1_000_000).set_proof_size(u64::MAX),
);
frame_system::limits::BlockWeights::simple_max(frame_support::weights::constants::WEIGHT_PER_SECOND.set_proof_size(u64::MAX));
}
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
@@ -111,6 +108,16 @@ impl frame_system::Config for Test {
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
}
impl pallet_preimage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances;
type ManagerOrigin = EnsureRoot<u64>;
type BaseDeposit = ConstU64<0>;
type ByteDeposit = ConstU64<0>;
}
impl pallet_scheduler::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
@@ -118,11 +125,10 @@ impl pallet_scheduler::Config for Test {
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<u64>;
type MaxScheduledPerBlock = ();
type MaxScheduledPerBlock = ConstU32<100>;
type WeightInfo = ();
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type PreimageProvider = ();
type NoPreimagePostponement = ();
type Preimages = ();
}
impl pallet_balances::Config for Test {
@@ -158,7 +164,6 @@ impl SortedMembers<u64> for OneToFive {
}
impl Config for Test {
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Currency = pallet_balances::Pallet<Self>;
type EnactmentPeriod = ConstU64<2>;
@@ -167,6 +172,8 @@ impl Config for Test {
type VoteLockingPeriod = ConstU64<3>;
type FastTrackVotingPeriod = ConstU64<2>;
type MinimumDeposit = ConstU64<1>;
type MaxDeposits = ConstU32<1000>;
type MaxBlacklisted = ConstU32<5>;
type ExternalOrigin = EnsureSignedBy<Two, u64>;
type ExternalMajorityOrigin = EnsureSignedBy<Three, u64>;
type ExternalDefaultOrigin = EnsureSignedBy<One, u64>;
@@ -176,16 +183,15 @@ impl Config for Test {
type CancelProposalOrigin = EnsureRoot<u64>;
type VetoOrigin = EnsureSignedBy<OneToFive, u64>;
type CooloffPeriod = ConstU64<2>;
type PreimageByteDeposit = PreimageByteDeposit;
type Slash = ();
type InstantOrigin = EnsureSignedBy<Six, u64>;
type InstantAllowed = InstantAllowed;
type Scheduler = Scheduler;
type MaxVotes = ConstU32<100>;
type OperationalPreimageOrigin = EnsureSignedBy<Six, u64>;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
type MaxProposals = ConstU32<100>;
type Preimages = Preimage;
}
pub fn new_test_ext() -> sp_io::TestExternalities {
@@ -203,12 +209,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
ext
}
/// Execute the function two times, with `true` and with `false`.
pub fn new_test_ext_execute_with_cond(execute: impl FnOnce(bool) -> () + Clone) {
new_test_ext().execute_with(|| (execute.clone())(false));
new_test_ext().execute_with(|| execute(true));
}
#[test]
fn params_should_work() {
new_test_ext().execute_with(|| {
@@ -218,44 +218,22 @@ fn params_should_work() {
});
}
fn set_balance_proposal(value: u64) -> Vec<u8> {
RuntimeCall::Balances(pallet_balances::Call::set_balance {
who: 42,
new_free: value,
new_reserved: 0,
})
.encode()
fn set_balance_proposal(value: u64) -> BoundedCallOf<Test> {
let inner = pallet_balances::Call::set_balance { who: 42, new_free: value, new_reserved: 0 };
let outer = RuntimeCall::Balances(inner);
Preimage::bound(outer).unwrap()
}
#[test]
fn set_balance_proposal_is_correctly_filtered_out() {
for i in 0..10 {
let call = RuntimeCall::decode(&mut &set_balance_proposal(i)[..]).unwrap();
let call = Preimage::realize(&set_balance_proposal(i)).unwrap().0;
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
}
}
fn set_balance_proposal_hash(value: u64) -> H256 {
BlakeTwo256::hash(&set_balance_proposal(value)[..])
}
fn set_balance_proposal_hash_and_note(value: u64) -> H256 {
let p = set_balance_proposal(value);
let h = BlakeTwo256::hash(&p[..]);
match Democracy::note_preimage(RuntimeOrigin::signed(6), p) {
Ok(_) => (),
Err(x) if x == Error::<Test>::DuplicatePreimage.into() => (),
Err(x) => panic!("{:?}", x),
}
h
}
fn propose_set_balance(who: u64, value: u64, delay: u64) -> DispatchResult {
Democracy::propose(RuntimeOrigin::signed(who), set_balance_proposal_hash(value), delay)
}
fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> DispatchResult {
Democracy::propose(RuntimeOrigin::signed(who), set_balance_proposal_hash_and_note(value), delay)
Democracy::propose(RuntimeOrigin::signed(who), set_balance_proposal(value), delay)
}
fn next_block() {
@@ -272,7 +250,7 @@ fn fast_forward_to(n: u64) {
fn begin_referendum() -> ReferendumIndex {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
0
}
@@ -24,7 +24,7 @@ fn cancel_referendum_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -42,37 +42,13 @@ fn cancel_referendum_should_work() {
});
}
#[test]
fn cancel_queued_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
// start of 2 => next referendum scheduled.
fast_forward_to(2);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
fast_forward_to(4);
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_some());
assert_noop!(
Democracy::cancel_queued(RuntimeOrigin::root(), 1),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::cancel_queued(RuntimeOrigin::root(), 0));
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_none());
});
}
#[test]
fn emergency_cancel_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
2,
);
@@ -86,7 +62,7 @@ fn emergency_cancel_should_work() {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
2,
);
@@ -18,7 +18,10 @@
//! The for various partial storage decoders
use super::*;
use frame_support::storage::{migration, unhashed};
use frame_support::{
storage::{migration, unhashed},
BoundedVec,
};
#[test]
fn test_decode_compact_u32_at() {
@@ -42,7 +45,8 @@ fn test_decode_compact_u32_at() {
fn len_of_deposit_of() {
new_test_ext().execute_with(|| {
for l in vec![0, 1, 200, 1000] {
let value: (Vec<u64>, u64) = ((0..l).map(|_| Default::default()).collect(), 3u64);
let value: (BoundedVec<u64, _>, u64) =
((0..l).map(|_| Default::default()).collect::<Vec<_>>().try_into().unwrap(), 3u64);
DepositOf::<Test>::insert(2, value);
assert_eq!(Democracy::len_of_deposit_of(2), Some(l));
}
@@ -51,35 +55,3 @@ fn len_of_deposit_of() {
assert_eq!(Democracy::len_of_deposit_of(2), None);
})
}
#[test]
fn pre_image() {
new_test_ext().execute_with(|| {
let key = Default::default();
let missing = PreimageStatus::Missing(0);
Preimages::<Test>::insert(key, missing);
assert_noop!(Democracy::pre_image_data_len(key), Error::<Test>::PreimageMissing);
assert_eq!(Democracy::check_pre_image_is_missing(key), Ok(()));
Preimages::<Test>::remove(key);
assert_noop!(Democracy::pre_image_data_len(key), Error::<Test>::PreimageMissing);
assert_noop!(Democracy::check_pre_image_is_missing(key), Error::<Test>::NotImminent);
for l in vec![0, 10, 100, 1000u32] {
let available = PreimageStatus::Available {
data: (0..l).map(|i| i as u8).collect(),
provider: 0,
deposit: 0,
since: 0,
expiry: None,
};
Preimages::<Test>::insert(key, available);
assert_eq!(Democracy::pre_image_data_len(key), Ok(l));
assert_noop!(
Democracy::check_pre_image_is_missing(key),
Error::<Test>::DuplicatePreimage
);
}
})
}
@@ -24,7 +24,7 @@ fn single_proposal_should_work_with_delegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
@@ -75,7 +75,7 @@ fn cyclic_delegation_should_unwind() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
@@ -100,7 +100,7 @@ fn single_proposal_should_work_with_vote_and_delegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
@@ -122,7 +122,7 @@ fn single_proposal_should_work_with_undelegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
// Delegate and undelegate vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
@@ -23,35 +23,29 @@ use super::*;
fn veto_external_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert!(<NextExternal<Test>>::exists());
let h = set_balance_proposal_hash_and_note(2);
let h = set_balance_proposal(2).hash();
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
// cancelled.
assert!(!<NextExternal<Test>>::exists());
// fails - same proposal can't be resubmitted.
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(1);
// fails as we're still in cooloff period.
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(2);
// works; as we're out of the cooloff period.
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert!(<NextExternal<Test>>::exists());
// 3 can't veto the same thing twice.
@@ -68,14 +62,11 @@ fn veto_external_works() {
fast_forward_to(3);
// same proposal fails as we're still in cooloff
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
Error::<Test>::ProposalBlacklisted
);
// different proposal works fine.
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(3),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
});
}
@@ -84,22 +75,16 @@ fn external_blacklisting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
let hash = set_balance_proposal_hash(2);
let hash = set_balance_proposal(2).hash();
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
fast_forward_to(2);
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
assert_noop!(
Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2),
),
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
Error::<Test>::ProposalBlacklisted,
);
});
@@ -110,15 +95,12 @@ fn external_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal_hash(2),),
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal(2),),
BadOrigin,
);
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(1),),
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),),
Error::<Test>::DuplicateProposal
);
fast_forward_to(2);
@@ -126,7 +108,7 @@ fn external_referendum_works() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal_hash: set_balance_proposal_hash(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -140,22 +122,19 @@ fn external_majority_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_majority(
RuntimeOrigin::signed(1),
set_balance_proposal_hash(2)
),
Democracy::external_propose_majority(RuntimeOrigin::signed(1), set_balance_proposal(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal_hash_and_note(2)
set_balance_proposal(2)
));
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal_hash: set_balance_proposal_hash(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -169,22 +148,19 @@ fn external_default_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_default(
RuntimeOrigin::signed(3),
set_balance_proposal_hash(2)
),
Democracy::external_propose_default(RuntimeOrigin::signed(3), set_balance_proposal(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_default(
RuntimeOrigin::signed(1),
set_balance_proposal_hash_and_note(2)
set_balance_proposal(2)
));
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal_hash: set_balance_proposal_hash(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityAgainst,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -197,11 +173,8 @@ fn external_default_referendum_works() {
fn external_and_public_interleaving_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(1),
));
assert_ok!(propose_set_balance_and_note(6, 2, 2));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),));
assert_ok!(propose_set_balance(6, 2, 2));
fast_forward_to(2);
@@ -210,17 +183,14 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal_hash: set_balance_proposal_hash_and_note(1),
proposal: set_balance_proposal(1),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish external
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(3),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
fast_forward_to(4);
@@ -229,7 +199,7 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(1),
Ok(ReferendumStatus {
end: 6,
proposal_hash: set_balance_proposal_hash_and_note(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -244,17 +214,14 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(2),
Ok(ReferendumStatus {
end: 8,
proposal_hash: set_balance_proposal_hash_and_note(3),
proposal: set_balance_proposal(3),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish external
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(5),
));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(5),));
fast_forward_to(8);
@@ -263,18 +230,15 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(3),
Ok(ReferendumStatus {
end: 10,
proposal_hash: set_balance_proposal_hash_and_note(5),
proposal: set_balance_proposal(5),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish both
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(7),
));
assert_ok!(propose_set_balance_and_note(6, 4, 2));
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(7),));
assert_ok!(propose_set_balance(6, 4, 2));
fast_forward_to(10);
@@ -283,16 +247,16 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(4),
Ok(ReferendumStatus {
end: 12,
proposal_hash: set_balance_proposal_hash_and_note(4),
proposal: set_balance_proposal(4),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish public again
assert_ok!(propose_set_balance_and_note(6, 6, 2));
assert_ok!(propose_set_balance(6, 6, 2));
// cancel external
let h = set_balance_proposal_hash_and_note(7);
let h = set_balance_proposal(7).hash();
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
fast_forward_to(12);
@@ -302,7 +266,7 @@ fn external_and_public_interleaving_works() {
Democracy::referendum_status(5),
Ok(ReferendumStatus {
end: 14,
proposal_hash: set_balance_proposal_hash_and_note(6),
proposal: set_balance_proposal(6),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -23,14 +23,14 @@ use super::*;
fn fast_track_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal_hash_and_note(2);
let h = set_balance_proposal(2).hash();
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal_hash_and_note(2)
set_balance_proposal(2)
));
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 2, 0));
@@ -38,7 +38,7 @@ fn fast_track_referendum_works() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 2,
proposal_hash: set_balance_proposal_hash_and_note(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 0,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -51,14 +51,14 @@ fn fast_track_referendum_works() {
fn instant_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal_hash_and_note(2);
let h = set_balance_proposal(2).hash();
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal_hash_and_note(2)
set_balance_proposal(2)
));
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 1, 0), BadOrigin);
@@ -76,7 +76,7 @@ fn instant_referendum_works() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 1,
proposal_hash: set_balance_proposal_hash_and_note(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 0,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -93,7 +93,7 @@ fn instant_next_block_referendum_backed() {
let majority_origin_id = 3;
let instant_origin_id = 6;
let voting_period = 1;
let proposal_hash = set_balance_proposal_hash_and_note(2);
let proposal = set_balance_proposal(2);
let delay = 2; // has no effect on test
// init
@@ -103,13 +103,13 @@ fn instant_next_block_referendum_backed() {
// propose with majority origin
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(majority_origin_id),
proposal_hash
proposal.clone()
));
// fast track with instant origin and voting period pointing to the next block
assert_ok!(Democracy::fast_track(
RuntimeOrigin::signed(instant_origin_id),
proposal_hash,
proposal.hash(),
voting_period,
delay
));
@@ -119,7 +119,7 @@ fn instant_next_block_referendum_backed() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: start_block_number + voting_period,
proposal_hash,
proposal,
threshold: VoteThreshold::SimpleMajority,
delay,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
@@ -143,11 +143,8 @@ fn instant_next_block_referendum_backed() {
fn fast_track_referendum_fails_when_no_simple_majority() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal_hash_and_note(2);
assert_ok!(Democracy::external_propose(
RuntimeOrigin::signed(2),
set_balance_proposal_hash_and_note(2)
));
let h = set_balance_proposal(2).hash();
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)));
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::NotSimpleMajority
@@ -43,7 +43,7 @@ fn lock_voting_should_work() {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -59,7 +59,7 @@ fn lock_voting_should_work() {
assert_eq!(Balances::locks(i), vec![the_lock(i * 10)]);
}
fast_forward_to(2);
fast_forward_to(3);
// Referendum passed; 1 and 5 didn't get their way and can now reap and unlock.
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
@@ -126,13 +126,13 @@ fn no_locks_without_conviction_should_work() {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(0, 10)));
fast_forward_to(2);
fast_forward_to(3);
assert_eq!(Balances::free_balance(42), 2);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 1, r));
@@ -146,7 +146,7 @@ fn lock_voting_should_work_with_delegation() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -167,28 +167,16 @@ fn lock_voting_should_work_with_delegation() {
fn setup_three_referenda() -> (u32, u32, u32) {
System::set_block_number(0);
let r1 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0,
);
let r1 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r1, aye(4, 10)));
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0,
);
let r2 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r2, aye(3, 20)));
let r3 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0,
);
let r3 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r3, aye(2, 50)));
fast_forward_to(2);
@@ -306,7 +294,7 @@ fn locks_should_persist_from_voting_to_delegation() {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SimpleMajority,
0,
);
@@ -1,237 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The preimage tests.
use super::*;
#[test]
fn missing_preimage_should_fail() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 0);
});
}
#[test]
fn preimage_deposit_should_be_required_and_returned() {
new_test_ext_execute_with_cond(|operational| {
// fee of 100 is too much.
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
assert_noop!(
if operational {
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), vec![0; 500])
} else {
Democracy::note_preimage(RuntimeOrigin::signed(6), vec![0; 500])
},
BalancesError::<Test, _>::InsufficientBalance,
);
// fee of 1 is reasonable.
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_eq!(Balances::reserved_balance(6), 12);
next_block();
next_block();
assert_eq!(Balances::reserved_balance(6), 0);
assert_eq!(Balances::free_balance(6), 60);
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn preimage_deposit_should_be_reapable_earlier_by_owner() {
new_test_ext_execute_with_cond(|operational| {
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
assert_ok!(if operational {
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
} else {
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
});
assert_eq!(Balances::reserved_balance(6), 12);
next_block();
assert_noop!(
Democracy::reap_preimage(
RuntimeOrigin::signed(6),
set_balance_proposal_hash(2),
u32::MAX
),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(
RuntimeOrigin::signed(6),
set_balance_proposal_hash(2),
u32::MAX
));
assert_eq!(Balances::free_balance(6), 60);
assert_eq!(Balances::reserved_balance(6), 0);
});
}
#[test]
fn preimage_deposit_should_be_reapable() {
new_test_ext_execute_with_cond(|operational| {
assert_noop!(
Democracy::reap_preimage(
RuntimeOrigin::signed(5),
set_balance_proposal_hash(2),
u32::MAX
),
Error::<Test>::PreimageMissing
);
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
assert_ok!(if operational {
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
} else {
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
});
assert_eq!(Balances::reserved_balance(6), 12);
next_block();
next_block();
next_block();
assert_noop!(
Democracy::reap_preimage(
RuntimeOrigin::signed(5),
set_balance_proposal_hash(2),
u32::MAX
),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(
RuntimeOrigin::signed(5),
set_balance_proposal_hash(2),
u32::MAX
));
assert_eq!(Balances::reserved_balance(6), 0);
assert_eq!(Balances::free_balance(6), 48);
assert_eq!(Balances::free_balance(5), 62);
});
}
#[test]
fn noting_imminent_preimage_for_free_should_work() {
new_test_ext_execute_with_cond(|operational| {
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
1,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_noop!(
if operational {
Democracy::note_imminent_preimage_operational(
RuntimeOrigin::signed(6),
set_balance_proposal(2),
)
} else {
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
},
Error::<Test>::NotImminent
);
next_block();
// Now we're in the dispatch queue it's all good.
assert_ok!(Democracy::note_imminent_preimage(
RuntimeOrigin::signed(6),
set_balance_proposal(2)
));
next_block();
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn reaping_imminent_preimage_should_fail() {
new_test_ext().execute_with(|| {
let h = set_balance_proposal_hash_and_note(2);
let r = Democracy::inject_referendum(3, h, VoteThreshold::SuperMajorityApprove, 1);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
next_block();
next_block();
assert_noop!(
Democracy::reap_preimage(RuntimeOrigin::signed(6), h, u32::MAX),
Error::<Test>::Imminent
);
});
}
#[test]
fn note_imminent_preimage_can_only_be_successful_once() {
new_test_ext().execute_with(|| {
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
1,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
next_block();
// First time works
assert_ok!(Democracy::note_imminent_preimage(
RuntimeOrigin::signed(6),
set_balance_proposal(2)
));
// Second time fails
assert_noop!(
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2)),
Error::<Test>::DuplicatePreimage
);
// Fails from any user
assert_noop!(
Democracy::note_imminent_preimage(RuntimeOrigin::signed(5), set_balance_proposal(2)),
Error::<Test>::DuplicatePreimage
);
});
}
@@ -22,9 +22,9 @@ use super::*;
#[test]
fn backing_for_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 2));
assert_ok!(propose_set_balance_and_note(1, 4, 4));
assert_ok!(propose_set_balance_and_note(1, 3, 3));
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_ok!(propose_set_balance(1, 3, 3));
assert_eq!(Democracy::backing_for(0), Some(2));
assert_eq!(Democracy::backing_for(1), Some(4));
assert_eq!(Democracy::backing_for(2), Some(3));
@@ -34,11 +34,11 @@ fn backing_for_should_work() {
#[test]
fn deposit_for_proposals_should_be_taken() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::free_balance(2), 15);
assert_eq!(Balances::free_balance(5), 35);
@@ -48,11 +48,11 @@ fn deposit_for_proposals_should_be_taken() {
#[test]
fn deposit_for_proposals_should_be_returned() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
fast_forward_to(3);
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 20);
@@ -77,30 +77,19 @@ fn poor_proposer_should_not_work() {
#[test]
fn poor_seconder_should_not_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(2, 2, 11));
assert_ok!(propose_set_balance(2, 2, 11));
assert_noop!(
Democracy::second(RuntimeOrigin::signed(1), 0, u32::MAX),
Democracy::second(RuntimeOrigin::signed(1), 0),
BalancesError::<Test, _>::InsufficientBalance
);
});
}
#[test]
fn invalid_seconds_upper_bound_should_not_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_noop!(
Democracy::second(RuntimeOrigin::signed(2), 0, 0),
Error::<Test>::WrongUpperBound
);
});
}
#[test]
fn cancel_proposal_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 2));
assert_ok!(propose_set_balance_and_note(1, 4, 4));
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_noop!(Democracy::cancel_proposal(RuntimeOrigin::signed(1), 0), BadOrigin);
assert_ok!(Democracy::cancel_proposal(RuntimeOrigin::root(), 0));
System::assert_last_event(crate::Event::ProposalCanceled { prop_index: 0 }.into());
@@ -113,10 +102,10 @@ fn cancel_proposal_should_work() {
fn blacklisting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let hash = set_balance_proposal_hash(2);
let hash = set_balance_proposal(2).hash();
assert_ok!(propose_set_balance_and_note(1, 2, 2));
assert_ok!(propose_set_balance_and_note(1, 4, 4));
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_noop!(Democracy::blacklist(RuntimeOrigin::signed(1), hash, None), BadOrigin);
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
@@ -124,11 +113,11 @@ fn blacklisting_should_work() {
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);
assert_noop!(propose_set_balance(1, 2, 2), Error::<Test>::ProposalBlacklisted);
fast_forward_to(2);
let hash = set_balance_proposal_hash(4);
let hash = set_balance_proposal(4).hash();
assert_ok!(Democracy::referendum_status(0));
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, Some(0)));
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
@@ -139,9 +128,9 @@ fn blacklisting_should_work() {
fn runners_up_should_come_after() {
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_ok!(propose_set_balance_and_note(1, 3, 3));
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_ok!(propose_set_balance(1, 3, 3));
fast_forward_to(2);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
fast_forward_to(4);
@@ -24,7 +24,7 @@ fn simple_passing_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -43,7 +43,7 @@ fn simple_failing_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -62,13 +62,13 @@ fn ooo_inject_referendums_should_work() {
new_test_ext().execute_with(|| {
let r1 = Democracy::inject_referendum(
3,
set_balance_proposal_hash_and_note(3),
set_balance_proposal(3),
VoteThreshold::SuperMajorityApprove,
0,
);
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -77,11 +77,13 @@ fn ooo_inject_referendums_should_work() {
assert_eq!(tally(r2), Tally { ayes: 1, nays: 0, turnout: 10 });
next_block();
assert_eq!(Balances::free_balance(42), 2);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
assert_eq!(tally(r1), Tally { ayes: 1, nays: 0, turnout: 10 });
next_block();
assert_eq!(Balances::free_balance(42), 2);
next_block();
assert_eq!(Balances::free_balance(42), 3);
});
@@ -92,7 +94,7 @@ fn delayed_enactment_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
1,
);
@@ -118,19 +120,19 @@ fn lowest_unbaked_should_be_sensible() {
new_test_ext().execute_with(|| {
let r1 = Democracy::inject_referendum(
3,
set_balance_proposal_hash_and_note(1),
set_balance_proposal(1),
VoteThreshold::SuperMajorityApprove,
0,
);
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
let r3 = Democracy::inject_referendum(
10,
set_balance_proposal_hash_and_note(3),
set_balance_proposal(3),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -141,16 +143,19 @@ fn lowest_unbaked_should_be_sensible() {
assert_eq!(Democracy::lowest_unbaked(), 0);
next_block();
// r2 is approved
assert_eq!(Balances::free_balance(42), 2);
// r2 ends with approval
assert_eq!(Democracy::lowest_unbaked(), 0);
next_block();
// r1 is approved
assert_eq!(Balances::free_balance(42), 1);
// r1 ends with approval
assert_eq!(Democracy::lowest_unbaked(), 3);
assert_eq!(Democracy::lowest_unbaked(), Democracy::referendum_count());
// r2 is executed
assert_eq!(Balances::free_balance(42), 2);
next_block();
// r1 is executed
assert_eq!(Balances::free_balance(42), 1);
});
}
@@ -63,7 +63,7 @@ fn split_vote_cancellation_should_work() {
fn single_proposal_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance_and_note(1, 2, 1));
assert_ok!(propose_set_balance(1, 2, 1));
let r = 0;
assert!(Democracy::referendum_info(r).is_none());
@@ -76,7 +76,7 @@ fn single_proposal_should_work() {
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal_hash: set_balance_proposal_hash_and_note(2),
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 1, nays: 0, turnout: 10 },
@@ -106,7 +106,7 @@ fn controversial_voting_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -132,7 +132,7 @@ fn controversial_low_turnout_voting_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
@@ -156,7 +156,7 @@ fn passing_low_turnout_voting_should_work() {
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
+15 -13
View File
@@ -18,7 +18,7 @@
//! Miscellaneous additional datatypes.
use crate::{AccountVote, Conviction, Vote, VoteThreshold};
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Saturating, Zero},
@@ -26,7 +26,7 @@ use sp_runtime::{
};
/// Info regarding an ongoing referendum.
#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
#[derive(Encode, MaxEncodedLen, Decode, Default, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct Tally<Balance> {
/// The number of aye votes, expressed in terms of post-conviction lock-vote.
pub ayes: Balance,
@@ -37,7 +37,9 @@ pub struct Tally<Balance> {
}
/// Amount of votes and capital placed in delegation for an account.
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
#[derive(
Encode, MaxEncodedLen, Decode, Default, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo,
)]
pub struct Delegations<Balance> {
/// The number of votes (this is post-conviction).
pub votes: Balance,
@@ -160,12 +162,12 @@ impl<
}
/// Info regarding an ongoing referendum.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct ReferendumStatus<BlockNumber, Hash, Balance> {
#[derive(Encode, MaxEncodedLen, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct ReferendumStatus<BlockNumber, Proposal, Balance> {
/// When voting on this referendum will end.
pub end: BlockNumber,
/// The hash of the proposal being voted on.
pub proposal_hash: Hash,
/// The proposal being voted on.
pub proposal: Proposal,
/// The thresholding mechanism to determine whether it passed.
pub threshold: VoteThreshold,
/// The delay (in blocks) to wait after a successful referendum before deploying.
@@ -175,23 +177,23 @@ pub struct ReferendumStatus<BlockNumber, Hash, Balance> {
}
/// Info regarding a referendum, present or past.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub enum ReferendumInfo<BlockNumber, Hash, Balance> {
#[derive(Encode, MaxEncodedLen, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub enum ReferendumInfo<BlockNumber, Proposal, Balance> {
/// Referendum is happening, the arg is the block number at which it will end.
Ongoing(ReferendumStatus<BlockNumber, Hash, Balance>),
Ongoing(ReferendumStatus<BlockNumber, Proposal, Balance>),
/// Referendum finished at `end`, and has been `approved` or rejected.
Finished { approved: bool, end: BlockNumber },
}
impl<BlockNumber, Hash, Balance: Default> ReferendumInfo<BlockNumber, Hash, Balance> {
impl<BlockNumber, Proposal, Balance: Default> ReferendumInfo<BlockNumber, Proposal, Balance> {
/// Create a new instance.
pub fn new(
end: BlockNumber,
proposal_hash: Hash,
proposal: Proposal,
threshold: VoteThreshold,
delay: BlockNumber,
) -> Self {
let s = ReferendumStatus { end, proposal_hash, threshold, delay, tally: Tally::default() };
let s = ReferendumStatus { end, proposal, threshold, delay, tally: Tally::default() };
ReferendumInfo::Ongoing(s)
}
}
+36 -12
View File
@@ -18,11 +18,12 @@
//! The vote datatype.
use crate::{Conviction, Delegations, ReferendumIndex};
use codec::{Decode, Encode, EncodeLike, Input, Output};
use codec::{Decode, Encode, EncodeLike, Input, MaxEncodedLen, Output};
use frame_support::traits::Get;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Saturating, Zero},
RuntimeDebug,
BoundedVec, RuntimeDebug,
};
use sp_std::prelude::*;
@@ -39,6 +40,12 @@ impl Encode for Vote {
}
}
impl MaxEncodedLen for Vote {
fn max_encoded_len() -> usize {
1
}
}
impl EncodeLike for Vote {}
impl Decode for Vote {
@@ -66,7 +73,7 @@ impl TypeInfo for Vote {
}
/// A vote for a referendum of a particular account.
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
#[derive(Encode, MaxEncodedLen, Decode, Copy, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum AccountVote<Balance> {
/// A standard vote, one-way (approve or reject) with a given amount of conviction.
Standard { vote: Vote, balance: Balance },
@@ -107,7 +114,18 @@ impl<Balance: Saturating> AccountVote<Balance> {
/// A "prior" lock, i.e. a lock for some now-forgotten reason.
#[derive(
Encode, Decode, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo,
Encode,
MaxEncodedLen,
Decode,
Default,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
RuntimeDebug,
TypeInfo,
)]
pub struct PriorLock<BlockNumber, Balance>(BlockNumber, Balance);
@@ -131,13 +149,15 @@ impl<BlockNumber: Ord + Copy + Zero, Balance: Ord + Copy + Zero> PriorLock<Block
}
/// An indicator for what an account is doing; it can either be delegating or voting.
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum Voting<Balance, AccountId, BlockNumber> {
#[derive(Clone, Encode, Decode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
#[codec(mel_bound(skip_type_params(MaxVotes)))]
#[scale_info(skip_type_params(MaxVotes))]
pub enum Voting<Balance, AccountId, BlockNumber, MaxVotes: Get<u32>> {
/// The account is voting directly. `delegations` is the total amount of post-conviction voting
/// weight that it controls from those that have delegated to it.
Direct {
/// The current votes of the account.
votes: Vec<(ReferendumIndex, AccountVote<Balance>)>,
votes: BoundedVec<(ReferendumIndex, AccountVote<Balance>), MaxVotes>,
/// The total amount of delegations that this account has received.
delegations: Delegations<Balance>,
/// Any pre-existing locks from past voting/delegating activity.
@@ -155,20 +175,24 @@ pub enum Voting<Balance, AccountId, BlockNumber> {
},
}
impl<Balance: Default, AccountId, BlockNumber: Zero> Default
for Voting<Balance, AccountId, BlockNumber>
impl<Balance: Default, AccountId, BlockNumber: Zero, MaxVotes: Get<u32>> Default
for Voting<Balance, AccountId, BlockNumber, MaxVotes>
{
fn default() -> Self {
Voting::Direct {
votes: Vec::new(),
votes: Default::default(),
delegations: Default::default(),
prior: PriorLock(Zero::zero(), Default::default()),
}
}
}
impl<Balance: Saturating + Ord + Zero + Copy, BlockNumber: Ord + Copy + Zero, AccountId>
Voting<Balance, AccountId, BlockNumber>
impl<
Balance: Saturating + Ord + Zero + Copy,
BlockNumber: Ord + Copy + Zero,
AccountId,
MaxVotes: Get<u32>,
> Voting<Balance, AccountId, BlockNumber, MaxVotes>
{
pub fn rejig(&mut self, now: BlockNumber) {
match self {
@@ -18,7 +18,7 @@
//! Voting thresholds.
use crate::Tally;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
@@ -26,7 +26,9 @@ use sp_runtime::traits::{IntegerSquareRoot, Zero};
use sp_std::ops::{Add, Div, Mul, Rem};
/// A means of determining if a vote is past pass threshold.
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, sp_runtime::RuntimeDebug, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Encode, MaxEncodedLen, Decode, sp_runtime::RuntimeDebug, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum VoteThreshold {
/// A supermajority of approvals is needed to pass this vote.
+132 -214
View File
@@ -18,22 +18,24 @@
//! Autogenerated weights for pallet_democracy
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-05-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2022-10-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// ./target/production/substrate
// /home/benchbot/cargo_target_dir/production/substrate
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_democracy
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --template=./.maintain/frame-weight-template.hbs
// --heap-pages=4096
// --pallet=pallet_democracy
// --chain=dev
// --output=./frame/democracy/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
@@ -45,27 +47,23 @@ use sp_std::marker::PhantomData;
/// Weight functions needed for pallet_democracy.
pub trait WeightInfo {
fn propose() -> Weight;
fn second(s: u32, ) -> Weight;
fn vote_new(r: u32, ) -> Weight;
fn vote_existing(r: u32, ) -> Weight;
fn second() -> Weight;
fn vote_new() -> Weight;
fn vote_existing() -> Weight;
fn emergency_cancel() -> Weight;
fn blacklist(p: u32, ) -> Weight;
fn external_propose(v: u32, ) -> Weight;
fn blacklist() -> Weight;
fn external_propose() -> Weight;
fn external_propose_majority() -> Weight;
fn external_propose_default() -> Weight;
fn fast_track() -> Weight;
fn veto_external(v: u32, ) -> Weight;
fn cancel_proposal(p: u32, ) -> Weight;
fn veto_external() -> Weight;
fn cancel_proposal() -> Weight;
fn cancel_referendum() -> Weight;
fn cancel_queued(r: u32, ) -> Weight;
fn on_initialize_base(r: u32, ) -> Weight;
fn on_initialize_base_with_launch_period(r: u32, ) -> Weight;
fn delegate(r: u32, ) -> Weight;
fn undelegate(r: u32, ) -> Weight;
fn clear_public_proposals() -> Weight;
fn note_preimage(b: u32, ) -> Weight;
fn note_imminent_preimage(b: u32, ) -> Weight;
fn reap_preimage(b: u32, ) -> Weight;
fn unlock_remove(r: u32, ) -> Weight;
fn unlock_set(r: u32, ) -> Weight;
fn remove_vote(r: u32, ) -> Weight;
@@ -80,125 +78,103 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Democracy Blacklist (r:1 w:0)
// Storage: Democracy DepositOf (r:0 w:1)
fn propose() -> Weight {
Weight::from_ref_time(48_328_000 as u64)
Weight::from_ref_time(57_410_000 as u64)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy DepositOf (r:1 w:1)
fn second(s: u32, ) -> Weight {
Weight::from_ref_time(30_923_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(142_000 as u64).saturating_mul(s as u64))
fn second() -> Weight {
Weight::from_ref_time(49_224_000 as u64)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn vote_new(r: u32, ) -> Weight {
Weight::from_ref_time(40_345_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(140_000 as u64).saturating_mul(r as u64))
fn vote_new() -> Weight {
Weight::from_ref_time(60_933_000 as u64)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn vote_existing(r: u32, ) -> Weight {
Weight::from_ref_time(39_853_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(150_000 as u64).saturating_mul(r as u64))
fn vote_existing() -> Weight {
Weight::from_ref_time(60_393_000 as u64)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy Cancellations (r:1 w:1)
fn emergency_cancel() -> Weight {
Weight::from_ref_time(19_364_000 as u64)
Weight::from_ref_time(24_588_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
// Storage: Democracy PublicProps (r:1 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy Blacklist (r:0 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn blacklist(p: u32, ) -> Weight {
Weight::from_ref_time(57_708_000 as u64)
// Standard Error: 4_000
.saturating_add(Weight::from_ref_time(192_000 as u64).saturating_mul(p as u64))
fn blacklist() -> Weight {
Weight::from_ref_time(91_226_000 as u64)
.saturating_add(T::DbWeight::get().reads(5 as u64))
.saturating_add(T::DbWeight::get().writes(6 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy Blacklist (r:1 w:0)
fn external_propose(v: u32, ) -> Weight {
Weight::from_ref_time(10_714_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(33_000 as u64).saturating_mul(v as u64))
fn external_propose() -> Weight {
Weight::from_ref_time(18_898_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:0 w:1)
fn external_propose_majority() -> Weight {
Weight::from_ref_time(3_697_000 as u64)
Weight::from_ref_time(5_136_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:0 w:1)
fn external_propose_default() -> Weight {
Weight::from_ref_time(3_831_000 as u64)
Weight::from_ref_time(5_243_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy ReferendumCount (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:0 w:1)
fn fast_track() -> Weight {
Weight::from_ref_time(20_271_000 as u64)
Weight::from_ref_time(24_275_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy Blacklist (r:1 w:1)
fn veto_external(v: u32, ) -> Weight {
Weight::from_ref_time(21_319_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(52_000 as u64).saturating_mul(v as u64))
fn veto_external() -> Weight {
Weight::from_ref_time(30_988_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
// Storage: Democracy PublicProps (r:1 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn cancel_proposal(p: u32, ) -> Weight {
Weight::from_ref_time(43_960_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(184_000 as u64).saturating_mul(p as u64))
fn cancel_proposal() -> Weight {
Weight::from_ref_time(78_515_000 as u64)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:0 w:1)
fn cancel_referendum() -> Weight {
Weight::from_ref_time(13_475_000 as u64)
Weight::from_ref_time(16_155_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Scheduler Lookup (r:1 w:1)
// Storage: Scheduler Agenda (r:1 w:1)
fn cancel_queued(r: u32, ) -> Weight {
Weight::from_ref_time(24_320_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(560_000 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
// Storage: Democracy LowestUnbaked (r:1 w:1)
// Storage: Democracy ReferendumCount (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:2 w:0)
/// The range of component `r` is `[0, 99]`.
fn on_initialize_base(r: u32, ) -> Weight {
Weight::from_ref_time(3_428_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(3_171_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(7_007_000 as u64)
// Standard Error: 2_686
.saturating_add(Weight::from_ref_time(2_288_781 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(T::DbWeight::get().writes(1 as u64))
@@ -208,33 +184,36 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Democracy LastTabledWasExternal (r:1 w:0)
// Storage: Democracy NextExternal (r:1 w:0)
// Storage: Democracy PublicProps (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:2 w:0)
/// The range of component `r` is `[0, 99]`.
fn on_initialize_base_with_launch_period(r: u32, ) -> Weight {
Weight::from_ref_time(7_867_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(3_177_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(9_528_000 as u64)
// Standard Error: 2_521
.saturating_add(Weight::from_ref_time(2_291_780 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(5 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy VotingOf (r:3 w:3)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:2 w:2)
/// The range of component `r` is `[0, 99]`.
fn delegate(r: u32, ) -> Weight {
Weight::from_ref_time(37_902_000 as u64)
// Standard Error: 4_000
.saturating_add(Weight::from_ref_time(4_335_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(46_787_000 as u64)
// Standard Error: 2_943
.saturating_add(Weight::from_ref_time(3_460_194 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(4 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(T::DbWeight::get().writes(4 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(r as u64)))
}
// Storage: Democracy VotingOf (r:2 w:2)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:2 w:2)
/// The range of component `r` is `[0, 99]`.
fn undelegate(r: u32, ) -> Weight {
Weight::from_ref_time(21_272_000 as u64)
// Standard Error: 3_000
.saturating_add(Weight::from_ref_time(4_351_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(29_789_000 as u64)
// Standard Error: 2_324
.saturating_add(Weight::from_ref_time(3_360_918 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(T::DbWeight::get().writes(2 as u64))
@@ -242,69 +221,48 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
// Storage: Democracy PublicProps (r:0 w:1)
fn clear_public_proposals() -> Weight {
Weight::from_ref_time(4_913_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
fn note_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(27_986_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(2_000 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
fn note_imminent_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(20_058_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(2_000 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
// Storage: System Account (r:1 w:0)
fn reap_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(28_619_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
Weight::from_ref_time(6_519_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `r` is `[0, 99]`.
fn unlock_remove(r: u32, ) -> Weight {
Weight::from_ref_time(26_619_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(56_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(28_884_000 as u64)
// Standard Error: 2_631
.saturating_add(Weight::from_ref_time(163_516 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `r` is `[0, 99]`.
fn unlock_set(r: u32, ) -> Weight {
Weight::from_ref_time(25_373_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(142_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(33_498_000 as u64)
// Standard Error: 622
.saturating_add(Weight::from_ref_time(133_421 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
/// The range of component `r` is `[1, 100]`.
fn remove_vote(r: u32, ) -> Weight {
Weight::from_ref_time(15_961_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(115_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(18_201_000 as u64)
// Standard Error: 1_007
.saturating_add(Weight::from_ref_time(152_699 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
/// The range of component `r` is `[1, 100]`.
fn remove_other_vote(r: u32, ) -> Weight {
Weight::from_ref_time(15_992_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(113_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(18_455_000 as u64)
// Standard Error: 951
.saturating_add(Weight::from_ref_time(150_907 as u64).saturating_mul(r as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64))
}
@@ -317,125 +275,103 @@ impl WeightInfo for () {
// Storage: Democracy Blacklist (r:1 w:0)
// Storage: Democracy DepositOf (r:0 w:1)
fn propose() -> Weight {
Weight::from_ref_time(48_328_000 as u64)
Weight::from_ref_time(57_410_000 as u64)
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy DepositOf (r:1 w:1)
fn second(s: u32, ) -> Weight {
Weight::from_ref_time(30_923_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(142_000 as u64).saturating_mul(s as u64))
fn second() -> Weight {
Weight::from_ref_time(49_224_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn vote_new(r: u32, ) -> Weight {
Weight::from_ref_time(40_345_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(140_000 as u64).saturating_mul(r as u64))
fn vote_new() -> Weight {
Weight::from_ref_time(60_933_000 as u64)
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn vote_existing(r: u32, ) -> Weight {
Weight::from_ref_time(39_853_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(150_000 as u64).saturating_mul(r as u64))
fn vote_existing() -> Weight {
Weight::from_ref_time(60_393_000 as u64)
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy Cancellations (r:1 w:1)
fn emergency_cancel() -> Weight {
Weight::from_ref_time(19_364_000 as u64)
Weight::from_ref_time(24_588_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Democracy PublicProps (r:1 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy Blacklist (r:0 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn blacklist(p: u32, ) -> Weight {
Weight::from_ref_time(57_708_000 as u64)
// Standard Error: 4_000
.saturating_add(Weight::from_ref_time(192_000 as u64).saturating_mul(p as u64))
fn blacklist() -> Weight {
Weight::from_ref_time(91_226_000 as u64)
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(6 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy Blacklist (r:1 w:0)
fn external_propose(v: u32, ) -> Weight {
Weight::from_ref_time(10_714_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(33_000 as u64).saturating_mul(v as u64))
fn external_propose() -> Weight {
Weight::from_ref_time(18_898_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:0 w:1)
fn external_propose_majority() -> Weight {
Weight::from_ref_time(3_697_000 as u64)
Weight::from_ref_time(5_136_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:0 w:1)
fn external_propose_default() -> Weight {
Weight::from_ref_time(3_831_000 as u64)
Weight::from_ref_time(5_243_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy ReferendumCount (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:0 w:1)
fn fast_track() -> Weight {
Weight::from_ref_time(20_271_000 as u64)
Weight::from_ref_time(24_275_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy NextExternal (r:1 w:1)
// Storage: Democracy Blacklist (r:1 w:1)
fn veto_external(v: u32, ) -> Weight {
Weight::from_ref_time(21_319_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(52_000 as u64).saturating_mul(v as u64))
fn veto_external() -> Weight {
Weight::from_ref_time(30_988_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Democracy PublicProps (r:1 w:1)
// Storage: Democracy DepositOf (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn cancel_proposal(p: u32, ) -> Weight {
Weight::from_ref_time(43_960_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(184_000 as u64).saturating_mul(p as u64))
fn cancel_proposal() -> Weight {
Weight::from_ref_time(78_515_000 as u64)
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:0 w:1)
fn cancel_referendum() -> Weight {
Weight::from_ref_time(13_475_000 as u64)
Weight::from_ref_time(16_155_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Scheduler Lookup (r:1 w:1)
// Storage: Scheduler Agenda (r:1 w:1)
fn cancel_queued(r: u32, ) -> Weight {
Weight::from_ref_time(24_320_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(560_000 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Democracy LowestUnbaked (r:1 w:1)
// Storage: Democracy ReferendumCount (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:2 w:0)
/// The range of component `r` is `[0, 99]`.
fn on_initialize_base(r: u32, ) -> Weight {
Weight::from_ref_time(3_428_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(3_171_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(7_007_000 as u64)
// Standard Error: 2_686
.saturating_add(Weight::from_ref_time(2_288_781 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
@@ -445,33 +381,36 @@ impl WeightInfo for () {
// Storage: Democracy LastTabledWasExternal (r:1 w:0)
// Storage: Democracy NextExternal (r:1 w:0)
// Storage: Democracy PublicProps (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:1 w:0)
// Storage: Democracy ReferendumInfoOf (r:2 w:0)
/// The range of component `r` is `[0, 99]`.
fn on_initialize_base_with_launch_period(r: u32, ) -> Weight {
Weight::from_ref_time(7_867_000 as u64)
// Standard Error: 2_000
.saturating_add(Weight::from_ref_time(3_177_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(9_528_000 as u64)
// Standard Error: 2_521
.saturating_add(Weight::from_ref_time(2_291_780 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy VotingOf (r:3 w:3)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:2 w:2)
/// The range of component `r` is `[0, 99]`.
fn delegate(r: u32, ) -> Weight {
Weight::from_ref_time(37_902_000 as u64)
// Standard Error: 4_000
.saturating_add(Weight::from_ref_time(4_335_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(46_787_000 as u64)
// Standard Error: 2_943
.saturating_add(Weight::from_ref_time(3_460_194 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(4 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(r as u64)))
}
// Storage: Democracy VotingOf (r:2 w:2)
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy ReferendumInfoOf (r:2 w:2)
/// The range of component `r` is `[0, 99]`.
fn undelegate(r: u32, ) -> Weight {
Weight::from_ref_time(21_272_000 as u64)
// Standard Error: 3_000
.saturating_add(Weight::from_ref_time(4_351_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(29_789_000 as u64)
// Standard Error: 2_324
.saturating_add(Weight::from_ref_time(3_360_918 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(r as u64)))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
@@ -479,69 +418,48 @@ impl WeightInfo for () {
}
// Storage: Democracy PublicProps (r:0 w:1)
fn clear_public_proposals() -> Weight {
Weight::from_ref_time(4_913_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
fn note_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(27_986_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(2_000 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
fn note_imminent_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(20_058_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(2_000 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy Preimages (r:1 w:1)
// Storage: System Account (r:1 w:0)
fn reap_preimage(b: u32, ) -> Weight {
Weight::from_ref_time(28_619_000 as u64)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
Weight::from_ref_time(6_519_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `r` is `[0, 99]`.
fn unlock_remove(r: u32, ) -> Weight {
Weight::from_ref_time(26_619_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(56_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(28_884_000 as u64)
// Standard Error: 2_631
.saturating_add(Weight::from_ref_time(163_516 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy VotingOf (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `r` is `[0, 99]`.
fn unlock_set(r: u32, ) -> Weight {
Weight::from_ref_time(25_373_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(142_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(33_498_000 as u64)
// Standard Error: 622
.saturating_add(Weight::from_ref_time(133_421 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
/// The range of component `r` is `[1, 100]`.
fn remove_vote(r: u32, ) -> Weight {
Weight::from_ref_time(15_961_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(115_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(18_201_000 as u64)
// Standard Error: 1_007
.saturating_add(Weight::from_ref_time(152_699 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Democracy ReferendumInfoOf (r:1 w:1)
// Storage: Democracy VotingOf (r:1 w:1)
/// The range of component `r` is `[1, 100]`.
fn remove_other_vote(r: u32, ) -> Weight {
Weight::from_ref_time(15_992_000 as u64)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(113_000 as u64).saturating_mul(r as u64))
Weight::from_ref_time(18_455_000 as u64)
// Standard Error: 951
.saturating_add(Weight::from_ref_time(150_907 as u64).saturating_mul(r as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}