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 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
841c59f
Change branch.
tomusdrw Jul 16, 2020
03d1983
Update runtime.
tomusdrw Jul 16, 2020
31ee050
Revert "Change branch."
tomusdrw Jul 16, 2020
100e302
Merge branch 'master' into td-6629-companion
tomusdrw Jul 28, 2020
fc38264
Update substrate.
tomusdrw Jul 28, 2020
5b6f37b
Fix tests.
tomusdrw Jul 28, 2020
83c355c
Merge branch 'master' into td-6629-companion
tomusdrw Jul 30, 2020
8d263b0
Merge branch 'master' into td-6629-companion
tomusdrw Aug 5, 2020
1694d39
Fix compilation.
tomusdrw Aug 5, 2020
eee7c59
Fix frame system imports.
tomusdrw Aug 6, 2020
61c9b15
Fix usages of system
tomusdrw Aug 6, 2020
5aac418
Fix stuff.
tomusdrw Aug 7, 2020
1383ce2
Merge branch 'master' into td-6629-companion
tomusdrw Aug 18, 2020
80d1523
Fix compilation.
tomusdrw Aug 18, 2020
516d4f3
Merge branch 'master' into td-6629-companion
tomusdrw Aug 20, 2020
5f6d986
Merge branch 'master' into td-6629-companion
tomusdrw Sep 9, 2020
d96a9bc
Merge branch 'master' into td-6629-companion
tomusdrw Sep 22, 2020
716628c
Merge branch 'master' into td-6629-companion
tomusdrw Sep 23, 2020
c474b3e
Merge branch 'master' into td-6629-companion
tomusdrw Nov 17, 2020
a5441ed
Fixes.
tomusdrw Nov 18, 2020
3f0704c
Merge branch 'master' into td-6629-companion
tomusdrw Nov 25, 2020
ab0fcf0
Merge branch 'master' into td-6629-companion
tomusdrw Dec 3, 2020
ca889b6
Fix block_weight usage.
tomusdrw Dec 3, 2020
f3502f0
Merge branch 'master' into td-6629-companion
tomusdrw Dec 3, 2020
2c96927
Merge branch 'master' into td-6629-companion
tomusdrw Dec 8, 2020
08c9ddc
Bump substrate.
tomusdrw Dec 8, 2020
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
17 changes: 6 additions & 11 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ mod tests {
use codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, assert_noop, parameter_types,
ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::ExistenceRequirement,
Expand All @@ -661,12 +661,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
Comment thread
tomusdrw marked this conversation as resolved.
Outdated
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -678,13 +680,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
18 changes: 7 additions & 11 deletions runtime/common/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sp_runtime::{
Perbill, Permill, Percent, testing::Header, DispatchResult,
Permill, Percent, testing::Header, DispatchResult,
traits::{BlakeTwo256, IdentityLookup},
};
use crate::registrar::Registrar;
Expand All @@ -588,12 +588,15 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}

impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
Expand All @@ -605,13 +608,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
69 changes: 43 additions & 26 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ pub mod impls;
pub mod paras_sudo_wrapper;

use primitives::v0::BlockNumber;
use sp_runtime::{Perquintill, Perbill, FixedPointNumber, traits::Saturating};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber};
use system::limits;
use frame_support::{
parameter_types, traits::{Currency},
weights::{Weight, constants::WEIGHT_PER_SECOND},
weights::{Weight, constants::WEIGHT_PER_SECOND, DispatchClass},
};
use pallet_transaction_payment::{TargetedFeeAdjustment, Multiplier};
use static_assertions::const_assert;
Expand All @@ -55,21 +56,17 @@ pub type NegativeImbalance<T> = <pallet_balances::Module<T> as Currency<<T as fr

/// We assume that an on-initialize consumes 10% of the weight on average, hence a single extrinsic
/// will not be allowed to consume more than `AvailableBlockRatio - 10%`.
const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10);
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;

// Common constants used in all runtimes.
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// Block time that can be used by weights.
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
/// Portion of the block available to normal class of dispatches.
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Maximum weight that a _single_ extrinsic can take.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT) * MaximumBlockWeight::get();
/// Maximum length of block. 5MB.
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
/// The portion of the `AvailableBlockRatio` that we adjust the fees with. Blocks filled less
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
Expand All @@ -79,9 +76,31 @@ parameter_types! {
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);
/// Maximum length of block. Up to 5MB.
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
/// Block weights base values and limits.
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have an extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
}

const_assert!(AvailableBlockRatio::get().deconstruct() >= AVERAGE_ON_INITIALIZE_WEIGHT.deconstruct());
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
Comment thread
kianenigma marked this conversation as resolved.
Outdated

/// Parameterized slow adjusting fee updated based on
/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism
Expand Down Expand Up @@ -112,14 +131,18 @@ mod multiplier_tests {

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const ExtrinsicBaseWeight: u64 = 100;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockLength: system::limits::BlockLength =
system::limits::BlockLength::max(2 * 1024);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(1024);
}

impl frame_system::Trait for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand All @@ -131,13 +154,6 @@ mod multiplier_tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
Expand All @@ -152,15 +168,16 @@ mod multiplier_tests {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap().into();
t.execute_with(|| {
System::set_block_limits(w, 0);
System::set_block_consumed_resources(w, 0);
assertions()
});
}

#[test]
fn multiplier_can_grow_from_zero() {
let minimum_multiplier = MinimumMultiplier::get();
let target = TargetBlockFullness::get() * (AvailableBlockRatio::get() * MaximumBlockWeight::get());
let target = TargetBlockFullness::get() *
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
// if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/10th bigger than target.
run_with_system_weight(target * 101 / 100, || {
Expand Down
17 changes: 6 additions & 11 deletions runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,13 +1724,15 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}

impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -1742,13 +1744,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u128>;
Expand Down Expand Up @@ -1953,7 +1948,7 @@ mod tests {
}

parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
}

impl pallet_offences::Trait for Test {
Expand Down
17 changes: 6 additions & 11 deletions runtime/common/src/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{
Perbill, MultiSignature,
MultiSignature,
traits::{BlakeTwo256, IdentityLookup, Identity, Verify, IdentifyAccount, Dispatchable},
testing::Header
};
Expand Down Expand Up @@ -410,12 +410,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -427,13 +429,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
15 changes: 5 additions & 10 deletions runtime/common/src/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -733,13 +735,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u128>;
Expand Down
20 changes: 6 additions & 14 deletions runtime/common/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,7 @@ mod tests {
use std::{collections::HashMap, cell::RefCell};

use sp_core::H256;
use sp_runtime::{
Perbill,
traits::{BlakeTwo256, Hash, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, Hash, IdentityLookup};
use frame_support::{
impl_outer_origin, parameter_types, assert_ok, assert_noop,
traits::{OnInitialize, OnFinalize}
Expand All @@ -903,12 +900,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: system::limits::BlockWeights =
system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
Expand All @@ -920,13 +919,6 @@ mod tests {
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 ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
Loading