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

Add Control to Growth of the Staking Pallet #8920

Merged
51 commits merged into from
Jun 16, 2021
Merged

Conversation

shawntabrizi
Copy link
Member

@shawntabrizi shawntabrizi commented May 27, 2021

This PR attempts to address some of the issues related to scaling the Staking Pallet.

Due to constraints in the runtime, an unbounded and unlimited nominator and validator set is just not possible.

We introduce a few different layers of checks which will provide direct and indirect checks on the size of the staking system:

  • We introduce a minimum active bond for both validators and nominators.

    • These minimum bonds are separate for the validator and nominator role, and are represented as storage items so they can be updated through governance.
    • When calling nominate or validate, we check that your current active bond meets these requirements.
    • When calling unbond we also check that your active bond does not drop below these requirements.
    • At any time, a user can chill, at which point they are able to unbond all their funds.
    • To keep things backwards compatible and safe as these bonds change, we introduce a chill_other extrinsic which is permissionless. This allows any third party user to point to an account where the minimum active bond is not satisfied, and chill that account.
  • We introduce optional hard limits to the number of Validators and Nominators allowed in the staking system.

  • tests for all the new logic

polkadot companion: paritytech/polkadot#3260

@shawntabrizi shawntabrizi requested a review from kianenigma as a code owner May 27, 2021 04:26
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label May 27, 2021
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Looks overall good so far, but must have another look.

Idea: you can write a pre-migration function that does no migration, but only ensures that the current counter values are sane. Then we can put this in a runtime's custom migrations to have this auto-checked every now and then.

@kianenigma kianenigma added B7-runtimenoteworthy C3-medium PR touches the given topic and has a medium impact on builders. labels May 31, 2021
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

  • I think we can provide a simpler and safe way for nominators to compete as well, based on their staked amount.
  • The total limit of nominators should be a storage item that the governance can tweak more easily, without a full-fledged runtime upgrade. The validator count, meh, I care less for that.

Otherwise looks good to me.

@kianenigma kianenigma added C7-high ❗️ D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited and removed C3-medium PR touches the given topic and has a medium impact on builders. labels Jun 4, 2021
@kianenigma
Copy link
Contributor

@shawntabrizi please update this PR such that:

  1. we put the counters in there
  2. impose new MinStake and MinValidatorStake

but don't enforce any bounds yet. You can simply keep the functionality, but set it to None to indicate no bound is enforced now.

Then we can merge this PR asap as it would be simpler.

