From 1b4dcd1f23f4bc4d57de3890669d0bd81314b54c Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 10 Mar 2020 20:54:29 +0100 Subject: [PATCH] Staking improve payout_validator (#5208) * add documentation and optimise payout_validator a bit * bump spec version to be safe this is just in case clipped exposure and exposure have different fields own and total. This shouldn't be the case but better be safe in case storage is wrong. * Update frame/staking/src/lib.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/staking/src/lib.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 34cb8eb749..44d23cf772 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -82,7 +82,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 234, + spec_version: 235, impl_version: 0, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 5226f5a3b3..5084c6c4a8 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -767,6 +767,7 @@ decl_storage! { /// /// This is similar to [`ErasStakers`] but number of nominators exposed is reduce 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. @@ -1349,7 +1350,10 @@ decl_module! { /// - `who` is the controller account of the nominator to pay out. /// - `era` may not be lower than one following the most recently paid era. If it is higher, /// then it indicates an instruction to skip the payout of all previous eras. - /// - `validators` is the list of all validators that `who` had exposure to during `era`. + /// - `validators` is the list of all validators that `who` had exposure to during `era`, + /// alongside the index of `who` in the clipped exposure of the validator. + /// I.e. each element is a tuple of + /// `(validator, index of `who` in clipped exposure of validator)`. /// If it is incomplete, then less than the full reward will be paid out. /// It must not exceed `MAX_NOMINATIONS`. /// @@ -1542,7 +1546,7 @@ impl Module { let era_reward_points = >::get(&era); let commission = Self::eras_validator_prefs(&era, &ledger.stash).commission; - let exposure = >::get(&era, &ledger.stash); + let exposure = >::get(&era, &ledger.stash); let exposure_part = Perbill::from_rational_approximation( exposure.own,