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 1 commit
Commits
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
Next Next commit
Fix tx-payment integrity-test
  • Loading branch information
kianenigma committed Jul 10, 2020
commit b2dbc2e8410f6ee010b743029f8e371955bad6f7
2 changes: 2 additions & 0 deletions frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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$(<I>, $instance: $instantiable)?>
$crate::traits::IntegrityTest
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
Expand All @@ -1317,6 +1318,7 @@ macro_rules! decl_module {
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
#[cfg(feature = "std")]
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::IntegrityTest
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
Expand Down
8 changes: 5 additions & 3 deletions frame/transaction-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand All @@ -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",
]
53 changes: 52 additions & 1 deletion frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ type NegativeImbalanceOf<T> =
/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html
pub struct TargetedFeeAdjustment<T, S, V, M>(sp_std::marker::PhantomData<(T, S, V, M)>);

/// Something that can convert the current multiplier to the next one.
pub trait MultiplierUpdate: Convert<Multiplier, Multiplier> {
fn min() -> Multiplier;
fn target() -> Perquintill;
fn v() -> Multiplier;
}

impl MultiplierUpdate for () {
fn min() -> Multiplier {
Default::default()
}
fn target() -> Perquintill {
Default::default()
}
fn v() -> Multiplier {
Default::default()
}
}

impl<T, S, V, M> MultiplierUpdate for TargetedFeeAdjustment<T, S, V, M>
where T: frame_system::Trait, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
{
fn min() -> Multiplier {
M::get()
}
fn target() -> Perquintill {
S::get()
}
fn v() -> Multiplier {
V::get()
}
}

impl<T, S, V, M> Convert<Multiplier, Multiplier> for TargetedFeeAdjustment<T, S, V, M>
where T: frame_system::Trait, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
{
Expand Down Expand Up @@ -192,7 +225,7 @@ pub trait Trait: frame_system::Trait {
type WeightToFee: WeightToFeePolynomial<Balance=BalanceOf<Self>>;

/// Update the multiplier of the next block, based on the previous block's weight.
type FeeMultiplierUpdate: Convert<Multiplier, Multiplier>;
type FeeMultiplierUpdate: MultiplierUpdate;
}

decl_storage! {
Expand Down Expand Up @@ -229,6 +262,24 @@ decl_module! {
<T as frame_system::Trait>::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, we 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;
assert!(addition > 0);
target += addition;

sp_io::TestExternalities::new_empty().execute_with(|| {
<frame_system::Module<T>>::set_block_limits(target, 0);
let next = T::FeeMultiplierUpdate::convert(min_value);
assert!(next > min_value);
})
}
}
}
Expand Down