mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -19,8 +19,12 @@
|
||||
|
||||
//! Useful function for inflation for nominated proof of stake.
|
||||
|
||||
use sp_arithmetic::{Perquintill, PerThing, biguint::BigUint, traits::{Zero, SaturatedConversion}};
|
||||
use core::convert::TryFrom;
|
||||
use sp_arithmetic::{
|
||||
biguint::BigUint,
|
||||
traits::{SaturatedConversion, Zero},
|
||||
PerThing, Perquintill,
|
||||
};
|
||||
|
||||
/// Compute yearly inflation using function
|
||||
///
|
||||
@@ -54,11 +58,7 @@ use core::convert::TryFrom;
|
||||
/// the global incentivization to get the `ideal_stake`. A higher number results in less typical
|
||||
/// inflation at the cost of greater volatility for validators.
|
||||
/// Must be more than 0.01.
|
||||
pub fn compute_inflation<P: PerThing>(
|
||||
stake: P,
|
||||
ideal_stake: P,
|
||||
falloff: P,
|
||||
) -> P {
|
||||
pub fn compute_inflation<P: PerThing>(stake: P, ideal_stake: P, falloff: P) -> P {
|
||||
if stake < ideal_stake {
|
||||
// ideal_stake is more than 0 because it is strictly more than stake
|
||||
return stake / ideal_stake
|
||||
@@ -98,9 +98,7 @@ pub fn compute_inflation<P: PerThing>(
|
||||
let res = compute_taylor_serie_part(&inpos_param);
|
||||
|
||||
match u128::try_from(res.clone()) {
|
||||
Ok(res) if res <= Into::<u128>::into(P::ACCURACY) => {
|
||||
P::from_parts(res.saturated_into())
|
||||
},
|
||||
Ok(res) if res <= Into::<u128>::into(P::ACCURACY) => P::from_parts(res.saturated_into()),
|
||||
// If result is beyond bounds there is nothing we can do
|
||||
_ => {
|
||||
log::error!("Invalid inflation computation: unexpected result {:?}", res);
|
||||
@@ -109,7 +107,6 @@ pub fn compute_inflation<P: PerThing>(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Internal struct holding parameter info alongside other cached value.
|
||||
///
|
||||
/// All expressed in part from `accuracy`
|
||||
@@ -149,12 +146,15 @@ fn compute_taylor_serie_part(p: &INPoSParam) -> BigUint {
|
||||
taylor_sum = taylor_sum.add(&last_taylor_term);
|
||||
} else {
|
||||
if taylor_sum >= last_taylor_term {
|
||||
taylor_sum = taylor_sum.sub(&last_taylor_term)
|
||||
taylor_sum = taylor_sum
|
||||
.sub(&last_taylor_term)
|
||||
// NOTE: Should never happen as checked above
|
||||
.unwrap_or_else(|e| e);
|
||||
} else {
|
||||
taylor_sum_positive = !taylor_sum_positive;
|
||||
taylor_sum = last_taylor_term.clone().sub(&taylor_sum)
|
||||
taylor_sum = last_taylor_term
|
||||
.clone()
|
||||
.sub(&taylor_sum)
|
||||
// NOTE: Should never happen as checked above
|
||||
.unwrap_or_else(|e| e);
|
||||
}
|
||||
@@ -180,14 +180,13 @@ fn compute_taylor_serie_part(p: &INPoSParam) -> BigUint {
|
||||
///
|
||||
/// `previous_taylor_term` and result are expressed with accuracy `INPoSParam.accuracy`
|
||||
fn compute_taylor_term(k: u32, previous_taylor_term: &BigUint, p: &INPoSParam) -> BigUint {
|
||||
let x_minus_x_ideal = p.x.clone().sub(&p.x_ideal)
|
||||
// NOTE: Should never happen, as x must be more than x_ideal
|
||||
.unwrap_or_else(|_| BigUint::zero());
|
||||
let x_minus_x_ideal =
|
||||
p.x.clone()
|
||||
.sub(&p.x_ideal)
|
||||
// NOTE: Should never happen, as x must be more than x_ideal
|
||||
.unwrap_or_else(|_| BigUint::zero());
|
||||
|
||||
let res = previous_taylor_term.clone()
|
||||
.mul(&x_minus_x_ideal)
|
||||
.mul(&p.ln2_div_d)
|
||||
.div_unit(k);
|
||||
let res = previous_taylor_term.clone().mul(&x_minus_x_ideal).mul(&p.ln2_div_d).div_unit(k);
|
||||
|
||||
// p.accuracy is stripped by definition.
|
||||
let res = div_by_stripped(res, &p.accuracy);
|
||||
@@ -230,7 +229,5 @@ fn div_by_stripped(mut a: BigUint, b: &BigUint) -> BigUint {
|
||||
.div_unit(100_000)
|
||||
}
|
||||
|
||||
a.div(b, false)
|
||||
.map(|res| res.0)
|
||||
.unwrap_or_else(|| BigUint::zero())
|
||||
a.div(b, false).map(|res| res.0).unwrap_or_else(|| BigUint::zero())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user