diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 810c67e039b05..2d9e61323b838 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1302,6 +1302,7 @@ macro_rules! decl_module { $(#[doc = $doc_attr:tt])* fn integrity_test() { $( $impl:tt )* } ) => { + #[cfg(feature = "std")] impl<$trait_instance: $trait_name$(, $instance: $instantiable)?> $crate::traits::IntegrityTest for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* @@ -1317,6 +1318,7 @@ macro_rules! decl_module { $module:ident<$trait_instance:ident: $trait_name:ident$(, $instance:ident: $instantiable:path)?>; { $( $other_where_bounds:tt )* } ) => { + #[cfg(feature = "std")] impl<$trait_instance: $trait_name$(, $instance: $instantiable)?> $crate::traits::IntegrityTest for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* diff --git a/frame/transaction-payment/Cargo.toml b/frame/transaction-payment/Cargo.toml index cc26af45d7948..4c88b0168901b 100644 --- a/frame/transaction-payment/Cargo.toml +++ b/frame/transaction-payment/Cargo.toml @@ -20,10 +20,10 @@ frame-support = { version = "2.0.0-rc4", default-features = false, path = "../su frame-system = { version = "2.0.0-rc4", default-features = false, path = "../system" } pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0-rc4", default-features = false, path = "./rpc/runtime-api" } smallvec = "1.4.1" +sp-io = { version = "2.0.0-rc4", path = "../../primitives/io", default-features = false } +sp-core = { version = "2.0.0-rc4", path = "../../primitives/core", default-features = false } [dev-dependencies] -sp-io = { version = "2.0.0-rc4", path = "../../primitives/io" } -sp-core = { version = "2.0.0-rc4", path = "../../primitives/core" } pallet-balances = { version = "2.0.0-rc4", path = "../balances" } sp-storage = { version = "2.0.0-rc4", path = "../../primitives/storage" } @@ -36,5 +36,7 @@ std = [ "sp-runtime/std", "frame-support/std", "frame-system/std", - "pallet-transaction-payment-rpc-runtime-api/std" + "pallet-transaction-payment-rpc-runtime-api/std", + "sp-io/std", + "sp-core/std", ] diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 96fbd1068d57d..9c624df8ca355 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -111,6 +111,42 @@ type NegativeImbalanceOf = /// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html pub struct TargetedFeeAdjustment(sp_std::marker::PhantomData<(T, S, V, M)>); +/// Something that can convert the current multiplier to the next one. +pub trait MultiplierUpdate: Convert { + /// Minimum multiplier + fn min() -> Multiplier; + /// Target block saturation level + fn target() -> Perquintill; + /// Variability factor + fn variability() -> Multiplier; +} + +impl MultiplierUpdate for () { + fn min() -> Multiplier { + Default::default() + } + fn target() -> Perquintill { + Default::default() + } + fn variability() -> Multiplier { + Default::default() + } +} + +impl MultiplierUpdate for TargetedFeeAdjustment + where T: frame_system::Trait, S: Get, V: Get, M: Get, +{ + fn min() -> Multiplier { + M::get() + } + fn target() -> Perquintill { + S::get() + } + fn variability() -> Multiplier { + V::get() + } +} + impl Convert for TargetedFeeAdjustment where T: frame_system::Trait, S: Get, V: Get, M: Get, { @@ -192,7 +228,7 @@ pub trait Trait: frame_system::Trait { type WeightToFee: WeightToFeePolynomial>; /// Update the multiplier of the next block, based on the previous block's weight. - type FeeMultiplierUpdate: Convert; + type FeeMultiplierUpdate: MultiplierUpdate; } decl_storage! { @@ -229,6 +265,32 @@ decl_module! { ::MaximumBlockWeight::get().try_into().unwrap() ).unwrap(), ); + + // This is the minimum value of the multiplier. Make sure that if we collapse to this + // value, we can recover with a reasonable amount of traffic. For this test we assert + // that if we collapse to minimum, the trend will be positive with a weight value + // which is 1% more than the target. + let min_value = T::FeeMultiplierUpdate::min(); + let mut target = + T::FeeMultiplierUpdate::target() * + (T::AvailableBlockRatio::get() * T::MaximumBlockWeight::get()); + + // add 1 percent; + let addition = target / 100; + if addition == 0 { + // this is most likely because in a test setup we set everything to (). + return; + } + target += addition; + + sp_io::TestExternalities::new_empty().execute_with(|| { + >::set_block_limits(target, 0); + let next = T::FeeMultiplierUpdate::convert(min_value); + assert!(next > min_value, "The minimum bound of the multiplier is too low. When \ + block saturation is more than target by 1% and multiplier is minimal then \ + the multiplier doesn't increase." + ); + }) } } }