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 2 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2416411
Implement Fixed trait.
seerscode May 1, 2020
0c0c1da
Merge branch 'master' into md-fixed-point
seerscode May 4, 2020
aa5d54d
Fix tests
seerscode May 4, 2020
854e24b
Fix tests
seerscode May 4, 2020
1b0bf3d
Fix tests 2
seerscode May 4, 2020
087bca8
Address review comment regarding from_i129.
seerscode May 4, 2020
45b625a
Remove precision by using log10() as suggested in review.
seerscode May 4, 2020
7868978
Add small comments.
seerscode May 4, 2020
14e1fac
Use checked versions + panic for ops::*.
seerscode May 4, 2020
2133c2f
Remove repeated test.
seerscode May 4, 2020
6c34aba
Uncomment test.
seerscode May 4, 2020
9c93490
Remove casts.
seerscode May 4, 2020
091991c
Add more comments.
seerscode May 5, 2020
9ed7371
Add tests.
seerscode May 5, 2020
838b97e
Panic on saturating_div_int
seerscode May 5, 2020
86408cd
More tests.
seerscode May 5, 2020
5819666
More docs.
seerscode May 6, 2020
b1647ec
Saturating renames.
seerscode May 6, 2020
698a452
Fix to_bound doc.
seerscode May 6, 2020
75d5756
Move some impl to trait.
seerscode May 6, 2020
a119bfa
Add range
seerscode May 6, 2020
993e821
Add macro pre.
seerscode May 6, 2020
d742b5e
More round() tests.
seerscode May 6, 2020
514c76b
Delete confusion.
seerscode May 7, 2020
0f05701
Merge branch 'master' into md-fixed-point
seerscode May 7, 2020
c0deb6c
More impl to trait
seerscode May 7, 2020
c39cd72
Add doc for fixedpoint op.
seerscode May 7, 2020
e4a4bac
Remove trailing spaces.
seerscode May 7, 2020
caebcad
Suggested docs changes.
seerscode May 7, 2020
881a8e0
More tests and comments for roundings.
seerscode May 7, 2020
50856ea
Some quickcheck tests.
seerscode May 7, 2020
afd0e2e
Add missing panic, more test/comments.
seerscode May 11, 2020
917fa0d
Merge branch 'master' into md-fixed-point
seerscode May 12, 2020
19460a7
Nits.
seerscode May 12, 2020
a6f4fd2
Rename.
seerscode May 12, 2020
fd8f6c0
Remove primitives-types import.
seerscode May 14, 2020
3054ba2
Merge branch 'master' into md-fixed-point
seerscode May 18, 2020
e730534
Apply review suggestions
seerscode May 18, 2020
9b4369c
Fix long lines and add some fuzz.
seerscode May 19, 2020
cb9b29e
fix long line
seerscode May 19, 2020
2907c24
Update fuzzer
seerscode May 21, 2020
bfa811f
Merge branch 'master' into md-fixed-point
seerscode May 21, 2020
66eb8d0
Bump impl
seerscode May 21, 2020
0ef1888
Merge branch 'master' into md-fixed-point
gavofyork May 21, 2020
b5543d1
fix warnings
shawntabrizi May 21, 2020
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
17 changes: 6 additions & 11 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

//! Some configurable implementations as associated type for the substrate runtime.

use core::num::NonZeroI128;
use node_primitives::Balance;
use sp_runtime::traits::{Convert, Saturating};
use sp_runtime::{Fixed128, Perquintill};
use sp_runtime::{FixedPointNumber, Fixed128, Perquintill};
use frame_support::{traits::{OnUnbalanced, Currency, Get}, weights::Weight};
use crate::{Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance};

Expand Down Expand Up @@ -78,18 +77,14 @@ impl<T: Get<Perquintill>> Convert<Fixed128, Fixed128> for TargetedFeeAdjustment<
// determines if the first_term is positive
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::from_rational`.
let diff = Fixed128::from_rational(
diff_abs as i128,
NonZeroI128::new(max_weight.max(1) as i128).unwrap(),
);
// safe, diff_abs cannot exceed u64.
let diff = Fixed128::from_rational(diff_abs as i128, max_weight.max(1) as i128);
let diff_squared = diff.saturating_mul(diff);

// 0.00004 = 4/100_000 = 40_000/10^9
let v = Fixed128::from_rational(4, NonZeroI128::new(100_000).unwrap());
let v = Fixed128::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::from_rational(8, NonZeroI128::new(10_000_000_000).unwrap());
let v_squared_2 = Fixed128::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 @@ -108,7 +103,7 @@ impl<T: Get<Perquintill>> Convert<Fixed128, Fixed128> for TargetedFeeAdjustment<
// 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::from_natural(-1))
.max(Fixed128::from_integer(-1))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
dispatch::DispatchResult,
};
use sp_runtime::{
Fixed128,
Fixed128, FixedPointNumber,
transaction_validity::{
TransactionPriority, ValidTransaction, InvalidTransaction, TransactionValidityError,
TransactionValidity,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub trait Trait: frame_system::Trait {

decl_storage! {
trait Store for Module<T: Trait> as TransactionPayment {
pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_parts(0);
pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_inner(0);
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ impl<T: Trait> Module<T> {
// the adjustable part of the fee
let adjustable_fee = len_fee.saturating_add(unadjusted_weight_fee);
let targeted_fee_adjustment = NextFeeMultiplier::get();
let adjusted_fee = targeted_fee_adjustment.saturated_multiply_accumulate(adjustable_fee.saturated_into());
let adjusted_fee = targeted_fee_adjustment.saturating_mul_int_acc(adjustable_fee.saturated_into());

let base_fee = Self::weight_to_fee(T::ExtrinsicBaseWeight::get());
base_fee.saturating_add(adjusted_fee.saturated_into()).saturating_add(tip)
Expand All @@ -174,7 +174,7 @@ impl<T: Trait> Module<T> {
{
let fee = UniqueSaturatedInto::<u128>::unique_saturated_into(Self::weight_to_fee(weight));
UniqueSaturatedFrom::unique_saturated_from(
NextFeeMultiplier::get().saturated_multiply_accumulate(fee)
NextFeeMultiplier::get().saturating_mul_int_acc(fee)
)
}

Expand Down
Loading