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

Fast Unstake Pallet #12129

Merged
merged 99 commits into from
Sep 23, 2022
Merged

Fast Unstake Pallet #12129

merged 99 commits into from
Sep 23, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Aug 28, 2022

Fixes #8436

This is a pallet that does one thing and one thing only: allow you to unstake from the staking system quickly IFF you are not exposed (i.e. not in the Exposure of any validator) in any of the last BondingDuration eras. Optionally, this pallet allows one to join a pool on the fly as they unstake.

Multiple ideas exist to implement this, all of which have been discussed in #8436. This PR is probably the most conservative approach in terms of security, yet it is the least efficient for the chain. To be specific, the pallet will schedule background tasks to check the entire exposure table of the stash who wants to unstake over multiple blocks. This is not fast, does waste chain resources, but it is safe.

@rossbulat and I have the intention to merge this before 9.29 release and implement it in the staking dashboard as well, hopefully providing a much better UX for those who wish to migrate from staking to Pools.

TODO:

  • Tests @rossbulat
  • Issue for future task: de-couple this from the nomination_pools pallet.

@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt $ 1

@command-bot
Copy link

command-bot bot commented Sep 20, 2022

@kianenigma https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1861972 was started for your command "$PIPELINE_SCRIPTS_DIR/fmt.sh" 1. Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment /cmd cancel 37-5c1b3b9b-da7c-4321-b653-9f26689237fc to cancel this command or /cmd cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Sep 20, 2022

@kianenigma Command "$PIPELINE_SCRIPTS_DIR/fmt.sh" 1 has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1861972 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1861972/artifacts/download.

@kianenigma kianenigma added C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. and removed 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 labels Sep 23, 2022
@kianenigma
Copy link
Contributor Author

