Streamline frame_system weight parametrization (#6629)

* Basic weights builder.

* Fixing WiP

* Make the tests work.

* Fix weights in node/runtime.

* WiP.

* Update pallets with new weights parameters.

* Validate returns a Result now.

* Count mandatory weight separately.

* DRY

* BREAKING: Updating state root, because of the left-over weight-tracking stuff

* Update tests affected by Mandatory tracking.

* Fixing tests.

* Fix defaults for simple_max

* Update frame/system/src/weights.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Rework the API a bit.

* Fix compilation & tests.

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Add extra docs & rename few things.

* Fix whitespace in ASCII art.

* Update frame/system/src/limits.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix max_extrinsic calculations.

* Fix conflicts.

* Fix compilation.

* Fix new code.

* re-remove generic asset

* Fix usage.

* Update state root.

* Update proxy.

* Fix tests.

* Move weights validity to integrity_test

* Remove redundant BlockWeights.

* Add all/non_mandatory comment

* Add test.

* Remove fn block_weights

* Make the macro prettier.

* Fix some docs.

* Make max_total behave more predictabily.

* Add BlockWeights to metadata.

* fix balances test

* Fix utility test.

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Tomasz Drwięga
2020-12-08 13:18:34 +01:00
committed by GitHub
parent f6198b4c1b
commit 39a776cd00
66 changed files with 1275 additions and 929 deletions
+15 -14
View File
@@ -533,7 +533,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn bid(origin, value: BalanceOf<T, I>) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(!<SuspendedCandidates<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
@@ -572,7 +572,7 @@ decl_module! {
///
/// Total Complexity: O(B + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn unbid(origin, pos: u32) -> DispatchResult {
let who = ensure_signed(origin)?;
@@ -642,7 +642,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn vouch(origin, who: T::AccountId, value: BalanceOf<T, I>, tip: BalanceOf<T, I>) -> DispatchResult {
let voucher = ensure_signed(origin)?;
// Check user is not suspended.
@@ -683,7 +683,7 @@ decl_module! {
///
/// Total Complexity: O(B)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn unvouch(origin, pos: u32) -> DispatchResult {
let voucher = ensure_signed(origin)?;
ensure!(Self::vouching(&voucher) == Some(VouchingStatus::Vouching), Error::<T, I>::NotVouching);
@@ -721,7 +721,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + C)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn vote(origin, candidate: <T::Lookup as StaticLookup>::Source, approve: bool) {
let voter = ensure_signed(origin)?;
let candidate = T::Lookup::lookup(candidate)?;
@@ -752,7 +752,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn defender_vote(origin, approve: bool) {
let voter = ensure_signed(origin)?;
let members = <Members<T, I>>::get();
@@ -784,7 +784,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + P + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn payout(origin) {
let who = ensure_signed(origin)?;
@@ -826,7 +826,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn found(origin, founder: T::AccountId, max_members: u32, rules: Vec<u8>) {
T::FounderSetOrigin::ensure_origin(origin)?;
ensure!(!<Head<T, I>>::exists(), Error::<T, I>::AlreadyFounded);
@@ -853,7 +853,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn unfound(origin) {
let founder = ensure_signed(origin)?;
ensure!(Founder::<T, I>::get() == Some(founder.clone()), Error::<T, I>::NotFounder);
@@ -895,7 +895,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn judge_suspended_member(origin, who: T::AccountId, forgive: bool) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
ensure!(<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::NotSuspended);
@@ -966,7 +966,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn judge_suspended_candidate(origin, who: T::AccountId, judgement: Judgement) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
if let Some((value, kind)) = <SuspendedCandidates<T, I>>::get(&who) {
@@ -1026,7 +1026,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn set_max_members(origin, max: u32) {
ensure_root(origin)?;
ensure!(max > 1, Error::<T, I>::MaxMembers);
@@ -1038,13 +1038,14 @@ decl_module! {
let mut members = vec![];
let mut weight = 0;
let weights = T::BlockWeights::get();
// Run a candidate/membership rotation
if (n % T::RotationPeriod::get()).is_zero() {
members = <Members<T, I>>::get();
Self::rotate_period(&mut members);
weight += T::MaximumBlockWeight::get() / 20;
weight += weights.max_block / 20;
}
// Run a challenge rotation
@@ -1055,7 +1056,7 @@ decl_module! {
}
Self::rotate_challenge(&mut members);
weight += T::MaximumBlockWeight::get() / 20;
weight += weights.max_block / 20;
}
weight
+5 -13
View File
@@ -25,7 +25,6 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
Perbill,
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
@@ -45,14 +44,11 @@ parameter_types! {
pub const PeriodSpend: u64 = 1000;
pub const MaxLockDuration: u64 = 100;
pub const ChallengePeriod: u64 = 8;
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const ExistentialDeposit: u64 = 1;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
ord_parameter_types! {
@@ -62,6 +58,9 @@ ord_parameter_types! {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -73,13 +72,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type OnNewAccount = ();