-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix tx-payment integrity-test #6633
Changes from all commits
b2dbc2e
a681a22
419f7af
fa6f2a1
f0fd1c8
1016b97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,42 @@ 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> { | ||
| /// Minimum multiplier | ||
| fn min() -> Multiplier; | ||
| /// Target block saturation level | ||
| fn target() -> Perquintill; | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// Variability factor | ||
| fn variability() -> Multiplier; | ||
| } | ||
|
|
||
| impl MultiplierUpdate for () { | ||
| fn min() -> Multiplier { | ||
| Default::default() | ||
| } | ||
| fn target() -> Perquintill { | ||
| Default::default() | ||
| } | ||
| fn variability() -> 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 variability() -> 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>, | ||
| { | ||
|
|
@@ -192,7 +228,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! { | ||
|
|
@@ -229,6 +265,32 @@ 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, 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this? If yes, your trait should return an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return an option from the The comment below explains this. In some crates we call Ideally, I prefer this to never allow any |
||
| // this is most likely because in a test setup we set everything to (). | ||
| return; | ||
| } | ||
| 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, "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." | ||
| ); | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.