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 (rebased) #13497

Closed
wants to merge 131 commits into from

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Feb 28, 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

@Ank4n Ank4n force-pushed the ankan/paged-rewards-rebased branch from 14510a0 to b4abd8a Compare February 28, 2023 22:59
@Ank4n Ank4n added A0-please_review Pull request needs code review. C3-medium PR touches the given topic and has a medium impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade. labels Feb 28, 2023
@Ank4n
Copy link
Contributor Author

Ank4n commented Feb 28, 2023

bot rebase

@paritytech-processbot
Copy link

Branch is already up-to-date

@Ank4n
Copy link
Contributor Author

Ank4n commented Mar 1, 2023

Seems something weird happened while rebasing and the bot thinks the history of master and this branch is different. Squashing my commits and adding these changes on top of fresh master in a new PR #13498.

@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. E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade. 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
2 participants