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

Implement pallet-bags-list and its interfaces with pallet-staking #9507

Merged
290 commits merged into from
Sep 17, 2021

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Aug 5, 2021

closes #9440

polkadot companion paritytech/polkadot#3413

Notes for reviewers

Below is a table describing how an extrinsic would affect an account (relative to SortedListProvider and CounterForNominators) given its role in staking:

extrinsic Chilled Nominator Validator
chill, chill_other nothing, nothing on_remove, dec counter nothing, nothing
nominate on_insert, inc counter nothing, nothing on_insert, inc counter
validate nothing, nothing on_remove, dec counter nothing, nothing
bond_extra nothing, nothing on_update, nothing nothing, nothing
rebond nothing, nothing on_update, nothing nothing, nothing
unbond nothing, nothing on_update, nothing nothing, nothing

TODO:


  • (seperate_pr) Make all staking tests work with and without bags-list. For now we use bags-list only, and we do this in a follow up, to prevent a single super big PR.
  • rename and fix docs, avoid using voter in bags-list, it should be id and vote-weight. Ideally we could also use something like priority instead of vote-weight.
  • (maybe+separate PR) Write a fuzzer/quick test that just bombards the SortedListProvider with random data and calls, and the internal state of the pallet should always remain correct. (Fuzzer for Pallet Bags List #9851)
  • (seperate pr) weight refunds for when the operation does not affect nominators (and thus not the bags list)
  • (separate PR) Allow the ability to reorder yourself within a bag.

original description for #9081 below:

Problem: there are too many nominators, we can't keep all of them.
Solution: truncate the list by stake.

Problem: an attacker can kick out as many people as they can afford to; those people at the low end would need to re-nominate.
Solution: don't actually take them out of the nominator set, but compute the top N members at runtime.

Problem: computing the top N at runtime is expensive.
Solution: create many bags, each of which holds voters within a particular stake range. Each bag is a linked list, so it can be added to and removed from in O(1). We can then iterate over the bags in order and truncate anywhere we desire. Given a realistic distribution of stake, it doesn't matter where we stop; the final bag is the one with the lowest-staked individuals.

polkadot companion: paritytech/polkadot#3413

coriolinus and others added 30 commits June 30, 2021 11:47
Co-authored-by: Kian Paimani <[email protected]>
This reorganizes bag storage such that bags are always referred to
by their upper threshold. This in turn means that adding and removing
bags is cheaper; you only need to migrate certain voters, not all of them.
The macro approach seems to be a non-starter; that only really works
if we're throwing around numeric literals everywhere, and that's just
not nice in this case.

Instead, let's write helper functions and make it really easy to
generate the tables in separate, permanent files, which humans
can then edit.
This isn't yet done, becuase it seems to take a Very Long Time to run,
and it really shouldn't. Need to look into that.

Still, it's a lot closer than it was this morning.
Turns out that when you're working in exponential space, you need
to divide, not subtract, in order to keep the math working properly.

Also neaten up the output a little bit to make it easier to read.
@emostov
Copy link
Contributor Author

emostov commented Sep 16, 2021

bot merge force

@ghost
Copy link

ghost commented Sep 16, 2021

Trying merge.

@ghost
Copy link

ghost commented Sep 16, 2021

Merge failed: "3 of 8 required status checks have not succeeded: 1 expected, 1 failing, and 1 pending."

@emostov
Copy link
Contributor Author

emostov commented Sep 16, 2021

bot merge

@ghost
Copy link

ghost commented Sep 16, 2021

Trying merge.

@ghost
Copy link

ghost commented Sep 16, 2021

Merge failed: "Required status check "continuous-integration/gitlab-check-polkadot-companion-build" is failing."

@emostov
Copy link
Contributor Author

emostov commented Sep 17, 2021

bot merge

@ghost
Copy link

ghost commented Sep 17, 2021

Trying merge.

This pull request was closed.
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. 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
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Make staking VoterList implementation generic
7 participants