This repository has been 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.6k
Unlimited number of nominators eligible for Rewards payout #13059
Closed
Closed
Changes from 15 commits
Commits
Show all changes
177 commits
Select commit
Hold shift + click to select a range
acab2d1
paged exposure skeleton
Ank4n 256ca4c
insignificant changes
Ank4n 8e6db42
Merge branch 'master' into ankan/paged-rewards
Ank4n 0cabf55
add note on usage of twox hash
Ank4n 00bc992
Merge branch 'master' into ankan/paged-rewards
Ank4n f65d7b6
impl paged exposure
Ank4n e7f299c
paged as exposure function
Ank4n b3f58d6
add test for paging exposure
Ank4n 661fab0
remove commented fn
Ank4n 06d83fb
cargo fmt
Ank4n 02e3ffc
more fmt
Ank4n c924bfc
remove unnecessary bound
Ank4n 108cd16
add wrapper struct and refactor
Ank4n e14eab3
create temp fn that checks both ledger and new claimed_rewards
Ank4n 70b8c7f
incomplete, paged extrinisic to pay stakers
Ank4n 484dad8
Merge branch 'master' into ankan/paged-rewards
Ank4n eac23e0
fix names
Ank4n 1cd79ff
add page as 0 for payout stakers, tests failing currently.
Ank4n 4fdc2df
fix double claim
Ank4n c339ca5
don't store claimed rewards for previous eras in the ledger
Ank4n 773d91c
mark claimed_rewards in Staking ledger as legacy
Ank4n f50ee11
test for not populating legacy claimed rewards anymore
Ank4n 309c737
test is not accurate since for prebonded era, there cannot be any rew…
Ank4n 4f4466c
fmt
Ank4n 7f4aa5b
assert claimed rewards is populated
Ank4n d64d28e
introduce struct ExposurePage
Ank4n da53a27
fmt
Ank4n dd60ba7
some docs
Ank4n b19193a
rename to into_pages
Ank4n e3569bf
verify claimed rewards and era stakers is cleared
Ank4n 99913b3
small comment
Ank4n cc6be46
reuse MaxNominatorRewardedPerValidator
Ank4n 6623056
get to the same stage as 1st attempt
Ank4n 90e7a9d
pay all pages
Ank4n cf6ee88
introduce invalid page error
Ank4n b86e3f8
docs
Ank4n 1072147
test all nominators are paid
Ank4n 9f4ea04
all test pass
Ank4n 42429e9
cargo fmt
Ank4n 4260bca
add more tests
Ank4n eb0709b
cargo fmt
Ank4n ec6ae58
fix benchmarks
Ank4n 03c53a0
fix clippy suggestion
Ank4n f87a862
Merge branch 'master' into ankan/paged-rewards
Ank4n c94ce9c
Merge branch 'master' of https://github.com/paritytech/substrate into…
554bb7c
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_staking
1aed1b5
doc for split into pages
Ank4n 18d2d1d
remove unused from
Ank4n b14319e
fix doc
Ank4n 0fa0195
rename MaxNominatorRewardedPerValidator
Ank4n 2d5082d
add weight for pages other than 0
Ank4n ce67004
fmt
Ank4n c330866
use n to make the compiler happy
Ank4n 99d19b7
fix minimum count
Ank4n fc2e091
correct number of nominators
Ank4n 2adf060
fix benchmark and commission payout
Ank4n 26efca4
refactor
Ank4n d7ab5b7
verify is paid only once per era for their own stake
Ank4n e77bd87
fmt
Ank4n 6bc015f
fix rustdoc
Ank4n 514a851
fmt
Ank4n 076a0c1
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_staking
cf0654b
fix rust doc
Ank4n 94a6dd5
handles errors
Ank4n e49d721
commission test
Ank4n 2f40eea
some things to discuss
Ank4n 455294b
try state checks
Ank4n 4e2b482
fmt
Ank4n 416ee7e
Merge branch 'master' into ankan/paged-rewards
Ank4n 478b473
Revert "try state checks"
Ank4n ddfcd18
cleanup era overview in history depth eras
Ank4n 75fb102
Merge branch 'master' into ankan/paged-rewards
Ank4n fed66ce
todos
Ank4n aeec825
remove store
Ank4n a85e451
[Revert] keep the same name of page size
Ank4n b832130
consume exposure
Ank4n 5d215c6
sc-finality-grandpa: Warp proof generation can not expect justificati…
bkchr d7e4a56
update criterion to v0.4.0 (#13142)
koushiro 3ec6576
fix up template (#13205)
shawntabrizi dca583b
Remove `uncles` related code (#13216)
bkchr b0e04e7
Implement RIType traits for u8 array with an arbitrary size (#13256)
conr2d 2d35736
grandpa: cleanup stale entries in set id session mapping (#13237)
andresilva 599cd6e
Benchmark's successful origin api update (#13146)
muharem 4ff092b
hooks default impl missing where clause (#13264)
kianenigma 0d47b62
implemented `contains_prefix` for StorageDoubleMap and StorageNMap (#…
muraca f88a55e
Calling proxy doesn't remove announcement (#13267)
Szegoo da40ff1
Fee and tip represented as asset ID inside `AssetTxFeePaid` (#13083)
Szegoo c9310e1
Move beefy-merkle-tree to utils/binary-merkle-tree and make it generi…
DaviRain-Su 4d02469
Metadata V15: Derive `TypeInfo` for describing runtime types (#13272)
lexnv 369365e
benchmarks: EnsureRankedMember must add ranked members (#13297)
ggwpez c6c490d
Minor: Update output validity tests (#13190)
mrcnski 6453a4a
BEEFY: define on-chain beefy-genesis and use it to coordinate voter i…
acatangiu ff8a71f
feat: add event SkepticsChosen event in society (#13291)
gitofdeepanshu ca58b7b
feat(client): significantly increase wasm instance limits (#13298)
hussein-aitlahcen 8866597
Remove in-tree bounded types and use bounded-collections crate (#13243)
KiChjang f28e182
some new definitions
Ank4n ab79cd3
new call to payout staekers by page
Ank4n 50690ff
fix benchmark
Ank4n 664c374
keep payout_stakers backward compatible
Ank4n bf41253
split exposure by ExposurePageSize
Ank4n caeb781
return both overview and page
Ank4n 3b9acbf
fmt
Ank4n 9ab601a
Update frame/staking/README.md
Ank4n 7f24aa1
introduce exposure extension
Ank4n 1bf6161
doc
Ank4n 21dff20
format
Ank4n 171d43b
pay commission in parts; failing tests
Ank4n 263894b
verify commission are paid across pages
Ank4n 78f94bc
fmt
Ank4n 806e656
docs
Ank4n e826056
fix test
Ank4n bd420b3
Merge branch 'master' into ankan/paged-rewards
Ank4n 5ae9ee8
only use one constant
Ank4n 641d112
payout_stakers still work nicely
Ank4n 0f76c59
remove todo
Ank4n 37d46b6
benchmark against implicit page payout stakers since thats worst case
Ank4n 406d3b8
add a working draft of changelog
Ank4n bfdd143
small doc update
Ank4n f2fd8d4
Fix block pruning (#13323)
arkpar 58eef2c
Referendum proposal's metadata (#12568)
muharem b107674
Improve test coverage of the `Notifications` protocol (#13033)
altonen 4123495
Configurable voting-degree in council elections pallet (#13305)
kianenigma 23fb86b
Rework generated API docs (#13178)
athei be6a11c
pallet-scheduler: Ensure we request a preimage (#13340)
bkchr 4b23fdb
[Fix] Try-state feature-gated for BagsList (#13296)
ruseinov 821ad7e
bump version of zombienet and update snaps links (#13359)
pepoviola 826cfb2
Fix longest chain finalization target lookup (#13289)
davxy 71432c2
SetMembers configurable origin (#13159)
girazoki bfe5a7d
have a way to disable pages
Ank4n 02703c7
fmt
Ank4n b79e231
simple rename
Ank4n 77ba7df
test for page size and count
Ank4n ff965e2
add the old test back
Ank4n 8a608f9
update changelog
Ank4n fef9db6
Merge branch 'master' of github.com:paritytech/substrate into ankan/p…
kianenigma a7bb9ed
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards
dd6989c
Merge branch 'ankan/paged-rewards' of github.com:paritytech/substrate…
kianenigma 64aa36b
Merge branch 'master' into ankan/paged-rewards
Ank4n 397e5d2
remove duplicate test
Ank4n 73630b4
todo tags
Ank4n cb59ca7
some renames and config vals
Ank4n a82b0bd
do not iterate twice
Ank4n e8ebbbc
rename
Ank4n 9a959e4
clean up
Ank4n f712e35
pr fixes
Ank4n dfe8a98
fmt
Ank4n e2bf7cf
make it compile
Ank4n d08ffd5
Merge branch 'master' into ankan/paged-rewards
Ank4n d79d897
keep only config item for MaxExposurePageSize
Ank4n 5a1f446
safe maths
Ank4n 08d60ff
pr comment
Ank4n b929439
simplify next claimable page
Ank4n 7df30f6
fix build
Ank4n 4a415e7
pr comments
Ank4n 8544412
clippy suggestion
Ank4n 04133ab
Merge branch 'ankan/paged-rewards' of github.com:paritytech/substrate…
kianenigma 0ce2bbd
write a new eras stakers
Ank4n ed8c993
clean up page_count
Ank4n 2634403
more readable validator exposure calculation
Ank4n 5f5abad
fmt
Ank4n 9ad77cb
do not use ErasStakers anymore
Ank4n 7dfb3e8
defensive unwrap for appending nominator pages to eras stakers
Ank4n fd2f6fb
better fn naming
Ank4n 45ad6e1
fmt
Ank4n d49de8b
move logic to combine all exposure into EraInfo
Ank4n c67e8bd
remove useless getters
Ank4n 06627f0
bounded ExposureOverview
Ank4n 89820f9
remove unused fn
Ank4n 66c8fe1
ErasStakers backward compatible test
Ank4n b5fa46e
fmt
Ank4n 12ed262
update changelog
Ank4n 14bc8b3
Use NMap for ErasStakersPaged
Ank4n 6ac7961
doc update
Ank4n af01a1f
Merge branch 'master' of https://github.com/paritytech/substrate into…
b5190b5
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_staking
21c20f2
rename to consistent names
Ank4n 2aa08d6
some docs
Ank4n 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
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -26,20 +26,18 @@ use frame_support::{ | |
pallet_prelude::*, | ||
traits::{ | ||
Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get, | ||
Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, | ||
Imbalance, Len, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, | ||
}, | ||
weights::Weight, | ||
}; | ||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; | ||
use pallet_session::historical; | ||
use sp_runtime::{ | ||
generic::Era, | ||
traits::{Bounded, Convert, One, SaturatedConversion, Saturating, StaticLookup, Zero}, | ||
Perbill, | ||
}; | ||
use sp_staking::{ | ||
offence::{DisableStrategy, OffenceDetails, OnOffenceHandler}, | ||
EraIndex, SessionIndex, Stake, StakingInterface, | ||
}; | ||
use sp_staking::{offence::{DisableStrategy, OffenceDetails, OnOffenceHandler}, EraIndex, SessionIndex, Stake, StakingInterface, PageIndex}; | ||
use sp_std::prelude::*; | ||
|
||
use crate::{ | ||
|
@@ -134,6 +132,7 @@ impl<T: Config> Pallet<T> { | |
pub(super) fn do_payout_stakers( | ||
validator_stash: T::AccountId, | ||
era: EraIndex, | ||
page: PageIndex, | ||
) -> DispatchResultWithPostInfo { | ||
// Validate input data | ||
let current_era = CurrentEra::<T>::get().ok_or_else(|| { | ||
|
@@ -159,36 +158,45 @@ impl<T: Config> Pallet<T> { | |
})?; | ||
let mut ledger = <Ledger<T>>::get(&controller).ok_or(Error::<T>::NotController)?; | ||
|
||
// clean up older claimed rewards | ||
ledger | ||
.claimed_rewards | ||
.retain(|&x| x >= current_era.saturating_sub(history_depth)); | ||
<Ledger<T>>::insert(&controller, &ledger); | ||
|
||
match ledger.claimed_rewards.binary_search(&era) { | ||
Ok(_) => | ||
return Err(Error::<T>::AlreadyClaimed | ||
.with_weight(T::WeightInfo::payout_stakers_alive_staked(0))), | ||
Err(pos) => ledger | ||
.claimed_rewards | ||
.try_insert(pos, era) | ||
// Since we retain era entries in `claimed_rewards` only upto | ||
// `HistoryDepth`, following bound is always expected to be | ||
// satisfied. | ||
.defensive_map_err(|_| Error::<T>::BoundNotMet)?, | ||
// todo(ank4n): remove | ||
// match ledger.claimed_rewards.binary_search(&era) { | ||
// Ok(_) => | ||
// return Err(Error::<T>::AlreadyClaimed | ||
// .with_weight(T::WeightInfo::payout_stakers_alive_staked(0))), | ||
// Err(pos) => ledger | ||
// .claimed_rewards | ||
// .try_insert(pos, era) | ||
// // Since we retain era entries in `claimed_rewards` only upto | ||
// // `HistoryDepth`, following bound is always expected to be | ||
// // satisfied. | ||
// .defensive_map_err(|_| Error::<T>::BoundNotMet)?, | ||
// } | ||
|
||
if EraInfo::<T>::temp_is_rewards_claimed(era, &ledger, &ledger.stash, page) { | ||
return Err(Error::<T>::AlreadyClaimed | ||
.with_weight(T::WeightInfo::payout_stakers_alive_staked(0))) | ||
} else { | ||
EraInfo::<T>::set_rewards_as_claimed(era, &ledger.stash, page); | ||
} | ||
|
||
let exposure = <ErasStakersClipped<T>>::get(&era, &ledger.stash); | ||
|
||
// Input data seems good, no errors allowed after this point | ||
|
||
<Ledger<T>>::insert(&controller, &ledger); | ||
|
||
// Get Era reward points. It has TOTAL and INDIVIDUAL | ||
// Find the fraction of the era reward that belongs to the validator | ||
// Take that fraction of the eras rewards to split to nominator and validator | ||
// | ||
// Then look at the validator, figure out the proportion of their reward | ||
// which goes to them and each of their nominators. | ||
|
||
let exposure = EraInfo::<T>::get_validator_exposure(era, &ledger.stash, page); | ||
// let exposure = EraInfo::<T>::get_validator_exposure(&era, &ledger.stash, page); | ||
|
||
let era_reward_points = <ErasRewardPoints<T>>::get(&era); | ||
let total_reward_points = era_reward_points.total; | ||
let validator_reward_points = era_reward_points | ||
|
@@ -561,31 +569,24 @@ impl<T: Config> Pallet<T> { | |
>, | ||
new_planned_era: EraIndex, | ||
) -> BoundedVec<T::AccountId, MaxWinnersOf<T>> { | ||
let elected_stashes: BoundedVec<_, MaxWinnersOf<T>> = exposures | ||
Ank4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.iter() | ||
.cloned() | ||
.map(|(x, _)| x) | ||
.collect::<Vec<_>>() | ||
.try_into() | ||
.expect("since we only map through exposures, size of elected_stashes is always same as exposures; qed"); | ||
|
||
// Populate stakers, exposures, and the snapshot of validator prefs. | ||
// Populate elected stash, stakers, exposures, and the snapshot of validator prefs. | ||
let mut total_stake: BalanceOf<T> = Zero::zero(); | ||
let mut elected_stashes = Vec::with_capacity(exposures.len()); | ||
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. Would be curious to see in which benchmark we realize that the weight of the exposure collection (election finalization) is now less. |
||
|
||
exposures.into_iter().for_each(|(stash, exposure)| { | ||
// build elected stash | ||
elected_stashes.push(stash.clone()); | ||
// accumulate total stake | ||
total_stake = total_stake.saturating_add(exposure.total); | ||
<ErasStakers<T>>::insert(new_planned_era, &stash, &exposure); | ||
|
||
let mut exposure_clipped = exposure; | ||
let clipped_max_len = T::MaxNominatorRewardedPerValidator::get() as usize; | ||
if exposure_clipped.others.len() > clipped_max_len { | ||
exposure_clipped.others.sort_by(|a, b| a.value.cmp(&b.value).reverse()); | ||
exposure_clipped.others.truncate(clipped_max_len); | ||
} | ||
<ErasStakersClipped<T>>::insert(&new_planned_era, &stash, exposure_clipped); | ||
// store staker exposure for this era | ||
EraInfo::<T>::set_validator_exposure(new_planned_era, &stash, exposure); | ||
}); | ||
|
||
// Insert current era staking information | ||
<ErasTotalStake<T>>::insert(&new_planned_era, total_stake); | ||
let elected_stashes: BoundedVec<_, MaxWinnersOf<T>> = elected_stashes | ||
.try_into() | ||
.expect("elected_stashes.len() always equal to exposures.len(); qed"); | ||
|
||
EraInfo::<T>::set_total_stake(new_planned_era, total_stake); | ||
|
||
// Collect the pref of all winners. | ||
for stash in &elected_stashes { | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use
into_iter()
here, you will be owning each chunk and therefore able to assign it toExposurePage.others
without needing to copy anything (I hope).