From 28533f68d41cf6d8aae8dc71496d9d8c5d72f382 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Wed, 12 Aug 2020 17:39:45 -0400 Subject: [PATCH] Expose clipped exposure --- src/frame/staking.rs | 48 +++++++++++++++++++++----------------------- src/runtimes.rs | 4 ---- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/frame/staking.rs b/src/frame/staking.rs index ea9ee1a241..d0ec9398af 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -26,7 +26,6 @@ use codec::{ }; use frame_support::Parameter; use sp_runtime::traits::{ - AtLeast32Bit, MaybeSerialize, Member, }; @@ -40,6 +39,7 @@ pub use pallet_staking::{ ActiveEraInfo, EraIndex, EraRewardPoints, + Exposure, Nominations, RewardDestination, RewardPoint, @@ -107,26 +107,6 @@ pub trait Staking: Balances { /// Maximum number of nominators that can be stored in a snapshot. const MAX_NOMINATORS: usize; - - /// Counter for the number of eras that have passed. - type EraIndex: Parameter - + Member - + AtLeast32Bit - + codec::Codec - + Default - + Copy - + MaybeSerialize - + Debug; - - /// Counter for the number of "reward" points earned by a given validator. - type RewardPoint: Parameter - + Member - + AtLeast32Bit - + codec::Codec - + Default - + Copy - + MaybeSerialize - + Debug; } /// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. @@ -137,7 +117,7 @@ pub struct UnlockChunk { pub value: T::Balance, /// Era number at which point it'll be unlocked. #[codec(compact)] - pub era: T::EraIndex, + pub era: EraIndex, } /// Number of eras to keep in history. @@ -226,13 +206,31 @@ pub struct NominatorsStore { /// /// This is the latest planned era, depending on how the Session pallet queues the validator /// set, it might be active or not. -#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] +#[derive(Encode, Copy, Clone, Debug, Store)] pub struct CurrentEraStore { - #[store(returns = Option)] + #[store(returns = Option)] /// Marker for the runtime pub _runtime: PhantomData, } +/// Clipped Exposure of validator at era. +/// +/// This is similar to [`ErasStakers`] but number of nominators exposed is reduced to the +/// `T::MaxNominatorRewardedPerValidator` biggest stakers. +/// (Note: the field `total` and `own` of the exposure remains unchanged). +/// This is used to limit the i/o cost for the nominator payout. +/// +/// This is keyed fist by the era index to allow bulk deletion and then the stash account. +/// +/// Is it removed after `HISTORY_DEPTH` eras. +/// If stakers hasn't been set or has been removed then empty exposure is returned. +#[derive(Encode, Copy, Clone, Debug, Store)] +pub struct ErasStakersClippedStore { + #[store(returns = Exposure)] + era: EraIndex, + validator_stash: T::AccountId, +} + /// The active era information, it holds index and start. /// /// The active era is the era currently rewarded. @@ -298,5 +296,5 @@ pub struct NominateCall { #[derive(PartialEq, Eq, Clone, Call, Encode, Decode, Debug)] struct PayoutStakersCall<'a, T: Staking> { pub validator_stash: &'a T::AccountId, - pub era: T::EraIndex, + pub era: EraIndex, } diff --git a/src/runtimes.rs b/src/runtimes.rs index f2064ac4e5..b38bee0dbe 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -151,8 +151,6 @@ impl Staking for DefaultNodeRuntime { type ValidatorIndex = u16; const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; - type EraIndex = u32; - type RewardPoint = u32; } impl Runtime for DefaultNodeRuntime { @@ -261,8 +259,6 @@ impl Staking for KusamaRuntime { type ValidatorIndex = u16; const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; - type EraIndex = u32; - type RewardPoint = u32; } impl Balances for KusamaRuntime {