From d5b11382d0b261e75464bbd9a75cd267e2d56a5b Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Wed, 12 Aug 2020 14:59:15 -0400 Subject: [PATCH] Era rewards point support I also did some refactoring. --- src/frame/staking.rs | 94 ++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 69 deletions(-) diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 1830d70564..ea9ee1a241 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -25,37 +25,28 @@ use codec::{ Encode, }; use frame_support::Parameter; -use sp_runtime::{ - traits::{ - AtLeast32Bit, - MaybeSerialize, - Member, - }, - Perbill, +use sp_runtime::traits::{ + AtLeast32Bit, + MaybeSerialize, + Member, }; + use std::{ fmt::Debug, marker::PhantomData, }; pub use pallet_staking::{ + ActiveEraInfo, EraIndex, + EraRewardPoints, + Nominations, + RewardDestination, + RewardPoint, StakingLedger, + ValidatorPrefs, }; -/// A record of the nominations made by a specific account. -#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Ord, PartialOrd, Hash)] -pub struct Nominations { - /// The targets of nomination. - pub targets: Vec, - /// The era the nominations were submitted. - /// - /// Except for initial nominations which are considered submitted at era 0. - pub submitted_in: T::EraIndex, - /// Whether the nominations have been suppressed. - pub suppressed: bool, -} - /// Similar to `ErasStakers`, this holds the preferences of validators. /// /// This is keyed first by the era index to allow bulk deletion and then the stash account. @@ -70,31 +61,17 @@ pub struct ErasValidatorPrefsStore { account_id: T::AccountId, } -/// Information regarding the active era (era in used in session). -#[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct ActiveEraInfo { - /// Index of era. - pub index: T::EraIndex, - /// Moment of start expresed as millisecond from `$UNIX_EPOCH`. - /// - /// Start can be none if start hasn't been set for the era yet, - /// Start is set on the first on_finalize of the era to guarantee usage of `Time`. - pub start: Option, -} - -/// A destination account for payment. -#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Debug)] -pub enum RewardDestination { - /// Pay into the stash account, increasing the amount at stake accordingly. - Staked, - /// Pay into the stash account, not increasing the amount at stake. - Stash, - /// Pay into the controller account. - Controller, +/// Rewards for the last `HISTORY_DEPTH` eras. +/// If reward hasn't been set or has been removed then 0 reward is returned. +#[derive(Clone, Encode, Decode, Debug, Store)] +pub struct ErasRewardPoints { + #[store(returns = EraRewardPoints)] + index: EraIndex, + _phantom: PhantomData, } /// Preference of what happens regarding validation. -#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Call)] +#[derive(Clone, Encode, Decode, Debug, Call)] pub struct SetPayeeCall { /// The payee pub payee: RewardDestination, @@ -102,23 +79,6 @@ pub struct SetPayeeCall { pub _runtime: PhantomData, } -/// Preference of what happens regarding validation. -#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug)] -pub struct ValidatorPrefs { - /// Reward that validator takes up-front; only the rest is split between themselves and - /// nominators. - #[codec(compact)] - pub commission: Perbill, -} - -impl Default for ValidatorPrefs { - fn default() -> Self { - ValidatorPrefs { - commission: Default::default(), - } - } -} - /// The subset of the `frame::Trait` that a client must implement. #[module] pub trait Staking: Balances { @@ -170,7 +130,7 @@ pub trait Staking: Balances { } /// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. -#[derive(PartialEq, Eq, Clone, Encode, Decode, Ord, PartialOrd, Hash, Debug)] +#[derive(Clone, Encode, Decode, Debug)] pub struct UnlockChunk { /// Amount of funds to be unlocked. #[codec(compact)] @@ -187,9 +147,7 @@ pub struct UnlockChunk { /// Must be more than the number of eras delayed by session otherwise. /// I.e. active era must always be in history. /// I.e. `active_era > current_era - history_depth` must be guaranteed. -#[derive( - Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store, -)] +#[derive(Encode, Decode, Copy, Clone, Debug, Default, Store)] pub struct HistoryDepthStore { #[store(returns = u32)] /// Marker for the runtime @@ -197,9 +155,7 @@ pub struct HistoryDepthStore { } /// The ideal number of staking participants. -#[derive( - Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store, -)] +#[derive(Encode, Decode, Copy, Clone, Debug, Store)] pub struct ValidatorCountStore { #[store(returns = u32)] /// Marker for the runtime @@ -259,9 +215,9 @@ pub struct ValidatorsStore { } /// The map from nominator stash key to the set of stash keys of all validators to nominate. -#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] +#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Store)] pub struct NominatorsStore { - #[store(returns = Option>)] + #[store(returns = Option>)] /// TŮ—he stash account pub stash: T::AccountId, } @@ -283,7 +239,7 @@ pub struct CurrentEraStore { /// Validator set of this era must be equal to `SessionInterface::validators`. #[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] pub struct ActiveEraStore { - #[store(returns = Option>)] + #[store(returns = Option)] /// Marker for the runtime pub _runtime: PhantomData, }