@kianenigma kianenigma added this to the Polkadot v0.9.5 milestone Jun 10, 2021
Comment on lines 223 to +232
fn new_era(v: u32, n: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 1_462_000
.saturating_add((393_007_000 as Weight).saturating_mul(v as Weight))
// Standard Error: 73_000
.saturating_add((72_014_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 1_146_000
.saturating_add((362_986_000 as Weight).saturating_mul(v as Weight))
// Standard Error: 57_000
.saturating_add((60_216_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(10 as Weight))
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(v as Weight)))
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight)))
.saturating_add(T::DbWeight::get().writes(9 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
Copy link
Member Author

Choose a reason for hiding this comment

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

and this

Copy link
Member Author

Choose a reason for hiding this comment

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

This benchmark seems unused @kianenigma

@shawntabrizi
Copy link
Member Author

Regarding me removing the lower bound on min-bond. I realized at this point in the PR (where things changed a bit in the logic) it is not needed, since it is impossible to have less than ED bonded, so this min is enforced anyway.

@kianenigma
Copy link
Contributor

bot merge

@ghost
Copy link

ghost commented Jun 16, 2021

Trying merge.

@ghost ghost merged commit f88f4ed into master Jun 16, 2021
@ghost ghost deleted the shawntabrizi-staking-count branch June 16, 2021 04:57
shawntabrizi added a commit that referenced this pull request Jun 17, 2021
* start count

* track count

* add max limit

* min bonds for participating

* respect min bond when unbonding

* revert a bit of u32

* fix merge

* more merge fixes

* update to `Current*`

* add helper functions

* Update frame/staking/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* fix

* minbond as storage

* checkpoint

* chill_other

* better bond tracking

* MinBond to MinNominatorBond

* better doc

* use helper function

* oops

* simple hard limits to validators / nominators.

* better doc

* update storage version

* fix tests

* enable migrations

* min bond tests

* chill other tests

* tests for max cap

* check `None` on cap too

* benchmarks

* Update frame/staking/src/lib.rs

* Update frame/staking/src/lib.rs

Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>

* Update frame/staking/src/lib.rs

Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>

* Update frame/staking/src/tests.rs

Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>

* fix benchmark

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* nits

* fix reap_stash benchmark

* remove lower bound to min bond

Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Parity Bot <admin@parity.io>
Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
@cwerling cwerling added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Jun 17, 2021
DrW3RK added a commit to w3f/polkadot-wiki that referenced this pull request Jul 22, 2021
salmad3 pushed a commit to w3f/polkadot-wiki that referenced this pull request Jul 23, 2021
* Update maintain-guides-how-to-chill.md

Summarize the contents in paritytech/substrate#8920

#2173

* Added content on Chill other

* Update maintain-guides-how-to-chill.md

Added suggestions from Danny

* Update maintain-guides-how-to-chill.md

minor correction
salmad3 added a commit to w3f/polkadot-wiki that referenced this pull request Jul 23, 2021
* Bump @octokit/rest from 18.6.7 to 18.6.8 (#2369)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.6.7 to 18.6.8.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](octokit/rest.js@v18.6.7...v18.6.8)

---
updated-dependencies:
- dependency-name: "@octokit/rest"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump katex from 0.13.11 to 0.13.12 (#2370)

Bumps [katex](https://github.com/KaTeX/KaTeX) from 0.13.11 to 0.13.12.
- [Release notes](https://github.com/KaTeX/KaTeX/releases)
- [Changelog](https://github.com/KaTeX/KaTeX/blob/master/CHANGELOG.md)
- [Commits](KaTeX/KaTeX@v0.13.11...v0.13.12)

---
updated-dependencies:
- dependency-name: katex
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update dotscanner listing to include Kusama and a tracking attribute (#2372)

* Update learn-accounts.md (#2358)

* Update learn-accounts.md

Added placeholder for content on Soft vs Hard Derivation paths

* Update learn-accounts.md

Added preliminary information. Might benefit from an infographic or a video explaining derivation paths. Please review and suggest content edits/updates

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update sidebars.js (#2374)

Correcting Typo

* Modify Secure Validator Setup (#2361)

* umodify secure validator setup

* update links + edits

* edits

* edits

* Update maintain-guides-how-to-use-polkadot-validator-setup.md

* Add Conditional Rendering for chain flag (#2367)

* add conditional rendering for chain flag

* Update maintain-sync.md

* Update Pages to address Stales (#2371)

* resolves #2321

* resolves #1844

* resolves #1733

* update simple payouts and prettier (#2363)

Co-authored-by: Danny Salman <salman.danny03@hotmail.com>

* Bump @octokit/rest from 18.6.8 to 18.7.0 (#2378)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.6.8 to 18.7.0.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](octokit/rest.js@v18.6.8...v18.7.0)

---
updated-dependencies:
- dependency-name: "@octokit/rest"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump katex from 0.13.12 to 0.13.13 (#2377)

Bumps [katex](https://github.com/KaTeX/KaTeX) from 0.13.12 to 0.13.13.
- [Release notes](https://github.com/KaTeX/KaTeX/releases)
- [Changelog](https://github.com/KaTeX/KaTeX/blob/master/CHANGELOG.md)
- [Commits](KaTeX/KaTeX@v0.13.12...v0.13.13)

---
updated-dependencies:
- dependency-name: katex
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update maintain-guides-how-to-chill.md (#2375)

* Update maintain-guides-how-to-chill.md

Summarize the contents in paritytech/substrate#8920

#2173

* Added content on Chill other

* Update maintain-guides-how-to-chill.md

Added suggestions from Danny

* Update maintain-guides-how-to-chill.md

minor correction

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dee Evans <deekor88@gmail.com>
Co-authored-by: Radha <86818441+DrW3RK@users.noreply.github.com>
Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>
jakehemmerle pushed a commit to w3f/polkadot-wiki that referenced this pull request Jul 27, 2021
* Update maintain-guides-how-to-chill.md

Summarize the contents in paritytech/substrate#8920

#2173

* Added content on Chill other

* Update maintain-guides-how-to-chill.md

Added suggestions from Danny

* Update maintain-guides-how-to-chill.md

minor correction
salmad3 added a commit to w3f/polkadot-wiki that referenced this pull request Jul 27, 2021
* Bump @octokit/rest from 18.6.7 to 18.6.8 (#2369)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.6.7 to 18.6.8.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](octokit/rest.js@v18.6.7...v18.6.8)

---
updated-dependencies:
- dependency-name: "@octokit/rest"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump katex from 0.13.11 to 0.13.12 (#2370)

Bumps [katex](https://github.com/KaTeX/KaTeX) from 0.13.11 to 0.13.12.
- [Release notes](https://github.com/KaTeX/KaTeX/releases)
- [Changelog](https://github.com/KaTeX/KaTeX/blob/master/CHANGELOG.md)
- [Commits](KaTeX/KaTeX@v0.13.11...v0.13.12)

---
updated-dependencies:
- dependency-name: katex
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Create greetings.yml

* update dotscanner listing to include Kusama and a tracking attribute (#2372)

* Update learn-accounts.md (#2358)

* Update learn-accounts.md

Added placeholder for content on Soft vs Hard Derivation paths

* Update learn-accounts.md

Added preliminary information. Might benefit from an infographic or a video explaining derivation paths. Please review and suggest content edits/updates

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update docs/learn-accounts.md

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>

* Update sidebars.js (#2374)

Correcting Typo

* Modify Secure Validator Setup (#2361)

* umodify secure validator setup

* update links + edits

* edits

* edits

* Update maintain-guides-how-to-use-polkadot-validator-setup.md

* Add Conditional Rendering for chain flag (#2367)

* add conditional rendering for chain flag

* Update maintain-sync.md

* Update Pages to address Stales (#2371)

* resolves #2321

* resolves #1844

* resolves #1733

* update simple payouts and prettier (#2363)

Co-authored-by: Danny Salman <salman.danny03@hotmail.com>

* Bump @octokit/rest from 18.6.8 to 18.7.0 (#2378)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.6.8 to 18.7.0.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](octokit/rest.js@v18.6.8...v18.7.0)

---
updated-dependencies:
- dependency-name: "@octokit/rest"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump katex from 0.13.12 to 0.13.13 (#2377)

Bumps [katex](https://github.com/KaTeX/KaTeX) from 0.13.12 to 0.13.13.
- [Release notes](https://github.com/KaTeX/KaTeX/releases)
- [Changelog](https://github.com/KaTeX/KaTeX/blob/master/CHANGELOG.md)
- [Commits](KaTeX/KaTeX@v0.13.12...v0.13.13)

---
updated-dependencies:
- dependency-name: katex
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update maintain-guides-how-to-chill.md (#2375)

* Update maintain-guides-how-to-chill.md

Summarize the contents in paritytech/substrate#8920

#2173

* Added content on Chill other

* Update maintain-guides-how-to-chill.md

Added suggestions from Danny

* Update maintain-guides-how-to-chill.md

minor correction

* take out stale check

* remove sentry node references (#2383)

* see path

* Bump @polkadot/keyring from 7.0.2 to 7.0.3 (#2385)

Bumps [@polkadot/keyring](https://github.com/polkadot-js/common) from 7.0.2 to 7.0.3.
- [Release notes](https://github.com/polkadot-js/common/releases)
- [Changelog](https://github.com/polkadot-js/common/blob/master/CHANGELOG.md)
- [Commits](polkadot-js/common@v7.0.2...v7.0.3)

---
updated-dependencies:
- dependency-name: "@polkadot/keyring"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @polkadot/api from 5.1.1 to 5.2.1 (#2386)

Bumps [@polkadot/api](https://github.com/polkadot-js/api) from 5.1.1 to 5.2.1.
- [Release notes](https://github.com/polkadot-js/api/releases)
- [Changelog](https://github.com/polkadot-js/api/blob/master/CHANGELOG.md)
- [Commits](polkadot-js/api@v5.1.1...v5.2.1)

---
updated-dependencies:
- dependency-name: "@polkadot/api"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @octokit/rest from 18.7.0 to 18.7.1 (#2387)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.7.0 to 18.7.1.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](octokit/rest.js@v18.7.0...v18.7.1)

---
updated-dependencies:
- dependency-name: "@octokit/rest"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Danny Salman <salman.danny03@hotmail.com>

* Update maintain-guides-how-to-use-polkadot-validator

* Add Time Delayed Proxies to the wiki (#2116)

* Add Time Delayed Proxies to the wiki

* Naming fix

* Prettify proxy page

* Add pretty script

* Fix mispelling

Co-authored-by: Danny Salman <salman.danny03@hotmail.com>

* Update sidebars.js (#2384)

* Update sidebars.js

Adding a menu item for video tutorials on Polkadot Wiki

* Create learn-video-tutorials.md

Added key links

* Update learn-video-tutorials.md

more links updated

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dee Evans <deekor88@gmail.com>
Co-authored-by: Radha <86818441+DrW3RK@users.noreply.github.com>
Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>
Co-authored-by: Jake Hemmerle <jakehemmerle@protonmail.com>
Co-authored-by: Emre Surmeli <s.emre.s.8@gmail.com>
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. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants