Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl pallet_democracy::Trait for Runtime {
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
type WeightInfo = ();
type WeightInfo = weights::pallet_democracy::WeightInfo;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
//! A list of the different weight modules for our runtime.

pub mod pallet_balances;
pub mod pallet_democracy;
155 changes: 155 additions & 0 deletions bin/node/runtime/src/weights/pallet_democracy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (C) 2020 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.

//! Weights for the Democracy Pallet
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

pub struct WeightInfo;
impl pallet_democracy::WeightInfo for WeightInfo {
fn propose() -> Weight {
(49113000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn second(s: u32, ) -> Weight {
(42067000 as Weight)
.saturating_add((220000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn vote_new(r: u32, ) -> Weight {
(54159000 as Weight)
.saturating_add((252000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn vote_existing(r: u32, ) -> Weight {
(54145000 as Weight)
.saturating_add((262000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn emergency_cancel() -> Weight {
(31071000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn external_propose(v: u32, ) -> Weight {
(14282000 as Weight)
.saturating_add((109000 as Weight).saturating_mul(v as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn external_propose_majority() -> Weight {
(3478000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn external_propose_default() -> Weight {
(3442000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn fast_track() -> Weight {
(30820000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn veto_external(v: u32, ) -> Weight {
(30971000 as Weight)
.saturating_add((184000 as Weight).saturating_mul(v as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn cancel_referendum() -> Weight {
(20431000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn cancel_queued(r: u32, ) -> Weight {
(42438000 as Weight)
.saturating_add((3284000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn on_initialize_base(r: u32, ) -> Weight {
(70826000 as Weight)
.saturating_add((10716000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(6 as Weight))
.saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight)))
.saturating_add(DbWeight::get().writes(5 as Weight))
}
fn delegate(r: u32, ) -> Weight {
(72046000 as Weight)
.saturating_add((7837000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
.saturating_add(DbWeight::get().writes(4 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
}
fn undelegate(r: u32, ) -> Weight {
(41028000 as Weight)
.saturating_add((7810000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
.saturating_add(DbWeight::get().writes(2 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
}
fn clear_public_proposals() -> Weight {
(3643000 as Weight)
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn note_preimage(b: u32, ) -> Weight {
(46629000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn note_imminent_preimage(b: u32, ) -> Weight {
(31147000 as Weight)
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn reap_preimage(b: u32, ) -> Weight {
(42848000 as Weight)
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn unlock_remove(r: u32, ) -> Weight {
(45333000 as Weight)
.saturating_add((171000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn unlock_set(r: u32, ) -> Weight {
(44424000 as Weight)
.saturating_add((291000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn remove_vote(r: u32, ) -> Weight {
(28250000 as Weight)
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn remove_other_vote(r: u32, ) -> Weight {
(28250000 as Weight)
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
}
86 changes: 25 additions & 61 deletions frame/democracy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::Module as Democracy;

const SEED: u32 = 0;
const MAX_REFERENDUMS: u32 = 100;
const MAX_PROPOSALS: u32 = 100;
const MAX_SECONDERS: u32 = 100;
const MAX_BYTES: u32 = 16_384;

Expand Down Expand Up @@ -101,21 +100,12 @@ benchmarks! {
_ { }

propose {
let p in 1 .. MAX_PROPOSALS;

// Add p proposals
for i in 0 .. p {
add_proposal::<T>(i)?;
}

assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created.");

let caller = funded_account::<T>("caller", 0);
let proposal_hash: T::Hash = T::Hashing::hash_of(&p);
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
let value = T::MinimumDeposit::get();
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
verify {
assert_eq!(Democracy::<T>::public_props().len(), (p + 1) as usize, "Proposals not created.");
assert_eq!(Democracy::<T>::public_props().len(), 1, "Proposals not created.");
}

second {
Expand Down Expand Up @@ -206,18 +196,8 @@ benchmarks! {
}

emergency_cancel {
let r in 1 .. MAX_REFERENDUMS;
let origin = T::CancellationOrigin::successful_origin();

// Create and cancel a bunch of referendums
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
let call = Call::<T>::emergency_cancel(ref_idx);
call.dispatch_bypass_filter(origin.clone())?;
}

// Lets now measure one more
let referendum_index = add_referendum::<T>(r)?;
let referendum_index = add_referendum::<T>(0)?;
let call = Call::<T>::emergency_cancel(referendum_index);
assert!(Democracy::<T>::referendum_status(referendum_index).is_ok());
}: { call.dispatch_bypass_filter(origin)? }
Expand All @@ -228,11 +208,10 @@ 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 as u32;

let origin = T::ExternalOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&p);
let proposal_hash = T::Hashing::hash_of(&0);
// Add proposal to blacklist with block number 0
Blacklist::<T>::insert(
proposal_hash,
Expand All @@ -247,10 +226,8 @@ benchmarks! {
}

external_propose_majority {
let p in 1 .. MAX_PROPOSALS;

let origin = T::ExternalMajorityOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&p);
let proposal_hash = T::Hashing::hash_of(&0);
let call = Call::<T>::external_propose_majority(proposal_hash);
}: { call.dispatch_bypass_filter(origin)? }
verify {
Expand All @@ -259,10 +236,8 @@ benchmarks! {
}

external_propose_default {
let p in 1 .. MAX_PROPOSALS;

let origin = T::ExternalDefaultOrigin::successful_origin();
let proposal_hash = T::Hashing::hash_of(&p);
let proposal_hash = T::Hashing::hash_of(&0);
let call = Call::<T>::external_propose_default(proposal_hash);
}: { call.dispatch_bypass_filter(origin)? }
verify {
Expand All @@ -271,10 +246,8 @@ benchmarks! {
}

fast_track {
let p in 1 .. MAX_PROPOSALS;

let origin_propose = T::ExternalDefaultOrigin::successful_origin();
let proposal_hash: T::Hash = T::Hashing::hash_of(&p);
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;

// NOTE: Instant origin may invoke a little bit more logic, but may not always succeed.
Expand Down Expand Up @@ -315,24 +288,21 @@ benchmarks! {
}

cancel_referendum {
let r in 0 .. MAX_REFERENDUMS;
// Should have no effect on the execution time.
for i in 0..r {
add_referendum::<T>(i)?;
}
let referendum_index = add_referendum::<T>(r)?;
let referendum_index = add_referendum::<T>(0)?;
}: _(RawOrigin::Root, referendum_index)

cancel_queued {
let r in 1 .. MAX_REFERENDUMS;
// Should have no effect on the execution time.

for i in 0..r {
add_referendum::<T>(i)?;
add_referendum::<T>(i)?; // This add one element in the scheduler
}

let referendum_index = add_referendum::<T>(r)?;
}: _(RawOrigin::Root, referendum_index)

// Note that we have a separate benchmark for `launch_next`
#[extra]
on_initialize_external {
let r in 0 .. MAX_REFERENDUMS;

Expand Down Expand Up @@ -371,6 +341,7 @@ benchmarks! {
}
}

#[extra]
on_initialize_public {
let r in 1 .. MAX_REFERENDUMS;

Expand Down Expand Up @@ -401,7 +372,8 @@ benchmarks! {
}
}

on_initialize_no_launch_no_maturing {
// No launch no maturing referenda.
on_initialize_base {
let r in 1 .. MAX_REFERENDUMS;

for i in 0..r {
Expand Down Expand Up @@ -526,11 +498,7 @@ benchmarks! {
}

clear_public_proposals {
let p in 0 .. MAX_PROPOSALS;

for i in 0 .. p {
add_proposal::<T>(i)?;
}
add_proposal::<T>(0)?;

}: _(RawOrigin::Root)

Expand Down Expand Up @@ -687,41 +655,36 @@ benchmarks! {
assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed");
}

// Worst case is when target == caller and referendum is ongoing
remove_other_vote {
let r in 1 .. MAX_REFERENDUMS;

let other = funded_account::<T>("other", r);
let caller = funded_account::<T>("caller", r);
let account_vote = account_vote::<T>(100.into());

for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(other.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
}

let votes = match VotingOf::<T>::get(&other) {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct"),
};
assert_eq!(votes.len(), r as usize, "Votes not created");

let referendum_index = r - 1;
ReferendumInfoOf::<T>::insert(
referendum_index,
ReferendumInfo::Finished { end: T::BlockNumber::zero(), approved: true }
);
let caller = funded_account::<T>("caller", 0);

System::<T>::set_block_number(T::EnactmentPeriod::get() * 10u32.into());

}: _(RawOrigin::Signed(caller), other.clone(), referendum_index)
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index)
verify {
let votes = match VotingOf::<T>::get(&other) {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
_ => return Err("Votes are not direct"),
};
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;
Expand All @@ -743,6 +706,7 @@ benchmarks! {
assert_last_event::<T>(RawEvent::Executed(0, false).into());
}

#[extra]
enact_proposal_slash {
// Num of bytes in encoded proposal
let b in 0 .. MAX_BYTES;
Expand Down Expand Up @@ -788,7 +752,7 @@ mod tests {
assert_ok!(test_benchmark_cancel_queued::<Test>());
assert_ok!(test_benchmark_on_initialize_external::<Test>());
assert_ok!(test_benchmark_on_initialize_public::<Test>());
assert_ok!(test_benchmark_on_initialize_no_launch_no_maturing::<Test>());
assert_ok!(test_benchmark_on_initialize_base::<Test>());
assert_ok!(test_benchmark_delegate::<Test>());
assert_ok!(test_benchmark_undelegate::<Test>());
assert_ok!(test_benchmark_clear_public_proposals::<Test>());
Expand Down
Loading