Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[NPoS] Unlimited number of nominators eligible for Rewards payout #13498

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
15805ce
rewards payout in multi block fashion
Ank4n Mar 1, 2023
bb6a79b
use MaxExposurePageSize from staking
Ank4n Mar 1, 2023
1e40f4d
add max exposure page count to staking interface
Ank4n Mar 1, 2023
ac43c26
fmt
Ank4n Mar 1, 2023
09e9147
fix unimplemented function
Ank4n Mar 1, 2023
1eab166
feature gate
Ank4n Mar 1, 2023
bb60f7b
rewards payout in multi block fashion
Ank4n Mar 1, 2023
1c88aa2
use MaxExposurePageSize from staking
Ank4n Mar 1, 2023
98550eb
add max exposure page count to staking interface
Ank4n Mar 1, 2023
fb80ae2
fmt
Ank4n Mar 1, 2023
494bbde
fix unimplemented function
Ank4n Mar 1, 2023
f2d06ea
feature gate
Ank4n Mar 1, 2023
5141b67
add staking api
Ank4n Mar 2, 2023
f1b90a8
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Mar 13, 2023
7d0c66b
Merge branch 'ankan/paged-rewards-staking-api' into ankan/paged-rewar…
Ank4n Mar 13, 2023
6308d43
fmt
Ank4n Mar 13, 2023
69737f0
update weights
Ank4n Mar 13, 2023
26a2e5b
fix imports
Ank4n Mar 13, 2023
cd01ee0
fix docs
Ank4n Mar 13, 2023
4e30f22
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Mar 18, 2023
3e2fed1
fix merge
Ank4n Mar 18, 2023
06d6bfe
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Mar 20, 2023
10b8b34
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Mar 26, 2023
6ea4f57
resolve pr comments
Ank4n Mar 26, 2023
d824e92
keep the order of staking interface impl
Ank4n Mar 26, 2023
6b6a319
move Exposure, ExposurePage, ExposureOverview and IndividualExposure …
Ank4n Mar 26, 2023
910dfe3
remove dependency to stakign for staking runtime api
Ank4n Mar 26, 2023
b0c7c36
initialise size of others while prepping pages
Ank4n Mar 26, 2023
832353f
imrpovements
Ank4n Mar 26, 2023
7dfadbc
fix code
Ank4n Mar 26, 2023
2ba18e5
link migration changelog
Ank4n Mar 26, 2023
9c5d405
remove unused import
Ank4n Mar 26, 2023
8abc250
fix staking tests
Ank4n Mar 26, 2023
f497d19
fmt
Ank4n Mar 26, 2023
70425f8
Apply suggestions from code review
Ank4n Mar 30, 2023
a0f64c4
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Mar 30, 2023
c9b5c4c
move EraInfo to lib
Ank4n Mar 30, 2023
2354bd7
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Apr 10, 2023
f12a75a
fix docs
Ank4n Apr 10, 2023
ae28d84
expect instead of unwrap
Ank4n Apr 10, 2023
f76dbcf
remove useless code
Ank4n Apr 10, 2023
f4dd55d
remove deprecated weight doc
Ank4n Apr 10, 2023
d99769d
clip required page count
Ank4n Apr 10, 2023
d939789
defensively assert
Ank4n Apr 10, 2023
b2eed7b
doc wrapping fix
Ank4n Apr 10, 2023
b776386
explain why we return one page when no nominator pages exist
Ank4n Apr 10, 2023
5f82274
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Apr 16, 2023
3ccb0af
eras stakers might be an unsafe runtime api, should evaluate separate…
Ank4n Apr 16, 2023
2865046
remove eras stakers runtime api from node runtime
Ank4n Apr 16, 2023
8c013e7
rename Era info functions
Ank4n Apr 16, 2023
809b47e
fmt
Ank4n Apr 16, 2023
2a14298
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n May 18, 2023
fe09ecd
fix tests
Ank4n May 18, 2023
2023135
fixes
Ank4n May 18, 2023
32a507e
".git/.scripts/commands/fmt/fmt.sh"
May 18, 2023
6b5fca1
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
May 20, 2023
945f64d
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n May 31, 2023
fa02b72
add back missed config while resolving conflict
Ank4n May 31, 2023
a4884b2
not needed anymore
Ank4n May 31, 2023
84368c5
fix migration
Ank4n May 31, 2023
77fece6
Merge remote-tracking branch 'origin/master' into ankan/paged-rewards…
Jun 19, 2023
2fa9227
Update frame/staking/runtime-api/src/lib.rs
Ank4n Jun 20, 2023
98ffc9f
Update frame/staking/src/pallet/mod.rs
Ank4n Jun 20, 2023
9275f3e
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Jun 22, 2023
559e1e2
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Jul 9, 2023
d73c7a1
cargo fmt
Ank4n Jul 9, 2023
dd70800
rename page count api
Ank4n Jul 9, 2023
746049e
make exposure page count and page size u16
Ank4n Jul 9, 2023
1a4963b
Apply suggestions from code review
Ank4n Jul 9, 2023
916dde2
wrap to 100 letters
Ank4n Jul 9, 2023
53ef105
Update frame/staking/src/lib.rs
Ank4n Jul 9, 2023
62835ef
rustdoc for Individual exposure
Ank4n Jul 9, 2023
0d7b4a8
rename ExposureOverview to more explicit PagedExposureMetadata
Ank4n Jul 9, 2023
1efa770
don't repeat docs
Ank4n Jul 9, 2023
ef07f43
rename the exposure_overfiew field
Ank4n Jul 9, 2023
60785b7
rename ExposureExt
Ank4n Jul 9, 2023
99d595f
fix benchmark
Ank4n Jul 9, 2023
3bd8768
".git/.scripts/commands/fmt/fmt.sh"
Jul 9, 2023
12a7566
Trigger Build
Ank4n Jul 9, 2023
fcd336f
rename test fn to set max page count
Ank4n Jul 9, 2023
12af748
revert changing types of exposure page size and count back to u32
Ank4n Jul 9, 2023
338f69a
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Aug 10, 2023
ac63a5f
unused import
Ank4n Aug 11, 2023
954a3a6
".git/.scripts/commands/fmt/fmt.sh"
Aug 11, 2023
38827d0
Pallets: Treasury deprecate `propose_spend` dispatchable (#14538)
muharem Aug 10, 2023
a1a06b5
Sync NFT metadata limits with AssetHub values (#14748)
jsidorenko Aug 11, 2023
307cec8
sc-cli: add no-beefy flag to cli config (#14754)
acatangiu Aug 11, 2023
0875d0b
sc-consensus-beefy: fix initialization when BEEFY genesis state unava…
acatangiu Aug 11, 2023
776adab
make `BagsList::put_in_front_of` be permissionless (#14714)
kianenigma Aug 12, 2023
ef8962a
[contracts] Derive useful traits for public types (#14723)
pmikolajczyk41 Aug 14, 2023
8b6ae95
add `frame_system::DefaultConfig` to individual pallet `DefaultConfig…
kianenigma Aug 14, 2023
3451985
Fixes CI (#14763)
gupnik Aug 14, 2023
e47ecde
fix: node cli docs (#14718)
muse254 Aug 14, 2023
df1f1ae
[fix lint warnings: Uniques pallet] fix clippy::missing_errors_doc li…
Aug 14, 2023
829f0d7
Add `try_state` check to Pallet `MessageQueue` (#13502)
gitofdeepanshu Aug 14, 2023
02c8757
Remove missing sentence (#14769)
naterarmstrong Aug 15, 2023
bd55f14
[fix lint warnings: NFTs pallet] fix clippy::missing_errors_doc lint …
Aug 15, 2023
981de06
chainHead: Limit ongoing operations (#14699)
lexnv Aug 15, 2023
de0528b
Update Scheduler Pallet Documentation (#14740)
snowmead Aug 15, 2023
28afcb8
Revert "sc-cli: add no-beefy flag to cli config (#14754)" (#14766)
acatangiu Aug 15, 2023
f6b8cbd
Add `--workspace` to clippy (#14772)
alvicsam Aug 15, 2023
4051fde
Make peer evictions less aggressive (#14619)
altonen Aug 15, 2023
cbf6e1c
`cargo clippy +nightly --fix` run on downstream node template (#14693)
nuke-web3 Aug 16, 2023
c40cf54
Improve `storage_alias` and make `UnlockAndUnreserveAllFunds` indepen…
bkchr Aug 16, 2023
d6f9693
[fix lint warnings: NFTs pallet] fix clippy::missing_docs_in_private_…
Aug 16, 2023
7674d26
Update wasm-opt to 0.114 (#14695)
brson Aug 16, 2023
7071c60
Revert "chore: update libp2p to 0.52.1 (#14429)" (#14722)
altonen Aug 16, 2023
3ddf325
Free standing `elections-phragmen` and `tips` Gov V1 unlock/unreserve…
liamaharon Aug 16, 2023
81c7234
Disarm `OnRuntimeUpgrade::pre/post_upgrade` `Tuple` footgun (#14759)
liamaharon Aug 16, 2023
5f07634
deprecate `try-runtime` subcommand and direct users to standalone cli…
liamaharon Aug 17, 2023
858140e
Runtime: avoid duplication and test all signature (#14663)
ashWhiteHat Aug 17, 2023
29f800b
Set `StateBackend::Transaction` to `PrefixedMemoryDB` (#14612)
bkchr Aug 17, 2023
e1bbd95
remove page count requirement
Ank4n Aug 20, 2023
4e0c8b6
Merge branch 'master' into ankan/paged-rewards-rebased2
Ank4n Aug 20, 2023
79e3fb0
paging is always enabled
Ank4n Aug 20, 2023
4d51ae0
".git/.scripts/commands/fmt/fmt.sh"
Aug 20, 2023
989b391
no clipping or sorting of nominators
Ank4n Aug 20, 2023
ec0694b
small edits to the changelog
Ank4n Aug 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ parameter_types! {
pub const BondingDuration: sp_staking::EraIndex = 24 * 28;
pub const SlashDeferDuration: sp_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub OffchainRepeat: BlockNumber = 5;
pub HistoryDepth: u32 = 84;
Expand Down Expand Up @@ -582,7 +581,8 @@ impl pallet_staking::Config for Runtime {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = ConstU32<256>;
type MaxExposurePageCount = ConstU32<1>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand All @@ -604,8 +604,6 @@ impl pallet_fast_unstake::Config for Runtime {
type Currency = Balances;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = ();
}

Expand Down Expand Up @@ -2049,10 +2047,18 @@ impl_runtime_apis! {
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
fn nominations_quota(balance: Balance) -> u32 {
Staking::api_nominations_quota(balance)
}

fn eras_stakers(era: sp_staking::EraIndex, account: AccountId) -> pallet_staking::Exposure<AccountId, Balance> {
Staking::api_eras_stakers(era, account)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now's your last time to ask yourself: is the (legacy) name eras_stakers actually good? shoudl we not use the oppurtunity and rename it to something better? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here.

On one hand, since this is meant for backward compatibility and all similar storage items are named similarly (eras_stakers, eras_stakers_paged, eras_stakers_overview ...), it makes sense to keep a similar name.

We could call it eras_exposure as well but then we are exposing a new term (exposure) outside staking world which may be just an internal concept. Eras Stakers might not be such a bad public name (staker info for the era).

Do you have a name suggestion?


fn era_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_era_page_count(era, account)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API call is only for validator exposures so the naming could reflect this and be a bit more intuitive. era_page_count gives me the impression that this is returning the total pages for a whole era.

Suggested change
fn era_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_era_page_count(era, account)
}
fn validator_exposure_page_count(era: sp_staking::EraIndex, who: AccountId) -> sp_staking::PageIndex {
Staking::api_era_page_count(era, who)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage item that page corresponds to is called ErasStakersPaged (which derives its name from the existing non-paged ErasStakers). What do you think about renaming it as eras_stakers_page_count?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to eras_stakers_page_count to keep in line with how storage items are named.

}

impl sp_consensus_babe::BabeApi<Block> for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageSize = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be any issues making these ConstU16? 32 bits may be overkill for these numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An update, I want to bound EraStakersPaged and ClaimedRewards with these two values and boundedVec needs to be bounded by a u32 value. I will undo the changes to make it u16.

type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand Down
8 changes: 4 additions & 4 deletions frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(1, validator),
Staking::eras_stakers(1, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -478,7 +478,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Balances::total_balance(&offending_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&offending_validator_id), 0);
assert_eq!(
Staking::eras_stakers(2, offending_validator_id),
Staking::eras_stakers(2, &offending_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -491,7 +491,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Balances::total_balance(validator), 10_000_000);
assert_eq!(Staking::slashable_balance_of(validator), 10_000);
assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -550,7 +550,7 @@ fn report_equivocation_old_session_works() {
assert_eq!(Balances::total_balance(&offending_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&offending_validator_id), 0);
assert_eq!(
Staking::eras_stakers(3, offending_validator_id),
Staking::eras_stakers(3, &offending_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);
})
Expand Down
3 changes: 2 additions & 1 deletion frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageSize = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand Down
12 changes: 6 additions & 6 deletions frame/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(1, validator),
Staking::eras_stakers(1, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Balances::total_balance(&equivocation_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&equivocation_validator_id), 0);
assert_eq!(
Staking::eras_stakers(2, equivocation_validator_id),
Staking::eras_stakers(2, &equivocation_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -329,7 +329,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -365,7 +365,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -399,7 +399,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Balances::total_balance(&equivocation_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&equivocation_validator_id), 0);
assert_eq!(
Staking::eras_stakers(3, equivocation_validator_id),
Staking::eras_stakers(3, &equivocation_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -413,7 +413,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(3, validator),
Staking::eras_stakers(3, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down
2 changes: 1 addition & 1 deletion frame/fast-unstake/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn setup_staking<T: Config>(v: u32, until: EraIndex) {
.collect::<Vec<_>>();

for era in 0..=until {
let others = (0..T::MaxBackersPerValidator::get())
let others = (0..T::Staking::max_exposure_page_size())
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
.map(|s| {
let who = frame_benchmarking::account::<T::AccountId>("nominator", era, s);
let value = ed;
Expand Down
4 changes: 0 additions & 4 deletions frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ pub mod pallet {
/// Maximum value for `ErasToCheckPerBlock`. This should be as close as possible, but more
/// than the actual value, in order to have accurate benchmarks.
type MaxErasToCheckPerBlock: Get<u32>;

/// Use only for benchmarking.
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator: Get<u32>;
}

/// The current "head of the queue" being unstaked.
Expand Down
5 changes: 2 additions & 3 deletions frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = ();
type HistoryDepth = ConstU32<84>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageSize = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type OffendingValidatorsThreshold = ();
type ElectionProvider = MockElection;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down Expand Up @@ -190,8 +191,6 @@ impl fast_unstake::Config for Runtime {
type BatchSize = BatchSize;
type WeightInfo = ();
type MaxErasToCheckPerBlock = ConstU32<16>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = ConstU32<128>;
}

type Block = frame_system::mocking::MockBlock<Runtime>;
Expand Down
3 changes: 2 additions & 1 deletion frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageSize = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand Down
12 changes: 6 additions & 6 deletions frame/grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(1, validator),
Staking::eras_stakers(1, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -371,7 +371,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Balances::total_balance(&equivocation_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&equivocation_validator_id), 0);
assert_eq!(
Staking::eras_stakers(2, equivocation_validator_id),
Staking::eras_stakers(2, &equivocation_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -385,7 +385,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -417,7 +417,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -450,7 +450,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Staking::slashable_balance_of(&equivocation_validator_id), 0);

assert_eq!(
Staking::eras_stakers(3, equivocation_validator_id),
Staking::eras_stakers(3, &equivocation_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -464,7 +464,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(3, validator),
Staking::eras_stakers(3, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down
3 changes: 2 additions & 1 deletion frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ impl pallet_staking::Config for Runtime {
type SessionInterface = ();
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = ();
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = ();
type ElectionProvider =
frame_election_provider_support::NoElection<(AccountId, BlockNumber, Staking, ())>;
Expand Down
5 changes: 5 additions & 0 deletions frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ impl sp_staking::StakingInterface for StakingMock {
fn set_current_era(_era: EraIndex) {
unimplemented!("method currently not used in testing")
}

#[cfg(feature = "runtime-benchmarks")]
fn max_exposure_page_size() -> sp_staking::PageIndex {
unimplemented!("method currently not used in testing")
}
}

impl frame_system::Config for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion frame/nomination-pools/test-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ impl pallet_staking::Config for Runtime {
type SessionInterface = ();
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = ();
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = ();
type ElectionProvider =
frame_election_provider_support::NoElection<(AccountId, BlockNumber, Staking, ())>;
Expand Down
3 changes: 2 additions & 1 deletion frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = ();
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down
2 changes: 1 addition & 1 deletion frame/root-offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub mod pallet {
.clone()
.into_iter()
.map(|(o, _)| OffenceDetails::<T> {
offender: (o.clone(), Staking::<T>::eras_stakers(now, o)),
offender: (o.clone(), Staking::<T>::eras_stakers(now, &o)),
reporters: vec![],
})
.collect())
Expand Down
3 changes: 2 additions & 1 deletion frame/root-offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down
3 changes: 2 additions & 1 deletion frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageCount = ConstU32<1>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = ();
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand Down
27 changes: 27 additions & 0 deletions frame/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is loosely based
on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). We maintain a
single integer version number for staking pallet to keep track of all storage
migrations.

## [v14]

### Added

- New item `ErasStakersPaged` that keeps up to `MaxExposurePageSize`
individual nominator exposures by era, validator and page.
- New item `ErasStakersOverview` complementary to `ErasStakersPaged` which keeps
state of own and total stake of the validator across pages.
- New item `ClaimedRewards` to support paged rewards payout.

### Deprecated

- `ErasStakersClipped` is deprecated and may be removed after 84 eras.
- `ErasStakers` is deprecated and may be removed after 84 eras.
- Field `claimed_rewards` in item `Ledger` is renamed
to `legacy_claimed_rewards` and may be removed after 84 eras.

[v14]: https://github.com/paritytech/substrate/pull/13498
8 changes: 4 additions & 4 deletions frame/staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ An account can become a nominator via the [`nominate`](https://docs.rs/pallet-st
The **reward and slashing** procedure is the core of the Staking module, attempting to _embrace
valid behavior_ while _punishing any misbehavior or lack of availability_.

Rewards must be claimed for each era before it gets too old by `$HISTORY_DEPTH` using the
Rewards must be claimed for each era before it gets too old by [`HistoryDepth`] using the
`payout_stakers` call. Any account can call `payout_stakers`, which pays the reward to the
Ank4n marked this conversation as resolved.
Show resolved Hide resolved
validator as well as its nominators. Only the [`Config::MaxNominatorRewardedPerValidator`]
biggest stakers can claim their reward. This is to limit the i/o cost to mutate storage for each
nominator's account.
validator as well as its nominators. Rewards are paged to maximum of [`Config::MaxExposurePageSize`]
nominators per page. Each page of staker payout needs to be called separately to ensure all nominators are
paid. This is to limit the i/o cost to mutate storage for each nominator's account.

Slashing can occur at any point in time, once misbehavior is reported. Once slashing is
determined, a value is deducted from the balance of the validator and all the nominators who
Expand Down
2 changes: 2 additions & 0 deletions frame/staking/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/staking" }

[features]
default = ["std"]
std = [
"codec/std",
"sp-api/std",
"sp-staking/std",
]
Loading