Per-things trait. (#4904)

* Give perthigns the trait it always deserved.

* Make staking and phragmen work with the new generic per_thing

* Make everything work together 🔨

* a bit of cleanup

* Clean usage

* Bump.

* Fix name

* fix grumbles

* hopefully fix the ui test

* Some grumbles

* revamp traits again

* Better naming again.
This commit is contained in:
Kian Paimani
2020-02-13 13:09:33 +01:00
committed by GitHub
parent e6454eb091
commit c871eaacbc
42 changed files with 346 additions and 241 deletions
+2 -2
View File
@@ -19,7 +19,7 @@
//! The staking rate in NPoS is the total amount of tokens staked by nominators and validators,
//! divided by the total token supply.
use sp_runtime::{Perbill, traits::SimpleArithmetic, curve::PiecewiseLinear};
use sp_runtime::{Perbill, PerThing, traits::AtLeast32Bit, curve::PiecewiseLinear};
/// The total payout to all validators (and their nominators) per era.
///
@@ -32,7 +32,7 @@ pub fn compute_total_payout<N>(
npos_token_staked: N,
total_tokens: N,
era_duration: u64
) -> (N, N) where N: SimpleArithmetic + Clone {
) -> (N, N) where N: AtLeast32Bit + Clone {
// Milliseconds per year for the Julian year (365.25 days).
const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100;
+6 -7
View File
@@ -267,12 +267,11 @@ use frame_support::{
};
use pallet_session::historical::SessionManager;
use sp_runtime::{
Perbill,
RuntimeDebug,
Perbill, PerThing, RuntimeDebug,
curve::PiecewiseLinear,
traits::{
Convert, Zero, One, StaticLookup, CheckedSub, Saturating, Bounded, SaturatedConversion,
SimpleArithmetic, EnsureOrigin,
AtLeast32Bit, EnsureOrigin,
}
};
use sp_staking::{
@@ -396,7 +395,7 @@ pub struct StakingLedger<AccountId, Balance: HasCompact> {
impl<
AccountId,
Balance: HasCompact + Copy + Saturating + SimpleArithmetic,
Balance: HasCompact + Copy + Saturating + AtLeast32Bit,
> StakingLedger<AccountId, Balance> {
/// Remove entries from `unlocking` that are sufficiently old and reduce the
/// total by the sum of their balances.
@@ -440,7 +439,7 @@ impl<
}
impl<AccountId, Balance> StakingLedger<AccountId, Balance> where
Balance: SimpleArithmetic + Saturating + Copy,
Balance: AtLeast32Bit + Saturating + Copy,
{
/// Slash the validator for a given amount of balance. This can grow the value
/// of the slash in the case that the validator has less than `minimum_balance`
@@ -1503,7 +1502,7 @@ impl<T: Trait> Module<T> {
});
all_nominators.extend(nominator_votes);
let maybe_phragmen_result = sp_phragmen::elect::<_, _, _, T::CurrencyToVote>(
let maybe_phragmen_result = sp_phragmen::elect::<_, _, _, T::CurrencyToVote, Perbill>(
Self::validator_count() as usize,
Self::minimum_validator_count().max(1) as usize,
all_validators,
@@ -1520,7 +1519,7 @@ impl<T: Trait> Module<T> {
let to_balance = |e: ExtendedBalance|
<T::CurrencyToVote as Convert<ExtendedBalance, BalanceOf<T>>>::convert(e);
let supports = sp_phragmen::build_support_map::<_, _, _, T::CurrencyToVote>(
let supports = sp_phragmen::build_support_map::<_, _, _, T::CurrencyToVote, Perbill>(
&elected_stashes,
&assignments,
Self::slashable_balance_of,
+1 -1
View File
@@ -52,7 +52,7 @@ use super::{
EraIndex, Trait, Module, Store, BalanceOf, Exposure, Perbill, SessionInterface,
NegativeImbalanceOf, UnappliedSlash,
};
use sp_runtime::traits::{Zero, Saturating};
use sp_runtime::{traits::{Zero, Saturating}, PerThing};
use frame_support::{
StorageMap, StorageDoubleMap,
traits::{Currency, OnUnbalanced, Imbalance},