This repository was archived by the owner on Nov 15, 2023. It is now read-only.
[NPoS] Implements dynamic number of nominators#12970
Merged
paritytech-processbot[bot] merged 96 commits intomasterfrom Aug 10, 2023
Merged
[NPoS] Implements dynamic number of nominators#12970paritytech-processbot[bot] merged 96 commits intomasterfrom
paritytech-processbot[bot] merged 96 commits intomasterfrom
Conversation
kianenigma
reviewed
Dec 21, 2022
kianenigma
reviewed
Dec 21, 2022
kianenigma
reviewed
Dec 21, 2022
kianenigma
reviewed
Dec 21, 2022
kianenigma
reviewed
Dec 21, 2022
Contributor
kianenigma
left a comment
There was a problem hiding this comment.
Looks in the right direction so far.
…s; Adds more tests
Contributor
Author
|
bot fmt |
Contributor
Author
|
bot rebase |
1 similar comment
Contributor
Author
|
bot rebase |
Contributor
Author
|
bot fmt |
Contributor
Author
|
bot clean |
Contributor
Author
|
bot rebase |
|
Rebased |
Contributor
Author
|
bot merge |
arkpar
reviewed
Aug 12, 2023
|
|
||
| #[test] | ||
| fn change_of_max_nominations() { | ||
| #[should_panic] |
Member
There was a problem hiding this comment.
Is this intended? If so, Is this test supposed to panic at the last assertion?
Member
|
|
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR refactors the implementation of the
ElectionDataProviderbounds and implements a dynamic nomination quota per voter, based on the account's balance and an arbitrary curve.Instead of a fixed
MAX_NOMINATIONSper nominator, theElectionDataProvideruses an implementor oftrait NominationsQuota<Balance>to calculate the max votes per nominator. Since the number of votes per nominator is dynamic, the election data provider (pallet staking) keeps track of the size of the snapshot to ensure that the final snapshot size is bounded, even when the number of votes per voter is calculated on the fly. This PR implements anElectionSizeTrackerto achieve this goal.The
FixedNominationsQuota<const MAX: u32>struct implements the nomination quota trait and can be used to set the maximum number of nominations per nominator to 16, which is the current behaviour.Lazy nomination quota checks: Note that if a nominator's quota decreases after the nomination has been done, all the nominations will be used. The nominations quota limits is only enacted when an account performs a new nomination, in which case, if the number of nomination exceeds the current nominator quota, the
fn nominateextrinsic fails withTooManyTargets.Notable changes:
Trait
NominationsQuotaAn implementor of
NominationsQuotareturns the maximum number of votes per nominator.FixedNominationsQuotaimplements an instance of a fixed number of nominations, similar to the current implementation when set to 16.ElectionsBoundsandDataProviderBoundsThe
MaxElectableTargetsandTargetsBoundare replaced byElectionBounds.ElectionsBoundsdefines the count and size limits of both voters and targets for an election.The
struct ElectionBoundssets the upper bounds in size (MB) and number of voters/targets to request from the election data provider. The bounds are defined over two axis: number of elements and size (in MB) of the snapshot that is built from the election result.Struct
ElectionSizeTrackerKeeps track of the amount of data (in size and number of elements) that an election data provider prepares in
get_npos_votersandget_npos_targets. The election data provider uses an instance ofElectionSizeTrackerto know when the number of voters exceeded the bounds in terms of size and return the election data to EPM.Changes to the
ElectionDataProviderinterfaceBoth
fn ElectionDataProvider::election_votersandfn ElectionDataProvider::electable_targetstake as an input an instance ofDataProviderBounds, instead of an optional max in the of number of returned elements.New events
SnapshotVotersSizeExceeded: emitted when the election snapshot was exhausted due to the voters size limit.SnapshotTargetsSizeExceeded: emitted when the election snapshot was exhausted due to the targets size limit.Runtime API
This PR also adds a new runtime API to allow clients to query the nominations quota for a given balance.
polkadot companion: paritytech/polkadot#6807
Related to and reviving this PR and discussion #10340
Helps #13069
Closes #12968