Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
WIP democracy weight
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed May 4, 2020
1 parent 2d68b72 commit 09593a4
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 112 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frame/democracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-core = { version = "2.0.0-dev", path = "../../primitives/core" }
pallet-balances = { version = "2.0.0-dev", path = "../balances" }
pallet-scheduler = { version = "2.0.0-dev", path = "../scheduler" }
sp-storage = { version = "2.0.0-dev", path = "../../primitives/storage" }
substrate-test-utils = { version = "2.0.0-dev", path = "../../test-utils" }
hex-literal = "0.2.1"

[features]
Expand All @@ -43,5 +44,6 @@ std = [
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
22 changes: 14 additions & 8 deletions frame/democracy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ fn add_proposal<T: Trait>(n: u32) -> Result<T::Hash, &'static str> {
let value = T::MinimumDeposit::get();
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);

Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal_hash, value.into())?;
Democracy::<T>::propose(
RawOrigin::Signed(other).into(),
proposal_hash,
value.into(),
u32::max_value(),
)?;

Ok(proposal_hash)
}
Expand Down Expand Up @@ -116,7 +121,7 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
let proposal_hash: T::Hash = T::Hashing::hash_of(&p);
let value = T::MinimumDeposit::get();
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
}: _(RawOrigin::Signed(caller), proposal_hash, value.into(), u32::max_value())
verify {
assert_eq!(Democracy::<T>::public_props().len(), (p + 1) as usize, "Proposals not created.");
}
Expand All @@ -130,15 +135,15 @@ benchmarks! {
// Create s existing "seconds"
for i in 0 .. s {
let seconder = funded_account::<T>("seconder", i);
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?;
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0, u32::max_value())?;
}

let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
assert_eq!(deposits.1.len(), (s + 1) as usize, "Seconds not recorded");
}: _(RawOrigin::Signed(caller), 0)
assert_eq!(deposits.0.len(), (s + 1) as usize, "Seconds not recorded");
}: _(RawOrigin::Signed(caller), 0, u32::max_value())
verify {
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
assert_eq!(deposits.1.len(), (s + 2) as usize, "`second` benchmark did not work");
assert_eq!(deposits.0.len(), (s + 2) as usize, "`second` benchmark did not work");
}

vote_new {
Expand Down Expand Up @@ -296,13 +301,14 @@ benchmarks! {
// Worst case scenario, we external propose a previously blacklisted proposal
external_propose {
let p in 1 .. MAX_PROPOSALS;
let v in 1 .. MAX_VETOERS;

let origin = T::ExternalOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&p);
// Add proposal to blacklist with block number 0
Blacklist::<T>::insert(
proposal_hash,
(T::BlockNumber::zero(), vec![T::AccountId::default()])
(T::BlockNumber::zero(), (0..v).map(|_| T::AccountId::default()).collect::<Vec<_>>())
);

let call = Call::<T>::external_propose(proposal_hash);
Expand Down Expand Up @@ -650,7 +656,7 @@ benchmarks! {
assert!(Preimages::<T>::contains_key(proposal_hash));

let caller = funded_account::<T>("caller", 0);
}: _(RawOrigin::Signed(caller), proposal_hash.clone())
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::max_value())
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
assert!(!Preimages::<T>::contains_key(proposal_hash));
Expand Down
Loading

0 comments on commit 09593a4

Please sign in to comment.