merging this, won't go to Polkadot yet.

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit bffd6a3 into master Sep 23, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-fast-unstake branch September 23, 2022 09:36
ordian added a commit that referenced this pull request Sep 23, 2022
* master:
  [Fix] parameter_types! dead code errors (#12340)
  [Feature] Sequential migration execution for try-runtime (#12319)
  bench: Use `_` instead  of `::` in auto-generated file names (#12332)
  Fast Unstake Pallet (#12129)
  Rename anonymous to pure proxy (#12283)
  Migrate remaining old decl_* macros to the new pallet attribute macros (#12271)
  pallet-utility: Disallow none origin (#12321)
  Make automatic storage deposits resistant against changing deposit prices (#12083)
  Format templates and fix `--steps` default value (#12286)
  Bump `wasmtime` to 1.0.0 (#12317)
  Introduce 'intermediate_insert' method to hide implementation details (#12215)
  Bound staking storage items (#12230)
  Use `array-bytes` for All Array/Bytes/Hex Operations (#12190)
  BREAKING: Rename Origin (#12258)
  Use temporary db for benchmarking (#12254)
  rpc: Implement `chainSpec` RPC API (#12261)
  Import target block body during warp sync (#12300)
  Proper naming wrt expectations (#12311)
  [ci] Revert cancel-pipeline job (#12309)
kianenigma added a commit to kianenigma/seeding that referenced this pull request Sep 27, 2022
# Membership Request 

Hi, I am Kian Paimani, known as @kianenigma. I have been working on Polkadot/Kusama through Parity since February 2019 and I can categorize my main contributions to Polkadot's ecosystem as follows: 

1. Maintaining and developing the staking sub-system.
2. General FRAME development, especially testing and quality assurance. 
3. Polkadot-native side-projects. 
4. Education 

> My first contribution to Polkadot is also indeed related to staking: paritytech/substrate#1915

### Staking system

I joke as the Polkadot staking to be both my blessing and my curse over the years. I started working on it since the first days that I joined this ecosystem and the work [is ongoing ever since](https://github.com/orgs/paritytech/projects/33/views/9). In the past, I focused on making sure that the staking system is secure and to some extent scalable. More recently, I coordinated the (imminent) launch of Nomination Pools. Nowadays I also put an extra effort on making sure that this sub-system of Polkadot is *sustainable*, through code refactor and educating other core developers. 

Lastly, I have been the main author of the [Polkadot staking newsletter](https://gist.github.com/kianenigma/aa835946455b9a3f167821b9d05ba376), which is my main attempt at making the entire complexity and development of this part of the protocol transparent to the end-users.

I expect myself to contribute *directly* to the staking system for at least another ~12, if not more, and afterwards having the role of an advisor. 

Some notable contributions: 

- paritytech/substrate#4517
- paritytech/substrate#7910
- paritytech/substrate#6242
- paritytech/substrate#9415
- paritytech/polkadot#3141
- paritytech/substrate#11212
- paritytech/substrate#12129

### FRAME 

Historically, I have contributed a variety of domains in FRAME, namely: 

- Early version of the weight system paritytech/substrate#3816 paritytech/substrate#3157
- Early version of the transaction fee system
- Primitive arithmetic types paritytech/substrate#3456
- Council election pallet paritytech/substrate#3364

Many of which were, admittedly, a PoC at most, if not considered "poor". I am happy that nowadays many of the above have been refactored and are being maintained by new domain experts. 

These days, I put most of my FRAME focus on testing and quality assurance. Through my work in the staking system, I have had to deal with the high sensitivity and liveness requirement of protocol development first hand (I believe I had to do among the [very first storage migrations](paritytech/substrate#3948) in Kusama) and consequently I felt the need to make better testing facilities, all of which have been formulated in https://forum.polkadot.network/t/testing-complex-frame-pallets-discussion-tools/356. Some relevant PRs:

- paritytech/substrate#8038
- paritytech/substrate#9788
- paritytech/substrate#10174

Regardless of wearing the staking hat, I plan to remain a direct contributor to FRAME, namely because I consider it to be an important requirements of successfully delivering more features to Polkadot's ecosystem. 

### Polkadot-Native Side Projects

I have started multiple small, mostly non-RUST projects in the polkadot ecosystem that I am very happy about, and I plan to continue doing so. I have not yet found the time to make a "polished product" out of any of these, but I hope that I can help foster our community such that someday a team will do so. I consider my role, for the time being, to *put ideas out there* through these side projects. 

- https://github.com/substrate-portfolio/polkadot-portfolio/
- https://github.com/kianenigma/polkadot-basic-notification/
- https://github.com/paritytech/polkadot-scripts/
- https://github.com/paritytech/substrate-debug-kit/

### Education 

Lastly, aside from having had a number of educational talks over the years (all of which [are listed](https://hello.kianenigma.nl/talks/) in my personal website), I am a big enthusiast of the newly formed Polkadot Blockchain Academy. I have [been an instructor](https://singular.app/collectibles/statemine/16/2) in the first cohort, and continue to contribute for as long and as much as I can, whilst still attending to the former 3 duties. 

---

With all of that being said and done, I consider myself at the beginning of the path to Dan 4, but happy to start at a lower one as well.
bkchr added a commit to polkadot-fellows/seeding that referenced this pull request Sep 27, 2022
# Membership Request 

Hi, I am Kian Paimani, known as @kianenigma. I have been working on Polkadot/Kusama through Parity since February 2019 and I can categorize my main contributions to Polkadot's ecosystem as follows: 

1. Maintaining and developing the staking sub-system.
2. General FRAME development, especially testing and quality assurance. 
3. Polkadot-native side-projects. 
4. Education 

> My first contribution to Polkadot is also indeed related to staking: paritytech/substrate#1915

### Staking system

I joke as the Polkadot staking to be both my blessing and my curse over the years. I started working on it since the first days that I joined this ecosystem and the work [is ongoing ever since](https://github.com/orgs/paritytech/projects/33/views/9). In the past, I focused on making sure that the staking system is secure and to some extent scalable. More recently, I coordinated the (imminent) launch of Nomination Pools. Nowadays I also put an extra effort on making sure that this sub-system of Polkadot is *sustainable*, through code refactor and educating other core developers. 

Lastly, I have been the main author of the [Polkadot staking newsletter](https://gist.github.com/kianenigma/aa835946455b9a3f167821b9d05ba376), which is my main attempt at making the entire complexity and development of this part of the protocol transparent to the end-users.

I expect myself to contribute *directly* to the staking system for at least another ~12, if not more, and afterwards having the role of an advisor. 

Some notable contributions: 

- paritytech/substrate#4517
- paritytech/substrate#7910
- paritytech/substrate#6242
- paritytech/substrate#9415
- paritytech/polkadot#3141
- paritytech/substrate#11212
- paritytech/substrate#12129

### FRAME 

Historically, I have contributed a variety of domains in FRAME, namely: 

- Early version of the weight system paritytech/substrate#3816 paritytech/substrate#3157
- Early version of the transaction fee system
- Primitive arithmetic types paritytech/substrate#3456
- Council election pallet paritytech/substrate#3364

Many of which were, admittedly, a PoC at most, if not considered "poor". I am happy that nowadays many of the above have been refactored and are being maintained by new domain experts. 

These days, I put most of my FRAME focus on testing and quality assurance. Through my work in the staking system, I have had to deal with the high sensitivity and liveness requirement of protocol development first hand (I believe I had to do among the [very first storage migrations](paritytech/substrate#3948) in Kusama) and consequently I felt the need to make better testing facilities, all of which have been formulated in https://forum.polkadot.network/t/testing-complex-frame-pallets-discussion-tools/356. Some relevant PRs:

- paritytech/substrate#8038
- paritytech/substrate#9788
- paritytech/substrate#10174

Regardless of wearing the staking hat, I plan to remain a direct contributor to FRAME, namely because I consider it to be an important requirements of successfully delivering more features to Polkadot's ecosystem. 

### Polkadot-Native Side Projects

I have started multiple small, mostly non-RUST projects in the polkadot ecosystem that I am very happy about, and I plan to continue doing so. I have not yet found the time to make a "polished product" out of any of these, but I hope that I can help foster our community such that someday a team will do so. I consider my role, for the time being, to *put ideas out there* through these side projects. 

- https://github.com/substrate-portfolio/polkadot-portfolio/
- https://github.com/kianenigma/polkadot-basic-notification/
- https://github.com/paritytech/polkadot-scripts/
- https://github.com/paritytech/substrate-debug-kit/

### Education 

Lastly, aside from having had a number of educational talks over the years (all of which [are listed](https://hello.kianenigma.nl/talks/) in my personal website), I am a big enthusiast of the newly formed Polkadot Blockchain Academy. I have [been an instructor](https://singular.app/collectibles/statemine/16/2) in the first cohort, and continue to contribute for as long and as much as I can, whilst still attending to the former 3 duties. 

---

With all of that being said and done, I consider myself at the beginning of the path to Dan 4, but happy to start at a lower one as well.

Co-authored-by: Bastian Köcher <[email protected]>
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/path-to-fast-unstake-in-polkadot-kusama/1539/1

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-digest-17-jan-2023/1706/1

ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* add failing test for itamar

* an ugly example of fast unstake

* Revert "add failing test for itamar"

This reverts commit bdd1399.

* fast unstake wip

* clean it up a bit

* some comments

* on_idle logic

* fix

* comment

* new working version, checks all pass, looking good

* some notes

* add mock boilerplate

* more boilerplate

* simplify the weight stuff

* ExtBuilder for pools

* fmt

* rm bags-list, simplify setup_works

* mock + tests boilerplate

* make some benchmarks work

* mock boilerplate

* tests boilerplate

* run_to_block works

* add Error enums

* add test

* note

* make UnstakeRequest fields pub

* some tests

* fix origin

* fmt

* add fast_unstake_events_since_last_call

* text

* rewrite some benchmes and fix them -- the outcome is still strange

* Fix weights

* cleanup

* Update frame/election-provider-support/solution-type/src/single_page.rs

* fix build

* Fix pools tests

* iterate teset + mock

* test unfinished

* cleanup and add some tests

* add test successful_multi_queue

* comment

* rm Head check

* add TODO

* complete successful_multi_queue

* + test early_exit

* fix a lot of things above the beautiful atlantic ocean 🌊

* seemingly it is finished now

* Fix build

* ".git/.scripts/fmt.sh" 1

* Fix slashing amount as well

* better docs

* abstract types

* rm use

* import

* Update frame/nomination-pools/benchmarking/src/lib.rs

Co-authored-by: Nitwit <[email protected]>

* Update frame/fast-unstake/src/types.rs

Co-authored-by: Nitwit <[email protected]>

* Fix build

* fmt

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Keith Yeung <[email protected]>

* make bounded

* feedback from code review with Ankan

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Roman Useinov <[email protected]>

* Update frame/fast-unstake/src/mock.rs

* update to master

* some final review comments

* fmt

* fix clippy

* remove unused

* ".git/.scripts/fmt.sh" 1

* make it all build again

* fmt

* undo fishy change

Co-authored-by: Ross Bulat <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: Nitwit <[email protected]>
Co-authored-by: Keith Yeung <[email protected]>
Co-authored-by: Roman Useinov <[email protected]>
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Enable an easy way to unbond, if you are not *exposed*
8 participants