Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rename Fixed128 to FixedI128.
Browse files Browse the repository at this point in the history
  • Loading branch information
seerscode committed Jun 5, 2020
1 parent a891609 commit 218b9a7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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))
}
}
}

0 comments on commit 218b9a7

Please sign in to comment.