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
[NPoS] Implements dynamic number of nominators #12970
Merged
paritytech-processbot
merged 96 commits into
master
from
gpestana/staking-dynamic-nominators
Aug 10, 2023
Merged
[NPoS] Implements dynamic number of nominators #12970
paritytech-processbot
merged 96 commits into
master
from
gpestana/staking-dynamic-nominators
Aug 10, 2023
Conversation
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
gpestana
added
A3-in_progress
Pull request is in progress. No review needed at this stage.
B3-apinoteworthy
C1-low
PR touches the given topic and has a low impact on builders.
D9-needsaudit 👮
PR contains changes to fund-managing logic that should be properly reviewed and externally audited
labels
Dec 19, 2022
github-actions
bot
added
A0-please_review
Pull request needs code review.
and removed
A3-in_progress
Pull request is in progress. No review needed at this stage.
labels
Dec 19, 2022
gpestana
changed the title
Allow for a dynamic number of nominators
Allow for a dynamic number of nominators (v2)
Dec 19, 2022
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
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.
Looks in the right direction so far.
…s; Adds more tests
bot fmt |
bot rebase |
1 similar comment
bot rebase |
bot fmt |
bot clean |
bot rebase |
Rebased |
bot merge |
paritytech-processbot
bot
deleted the
gpestana/staking-dynamic-nominators
branch
August 10, 2023 07:45
arkpar
reviewed
Aug 12, 2023
@@ -5120,50 +5297,55 @@ fn min_commission_works() { | |||
} | |||
|
|||
#[test] | |||
fn change_of_max_nominations() { | |||
#[should_panic] |
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.
Is this intended? If so, Is this test supposed to panic at the last assertion?
|
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
C1-low
PR touches the given topic and has a low impact on builders.
D1-audited 👍
PR contains changes to fund-managing logic that has been properly reviewed and externally audited
T1-runtime
This PR/Issue is related to the topic “runtime”.
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
ElectionDataProvider
bounds and implements a dynamic nomination quota per voter, based on the account's balance and an arbitrary curve.Instead of a fixed
MAX_NOMINATIONS
per nominator, theElectionDataProvider
uses 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 anElectionSizeTracker
to 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 nominate
extrinsic fails withTooManyTargets
.Notable changes:
Trait
NominationsQuota
An implementor of
NominationsQuota
returns the maximum number of votes per nominator.FixedNominationsQuota
implements an instance of a fixed number of nominations, similar to the current implementation when set to 16.ElectionsBounds
andDataProviderBounds
The
MaxElectableTargets
andTargetsBound
are replaced byElectionBounds
.ElectionsBounds
defines the count and size limits of both voters and targets for an election.The
struct ElectionBounds
sets 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
ElectionSizeTracker
Keeps track of the amount of data (in size and number of elements) that an election data provider prepares in
get_npos_voters
andget_npos_targets
. The election data provider uses an instance ofElectionSizeTracker
to know when the number of voters exceeded the bounds in terms of size and return the election data to EPM.Changes to the
ElectionDataProvider
interfaceBoth
fn ElectionDataProvider::election_voters
andfn ElectionDataProvider::electable_targets
take 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