Skip to content
Snippets Groups Projects
Unverified Commit 8949856d authored by Ankan's avatar Ankan Committed by GitHub
Browse files

Refactor Nomination Pool to support multiple staking strategies (#3905)

Third and final PR in the set, closes
https://github.com/paritytech/polkadot-sdk/issues/454.

Original PR: https://github.com/paritytech/polkadot-sdk/pull/2680

## Precursors:
- https://github.com/paritytech/polkadot-sdk/pull/3889.
- https://github.com/paritytech/polkadot-sdk/pull/3904.

## Follow up issues/improvements
- https://github.com/paritytech/polkadot-sdk/issues/4404

Overall changes are documented here (lot more visual :heart_eyes:

):
https://hackmd.io/@ak0n/454-np-governance

## Summary of various roles 🤯
### Pallet Staking
**Nominator**: An account that directly stakes on `pallet-staking` and
nominates a set of validators.
**Stakers**: Common term for nominators and validators.
Virtual Stakers: Same as stakers, but they are keyless accounts and
their locks are managed by a pallet external to `pallet-staking`.

### Pallet Delegated Staking
**Agent**: An account that receives delegation from other accounts
(delegators) and stakes on their behalf. They are also Virtual Stakers
in `pallet-staking` where `pallet-delegated-staking` manages its locks.
**Delegator**: An account that delegates some funds to an agent.

### Pallet Nomination Pools
**Pool account**: Keyless account of a pool where funds are pooled.
Members pledge their funds towards the pools. These are going to become
`Agent` accounts in `pallet-delegated-staking`.
**Pool Members**: They are individual members of the pool who
contributed funds to it. They are also `Delegator` in
`pallet-delegated-staking`.

## Changes
### Multiple Stake strategies

**TransferStake**: The current nomination pool logic can be considered a
staking strategy where delegators transfer funds to pool and stake. In
this scenario, funds are locked in pool account, and users lose the
control of their funds.

**DelegateStake**: With this PR, we introduce a new staking strategy
where individual delegators delegate fund to pool. `Delegate` implies
funds are locked in delegator account itself. Important thing to note
is, pool does not have funds of its own, but it has authorization from
its members to use these funds for staking.

We extract out all the interaction of pool with staking interface into a
new trait `StakeStrategy`. This is the logic that varies between the
above two staking strategies. We use the trait `StakeStrategy` to
implement above two strategies: `TransferStake` and `DelegateStake`.

### NominationPool
Consumes an implementation of `StakeStrategy` instead of
`StakingInterface`. I have renamed it from `Staking` to `StakeAdapter`
to clarify the difference from the earlier used trait.

To enable delegation based staking in pool, Nomination pool can be
configured as:
```
type StakeAdapter = pallet_nomination_pools::adapter::DelegateStake<Self, DelegatedStaking>;
```

Note that with the following configuration, the changes in the PR are
no-op.
```
type StakeAdapter = pallet_nomination_pools::adapter::TransferStake<Self, Staking>;
```

## Deployment roadmap
Plan to enable this only in Westend. In production runtimes, we can keep
pool to use `TransferStake` which will be no functional change.

Once we have a full audit, we can enable this in Kusama followed by
Polkadot.

## TODO
- [x] Runtime level (Westend) migration for existing nomination pools.
- [x] Permissionless call/ pallet::tasks for claiming delegator funds.
- [x] Add/update benches.
- [x] Migration tests.
- [x] Storage flag to mark `DelegateStake` migration and integrity
checks to not allow `TransferStake` for migrated runtimes.

---------

Signed-off-by: default avatarMatteo Muraca <mmuraca247@gmail.com>
Signed-off-by: default avatarAlexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: default avatarAndrei Sandu <andrei-mihail@parity.io>
Signed-off-by: default avatarAdrian Catangiu <adrian@parity.io>
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: default avatardivdeploy <chenguangxue@outlook.com>
Signed-off-by: default avatardependabot[bot] <support@github.com>
Signed-off-by: default avatarhongkuang <liurenhong@outlook.com>
Co-authored-by: default avatarBastian Köcher <git@kchr.de>
Co-authored-by: default avatargemini132 <164285545+gemini132@users.noreply.github.com>
Co-authored-by: default avatarMatteo Muraca <56828990+muraca@users.noreply.github.com>
Co-authored-by: default avatarLiam Aharon <liam.aharon@hotmail.com>
Co-authored-by: default avatarKian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: default avatarAlexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: default avatarAlessandro Siniscalchi <asiniscalchi@gmail.com>
Co-authored-by: default avatarAndrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: default avatarRoss Bulat <ross@parity.io>
Co-authored-by: default avatarSerban Iorga <serban@parity.io>
Co-authored-by: default avatars0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: default avatarSam Johnson <sam@durosoft.com>
Co-authored-by: default avatarAdrian Catangiu <adrian@parity.io>
Co-authored-by: default avatarJavier Viola <363911+pepoviola@users.noreply.github.com>
Co-authored-by: default avatarAlexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: default avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: default avatarDastan <88332432+dastansam@users.noreply.github.com>
Co-authored-by: default avatarClara van Staden <claravanstaden64@gmail.com>
Co-authored-by: default avatarRon <yrong1997@gmail.com>
Co-authored-by: default avatarVincent Geddes <vincent@snowfork.com>
Co-authored-by: default avatarSvyatoslav Nikolsky <svyatonik@gmail.com>
Co-authored-by: default avatarMichal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: default avatarDino Pačandi <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: default avatarAndrei Eres <eresav@me.com>
Co-authored-by: default avatarAlin Dima <alin@parity.io>
Co-authored-by: default avatarAndrei Sandu <andrei-mihail@parity.io>
Co-authored-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: default avatarBastian Köcher <info@kchr.de>
Co-authored-by: default avatarBranislav Kontur <bkontur@gmail.com>
Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
Co-authored-by: default avatargupnik <nikhilgupta.iitk@gmail.com>
Co-authored-by: Vladimir Istyufeev's avatarVladimir Istyufeev <vladimir@parity.io>
Co-authored-by: default avatarLulu <morgan@parity.io>
Co-authored-by: default avatarJuan Girini <juangirini@gmail.com>
Co-authored-by: default avatarFrancisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: default avatarDónal Murray <donal.murray@parity.io>
Co-authored-by: default avatarShawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: default avatarKutsal Kaan Bilgin <kutsalbilgin@gmail.com>
Co-authored-by: default avatarErmal Kaleci <ermalkaleci@gmail.com>
Co-authored-by: default avatarordian <write@reusable.software>
Co-authored-by: default avatardivdeploy <166095818+divdeploy@users.noreply.github.com>
Co-authored-by: default avatardependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: default avatarSergej Sakac <73715684+Szegoo@users.noreply.github.com>
Co-authored-by: default avatarSquirrel <gilescope@gmail.com>
Co-authored-by: default avatarHongKuang <166261675+HongKuang@users.noreply.github.com>
Co-authored-by: default avatarTsvetomir Dimitrov <tsvetomir@parity.io>
Co-authored-by: default avatarEgor_P <egor@parity.io>
Co-authored-by: default avatarAaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: default avatarDmitry Markin <dmitry@markin.tech>
Co-authored-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: default avatarLéa Narzis <78718413+lean-apple@users.noreply.github.com>
Co-authored-by: default avatarGonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: default avatargeorgepisaltu <52418509+georgepisaltu@users.noreply.github.com>
Co-authored-by: command-bot <>
Co-authored-by: default avatarPG Herveou <pgherveou@gmail.com>
Co-authored-by: default avatarjimwfs <wqq1479787@163.com>
Co-authored-by: default avatarjimwfs <169986508+jimwfs@users.noreply.github.com>
Co-authored-by: default avatarpolka.dom <polkadotdom@gmail.com>
parent ae864e6a
Branches
No related merge requests found
Pipeline #476991 waiting for manual action with stages
in 1 hour, 12 minutes, and 5 seconds
Showing
with 1248 additions and 204 deletions
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment