This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
staking: Flexible generation of reward curve and associated tweaks #8327
Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d461b25
Initial abstraction
gavofyork f77dfcd
Alter rest of APIs
gavofyork 090688b
Fixes
gavofyork 38e9831
Some extra getters in Gilt pallet.
gavofyork 5f947be
Merge remote-tracking branch 'origin/master' into gav-abstract-payout…
gavofyork e6170a5
Refactor Gilt to avoid u128 conversions
gavofyork b15debb
Simplify and improve pow in per_things
gavofyork 42a0be1
Add scalar division to per_things
gavofyork bfae307
Renaming from_fraction -> from_float, drop _approximation
gavofyork 7d5e4d1
Fixes
gavofyork 26c02e7
Merge remote-tracking branch 'origin/master' into gav-abstract-payout…
gavofyork d4ad9ef
Fixes
gavofyork 5f7e5cb
Fixes
gavofyork b9e0e20
Fixes
gavofyork 1acce8e
Make stuff build
gavofyork 096c1bd
Fixes
gavofyork 43baaf2
Fixes
gavofyork af3e62a
Fixes
gavofyork 2c24543
Fixes
gavofyork 1ee20de
Update .gitignore
shawntabrizi e4fecea
Update frame/gilt/src/lib.rs
gavofyork 72f4b11
Update frame/gilt/src/mock.rs
gavofyork 011eb05
Fixes
gavofyork 2fcc109
Merge branch 'gav-abstract-payout-curve' of github.com:paritytech/sub…
gavofyork 06b2e55
Fixes
gavofyork 95efd59
Fixes
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Initial abstraction
- Loading branch information
commit d461b25dfb09263bd8f0e8e929e994081f962a3c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,6 +780,36 @@ impl<T: Config> SessionInterface<<T as frame_system::Config>::AccountId> for T w | |
| } | ||
| } | ||
|
|
||
| pub trait EraPayout<Balance> { | ||
gavofyork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fn era_payout( | ||
| total_staked: Balance, | ||
| total_issuance: Balance, | ||
| era_duration_millis: u64, | ||
| ) -> (Balance, Balance); | ||
| } | ||
|
|
||
| pub struct ConvertCurve<T>(sp_std::marker::PhantomData<T>); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably could use a description |
||
| impl< | ||
| Balance: AtLeast32BitUnsigned + Clone, | ||
| T: Get<&'static PiecewiseLinear<'static>>, | ||
| > EraPayout<Balance> for ConvertCurve<T> { | ||
| fn era_payout( | ||
| total_staked: Balance, | ||
| total_issuance: Balance, | ||
| era_duration_millis: u64, | ||
| ) -> (Balance, Balance) { | ||
| let (validator_payout, max_payout) = inflation::compute_total_payout( | ||
| &T::get(), | ||
| total_staked, | ||
| total_issuance, | ||
| // Duration of era; more than u64::MAX is rewarded as u64::MAX. | ||
| era_duration_millis, | ||
| ); | ||
| let rest = max_payout.saturating_sub(validator_payout.clone()); | ||
| (validator_payout, rest) | ||
| } | ||
| } | ||
|
|
||
| pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> { | ||
| /// The staking balance. | ||
| type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>; | ||
|
|
@@ -836,9 +866,9 @@ pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> { | |
| /// Interface for interacting with a session module. | ||
| type SessionInterface: self::SessionInterface<Self::AccountId>; | ||
|
|
||
| /// The NPoS reward curve used to define yearly inflation. | ||
| /// The payout for validators and the system for the current era. | ||
| /// See [Era payout](./index.html#era-payout). | ||
| type RewardCurve: Get<&'static PiecewiseLinear<'static>>; | ||
| type EraPayout: EraPayout<BalanceOf<Self>>; | ||
|
|
||
| /// Something that can estimate the next session change, accurately or as a best effort guess. | ||
| type NextNewSession: EstimateNextNewSession<Self::BlockNumber>; | ||
|
|
@@ -2831,15 +2861,10 @@ impl<T: Config> Module<T> { | |
| if let Some(active_era_start) = active_era.start { | ||
| let now_as_millis_u64 = T::UnixTime::now().as_millis().saturated_into::<u64>(); | ||
|
|
||
| let era_duration = now_as_millis_u64 - active_era_start; | ||
| let (validator_payout, max_payout) = inflation::compute_total_payout( | ||
| &T::RewardCurve::get(), | ||
| Self::eras_total_stake(&active_era.index), | ||
| T::Currency::total_issuance(), | ||
| // Duration of era; more than u64::MAX is rewarded as u64::MAX. | ||
| era_duration.saturated_into::<u64>(), | ||
| ); | ||
| let rest = max_payout.saturating_sub(validator_payout); | ||
| let era_duration = (now_as_millis_u64 - active_era_start).saturated_into::<u64>(); | ||
| let staked = Self::eras_total_stake(&active_era.index); | ||
| let issuance = T::Currency::total_issuance(); | ||
| let (validator_payout, rest) = T::EraPayout::era_payout(staked, issuance, era_duration); | ||
|
|
||
| Self::deposit_event(RawEvent::EraPayout(active_era.index, validator_payout, rest)); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.