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

Unlimited number of nominators eligible for Rewards payout #13059

Closed
wants to merge 177 commits into from

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Jan 4, 2023

closes paritytech/polkadot-sdk#439 and paritytech/polkadot-sdk#473.
polkadot companion: paritytech/polkadot#6765

Context

Rewards payout is processed today in a single block and limited to MaxNominatorRewardedPerValidator. This number is currently 512 on both Kusama and Polkadot.

This PR tries to scale the nominators payout to an unlimited count in a multi-block fashion. Exposures are stored in pages, with each page capped to a certain number. Practically, this number would be the same as MaxNominatorRewardedPerValidator or lower.

The PR also intends to be mostly backward compatible.

Note about the release

This PR introduces a new storage item MaxExposurePageCount which defaults to minimum value of 1 when not set. This means functionally, the pallet will continue to work exactly as before after this release. To enable paged rewards payout, MaxExposurePageCount can be increased to a bigger number by OpenGov for each runtime separately.

How payouts would look like after this change

Staking exposes two calls, 1) the existing payout_stakers and 2) payout_stakers_by_page.

payout_stakers

This remains backward compatible with no signature change. If for a given era a validator has multiple pages, they can call payout_stakers multiple times. The pages are executed in an ascending sequence and the runtime takes care of preventing double claims.

payout_stakers_by_page

Very similar to payout_stakers but also accepts an extra param page_index. An account can choose to payout rewards only for an explicitly passed page.

Lets look at an example scenario.
Given an active validator on Kusama had 1100 nominators, MaxExposurePageCount set to 10 and MaxExposurePageSize set to 512 for Era e. In order to pay out rewards to all nominators, the caller would need to call payout_stakers 3 times.

  • payout_stakers(origin, stash, e) => will pay the first 512 nominators.
  • payout_stakers(origin, stash, e) => will pay the second set of 512 nominators.
  • payout_stakers(origin, stash, e) => will pay the last set of 76 nominators.
    ...
  • payout_stakers(origin, stash, e) => calling it the 4th time would return an error InvalidPage.

The above calls can also be replaced by payout_stakers_by_page and passing a page explicitly.

Important to note

  • Validator commission is paid out in chunks across all the pages where each commission chunk is proportional to the total stake of the current page. This encourages the validator to payout all the exposure pages.

Storage Changes

Added

  • ErasStakersOverview
  • ClaimedRewards
  • ErasStakersPaged

Deprecated

The following can be cleaned up after 84 eras. Tracker issue for cleaning up.

  • ErasStakers.
  • ErasStakersClipped.
  • StakingLedger.claimed_rewards, renamed to StakingLedger.legacy_claimed_rewards.

Config Changes

  • Renamed MaxNominatorRewardedPerValidator to MaxExposurePageSize.
  • New item MaxExposurePageCount

TODO

  • Tracker ticket for cleaning up the old code after 84 eras.
  • Add companion.
  • Redo benchmarks in kusama and polkadot.
  • Add Changelog for pallet_staking.
  • Pallet should be configurable to enable/disable paged rewards.
  • Commission payouts are distributed across pages.
  • Review documentation thoroughly.
  • Rename MaxNominatorRewardedPerValidator -> MaxExposurePageSize.
  • NMap for ErasStakersPaged.
  • Deprecate ErasStakers.
  • Integrity tests

Follow up issues

@github-actions github-actions bot added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jan 4, 2023
frame/staking/src/pallet/mod.rs Outdated Show resolved Hide resolved
@Ank4n Ank4n changed the title paged exposure skeleton [WIP] Paged exposure skeleton Jan 4, 2023
@Ank4n Ank4n changed the title [WIP] Paged exposure skeleton [WIP] paged reward payouts Jan 4, 2023
frame/staking/src/pallet/mod.rs Outdated Show resolved Hide resolved
frame/staking/src/pallet/mod.rs Outdated Show resolved Hide resolved
frame/staking/src/pallet/mod.rs Outdated Show resolved Hide resolved
frame/staking/src/pallet/mod.rs Outdated Show resolved Hide resolved
@Ank4n
Copy link
Contributor Author

Ank4n commented Feb 22, 2023

bot bench $ pallet dev pallet_staking

@command-bot
Copy link

command-bot bot commented Feb 22, 2023

@Ank4n https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431168 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" pallet dev pallet_staking. Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 52-ff52a743-ddb4-4724-b638-d28192f1e805 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Feb 22, 2023

@Ank4n Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" pallet dev pallet_staking has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431168 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431168/artifacts/download.

@Ank4n
Copy link
Contributor Author

Ank4n commented Feb 22, 2023

bot bench $ runtime westend-dev pallet_staking

@command-bot
Copy link

command-bot bot commented Feb 22, 2023

@Ank4n "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" runtime westend-dev pallet_staking (https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431633) was cancelled in #13059 (comment)

@Ank4n
Copy link
Contributor Author

Ank4n commented Feb 22, 2023

bot cancel

@command-bot
Copy link

command-bot bot commented Feb 22, 2023

@Ank4n Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" runtime westend-dev pallet_staking has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431633 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2431633/artifacts/download.

@@ -596,7 +597,7 @@ impl pallet_fast_unstake::Config for Runtime {
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = MaxExposurePageSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can come from T::Staking, still feature gated ofc.

@@ -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::MaxExposurePageSize::get())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let others = (0..T::MaxExposurePageSize::get())
let others = (0..T::Staking::MaxExposurePageSize::get())


## [14]

### Added
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, much better.

@Ank4n
Copy link
Contributor Author

Ank4n commented Mar 1, 2023

I got couple of feedbacks about lot of noise in this PR caused by upstream merges. Created a new PR with rebased changes here.

@Ank4n Ank4n closed this Mar 1, 2023
@louismerlin louismerlin removed the D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited label May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C3-medium PR touches the given topic and has a medium impact on builders. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

New staking reward system