Unverified Commit 473af3b1 authored by Marcio Diaz's avatar Marcio Diaz Committed by GitHub
Browse files

Companion PR for #6214 (#1204)



* Rename Fixed128 to FixedI128.

* Bump cargo, merge #6236 fixes

Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>
parent f9b27295
Pipeline #95550 passed with stages
in 22 minutes and 32 seconds
This diff is collapsed.
......@@ -17,7 +17,7 @@
//! Auxillary struct/enums for polkadot runtime.
use sp_runtime::traits::{Convert, Saturating};
use sp_runtime::{FixedPointNumber, Fixed128, Perquintill};
use sp_runtime::{FixedPointNumber, FixedI128, Perquintill};
use frame_support::traits::{OnUnbalanced, Imbalance, Currency, Get};
use crate::{MaximumBlockWeight, NegativeImbalance};
......@@ -83,8 +83,8 @@ where
/// https://research.web3.foundation/en/latest/polkadot/Token%20Economics/#relay-chain-transaction-fees
pub struct TargetedFeeAdjustment<T, R>(sp_std::marker::PhantomData<(T, R)>);
impl<T: Get<Perquintill>, R: system::Trait> Convert<Fixed128, Fixed128> for TargetedFeeAdjustment<T, R> {
fn convert(multiplier: Fixed128) -> Fixed128 {
impl<T: Get<Perquintill>, R: system::Trait> Convert<FixedI128, FixedI128> for TargetedFeeAdjustment<T, R> {
fn convert(multiplier: FixedI128) -> FixedI128 {
let max_weight = MaximumBlockWeight::get();
let block_weight = <system::Module<R>>::block_weight().total().min(max_weight);
let target_weight = (T::get() * max_weight) as u128;
......@@ -94,14 +94,14 @@ impl<T: Get<Perquintill>, R: system::Trait> Convert<Fixed128, Fixed128> for Targ
let positive = block_weight >= target_weight;
let diff_abs = block_weight.max(target_weight) - block_weight.min(target_weight);
// safe, diff_abs cannot exceed u64 and it can always be computed safely even with the lossy
// `Fixed128::saturating_from_rational`.
let diff = Fixed128::saturating_from_rational(diff_abs, max_weight.max(1));
// `FixedI128::saturating_from_rational`.
let diff = FixedI128::saturating_from_rational(diff_abs, max_weight.max(1));
let diff_squared = diff.saturating_mul(diff);
// 0.00004 = 4/100_000 = 40_000/10^9
let v = Fixed128::saturating_from_rational(4, 100_000);
let v = FixedI128::saturating_from_rational(4, 100_000);
// 0.00004^2 = 16/10^10 Taking the future /2 into account... 8/10^10
let v_squared_2 = Fixed128::saturating_from_rational(8, 10_000_000_000u64);
let v_squared_2 = FixedI128::saturating_from_rational(8, 10_000_000_000u64);
let first_term = v.saturating_mul(diff);
let second_term = v_squared_2.saturating_mul(diff_squared);
......@@ -120,7 +120,7 @@ impl<T: Get<Perquintill>, R: system::Trait> Convert<Fixed128, Fixed128> for Targ
// multiplier. While at -1, it means that the network is so un-congested that all
// transactions have no weight fee. We stop here and only increase if the network
// became more busy.
.max(Fixed128::saturating_from_integer(-1))
.max(FixedI128::saturating_from_integer(-1))
}
}
}
......@@ -874,7 +874,7 @@ construct_runtime! {
Scheduler: scheduler::{Module, Call, Storage, Event<T>},
// Proxy module. Late addition.
Proxy: proxy::{Module, Call, Storage, Event}
Proxy: proxy::{Module, Call, Storage, Event<T>}
}
}
......
......@@ -850,7 +850,7 @@ construct_runtime! {
Identity: identity::{Module, Call, Storage, Event<T>},
// Proxy module. Late addition.
Proxy: proxy::{Module, Call, Storage, Event}
Proxy: proxy::{Module, Call, Storage, Event<T>}
}
}
......
......@@ -664,7 +664,7 @@ construct_runtime! {
Sudo: sudo::{Module, Call, Storage, Event<T>, Config<T>},
// Proxy module. Late addition.
Proxy: proxy::{Module, Call, Storage, Event}
Proxy: proxy::{Module, Call, Storage, Event<T>}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment