Make staking inflation curve configurable. (#3644)

* Draft for new design of NPoS rewards

* finish code

* fix test

* add tests

* improve log test

* version bump

* Update srml/staking/reward-curve/Cargo.toml

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* u128 -> u64

* make conversion to smaller type safe

* Update core/sr-primitives/src/curve.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
thiolliere
2019-09-21 06:47:10 +02:00
committed by Gavin Wood
parent 68cda2fe79
commit c25d7386cf
15 changed files with 833 additions and 378 deletions
+12 -5
View File
@@ -261,11 +261,14 @@ use support::{
}
};
use session::{historical::OnSessionEnding, SelectInitialValidators};
use sr_primitives::Perbill;
use sr_primitives::weights::SimpleDispatchInfo;
use sr_primitives::traits::{
Convert, Zero, One, StaticLookup, CheckedSub, Saturating, Bounded, SimpleArithmetic,
SaturatedConversion,
use sr_primitives::{
Perbill,
curve::PiecewiseLinear,
weights::SimpleDispatchInfo,
traits::{
Convert, Zero, One, StaticLookup, CheckedSub, Saturating, Bounded, SimpleArithmetic,
SaturatedConversion,
}
};
use phragmen::{elect, equalize, Support, SupportMap, ExtendedBalance, ACCURACY};
use sr_staking_primitives::{
@@ -523,6 +526,9 @@ pub trait Trait: system::Trait {
/// Interface for interacting with a session module.
type SessionInterface: self::SessionInterface<Self::AccountId>;
/// The NPoS reward curve to use.
type RewardCurve: Get<&'static PiecewiseLinear<'static>>;
}
/// Mode of era-forcing.
@@ -1173,6 +1179,7 @@ impl<T: Trait> Module<T> {
let total_rewarded_stake = Self::slot_stake() * validator_len;
let total_payout = inflation::compute_total_payout(
&T::RewardCurve::get(),
total_rewarded_stake.clone(),
T::Currency::total_issuance(),
// Duration of era; more than u64::MAX is rewarded as u64::MAX.