polkadot_runtime_common/elections.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17//! Code for elections.
18
19/// Implements the weight types for the elections module and a specific
20/// runtime.
21/// This macro should not be called directly; use
22/// [`impl_runtime_weights`](crate::impl_runtime_weights!) instead.
23#[macro_export]
24macro_rules! impl_elections_weights {
25 ($runtime:ident) => {
26 parameter_types! {
27 /// A limit for off-chain phragmen unsigned solution submission.
28 ///
29 /// We want to keep it as high as possible, but can't risk having it reject,
30 /// so we always subtract the base block execution weight.
31 pub OffchainSolutionWeightLimit: Weight = BlockWeights::get()
32 .get(DispatchClass::Normal)
33 .max_extrinsic
34 .expect("Normal extrinsics have weight limit configured by default; qed")
35 .saturating_sub($runtime::weights::BlockExecutionWeight::get());
36
37 /// A limit for off-chain phragmen unsigned solution length.
38 ///
39 /// We allow up to 90% of the block's size to be consumed by the solution.
40 pub OffchainSolutionLengthLimit: u32 = Perbill::from_rational(90_u32, 100) *
41 *BlockLength::get()
42 .max
43 .get(DispatchClass::Normal);
44 }
45 };
46}
47
48/// The numbers configured here could always be more than the the maximum limits of staking pallet
49/// to ensure election snapshot will not run out of memory. For now, we set them to smaller values
50/// since the staking is bounded and the weight pipeline takes hours for this single pallet.
51pub struct BenchmarkConfig;
52impl pallet_election_provider_multi_phase::BenchmarkingConfig for BenchmarkConfig {
53 const VOTERS: [u32; 2] = [1000, 2000];
54 const TARGETS: [u32; 2] = [500, 1000];
55 const ACTIVE_VOTERS: [u32; 2] = [500, 800];
56 const DESIRED_TARGETS: [u32; 2] = [200, 400];
57 const SNAPSHOT_MAXIMUM_VOTERS: u32 = 1000;
58 const MINER_MAXIMUM_VOTERS: u32 = 1000;
59 const MAXIMUM_TARGETS: u32 = 300;
60}
61
62/// The accuracy type used for genesis election provider;
63pub type OnChainAccuracy = sp_runtime::Perbill;