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
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
272 changes: 136 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 4 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 parity_scale_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,12 @@ 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);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -678,13 +678,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 PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
16 changes: 5 additions & 11 deletions runtime/common/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,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::slots::Registrar;
Expand All @@ -595,12 +595,13 @@ 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);
}

impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
Expand All @@ -612,13 +613,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 PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
23 changes: 13 additions & 10 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ where
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_system::limits;
use frame_support::{impl_outer_origin, parameter_types, weights::DispatchClass};
use frame_support::traits::FindAuthor;
use sp_core::H256;
use sp_runtime::{
Expand All @@ -91,9 +92,15 @@ mod 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 BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.for_class(DispatchClass::all(), |weight| {
weight.base_extrinsic = 100;
})
.for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(1024);
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

Expand All @@ -110,13 +117,9 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type BlockLength = BlockLength;
type BlockWeights = BlockWeights;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
82 changes: 55 additions & 27 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ pub mod paras_sudo_wrapper;
pub mod paras_registrar;

use primitives::v1::{BlockNumber, ValidatorId};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber, traits::Saturating};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber};
use frame_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,22 +56,19 @@ const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];

/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic
/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`.
pub const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_perthousand(25);
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_perthousand(25);
/// 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;

const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());

// 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 @@ -80,9 +78,41 @@ 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());
parameter_types! {
/// A limit for off-chain phragmen unsigned solution submission.
///
/// We want to keep it as high as possible, but can't risk having it reject,
/// so we always subtract the base block execution weight.
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic
.expect("Normal extrinsics have weight limit configured by default; qed")
.saturating_sub(BlockExecutionWeight::get());
}

/// 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 @@ -148,14 +178,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: frame_system::limits::BlockLength =
frame_system::limits::BlockLength::max(2 * 1024);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}

impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand All @@ -167,13 +201,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 PalletInfo = ();
type AccountData = ();
Expand All @@ -188,15 +215,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
19 changes: 9 additions & 10 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mod tests {
use primitives::v1::{
Balance, BlockNumber, Header, Signature, AuthorityDiscoveryId,
};
use frame_system::limits;
use frame_support::{
traits::{Randomness, OnInitialize, OnFinalize},
impl_outer_origin, impl_outer_dispatch, assert_ok, parameter_types,
Expand Down Expand Up @@ -299,11 +300,13 @@ mod tests {

#[derive(Clone, Eq, PartialEq)]
pub struct Test;
const NORMAL_RATIO: Perbill = Perbill::from_percent(75);
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: limits::BlockWeights =
limits::BlockWeights::with_sensible_defaults(4 * 1024 * 1024, NORMAL_RATIO);
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
}

impl frame_system::Config for Test {
Expand All @@ -319,13 +322,9 @@ 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 BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u128>;
Expand Down Expand Up @@ -416,7 +415,7 @@ mod tests {
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = MaximumBlockWeight;
type OffchainSolutionWeightLimit = ();
type WeightInfo = ();
}

Expand Down
17 changes: 5 additions & 12 deletions runtime/common/src/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub fn remove_pallet<T>() -> frame_support::weights::Weight
remove_storage_prefix(b"Purchase", b"Statement", b"");
remove_storage_prefix(b"Purchase", b"UnlockBlock", b"");

T::MaximumBlockWeight::get()
<T as frame_system::Config>::BlockWeights::get().max_block
}

#[cfg(test)]
Expand All @@ -393,7 +393,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 @@ -424,12 +424,12 @@ 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);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
Expand All @@ -441,13 +441,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 PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
Expand Down
Loading