Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nomination Pool] Make staking restrictions configurable #7685

Merged
merged 14 commits into from
Feb 26, 2025

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Feb 24, 2025

closes #5742

Need to be backported to stable2503 release.

With the migration of staking accounts to fungible currency, we can now allow pool users to stake directly and vice versa. This update introduces a configurable filter mechanism to determine which accounts can join a nomination pool.

Example Usage

1. Allow any account to join a pool

To permit all accounts to join a nomination pool, use the Nothing filter:

impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = Nothing;
}

2. Restrict direct stakers from joining a pool

To prevent direct stakers from joining a nomination pool, use pallet_staking::AllStakers:

impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = pallet_staking::AllStakers<Runtime>;
}

3. Define a custom filter

For more granular control, you can define a custom filter:

struct MyCustomFilter<T: Config>(core::marker::PhantomData<T>);

impl<T: Config> Contains<T::AccountId> for MyCustomFilter<T> {
    fn contains(account: &T::AccountId) -> bool {
        todo!("Implement custom logic. Return `false` to allow the account to join a pool.")
    }
}

@Ank4n Ank4n added T1-FRAME This PR/Issue is related to core FRAME, the framework. T2-pallets This PR/Issue is related to a particular pallet. labels Feb 24, 2025
@Ank4n Ank4n marked this pull request as ready for review February 24, 2025 12:44
@Ank4n Ank4n requested a review from a team as a code owner February 24, 2025 12:44
@paritytech paritytech deleted a comment from kianenigma Feb 26, 2025
@bkchr bkchr force-pushed the ankan/make-pool-restriction-configurable branch 3 times, most recently from 5bbc2c7 to fcbb0bb Compare February 26, 2025 15:31
@bkchr bkchr force-pushed the ankan/make-pool-restriction-configurable branch 2 times, most recently from d9beb43 to 91cbb9f Compare February 26, 2025 15:41
@bkchr bkchr force-pushed the ankan/make-pool-restriction-configurable branch from 8592d82 to 428b491 Compare February 26, 2025 16:05
@Ank4n Ank4n changed the title [Nomination Pool] Make joining pool restriction configurable [Nomination Pool] Make staking restrictions configurable Feb 26, 2025
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13550269016
Failed job name: fmt

/// This struct implements the `Contains` trait, allowing it to determine whether
/// a particular account is currently staking by checking if the account exists in
/// the staking ledger.
pub struct AllStakers<T: Config>(core::marker::PhantomData<T>);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would name this something like AllDirectStakers or AllNativeStakers, since people who join nomination pools could still be considered "stakers" (i.e. they have their funds at stake). This is checking that they have an entry in the staking ledger specific to their account.

@bkchr bkchr merged commit f7e98b4 into master Feb 26, 2025
243 of 254 checks passed
@bkchr bkchr deleted the ankan/make-pool-restriction-configurable branch February 26, 2025 20:12
bkchr added a commit that referenced this pull request Feb 26, 2025
closes #5742

Need to be backported to stable2503 release.

With the migration of staking accounts to [fungible
currency](#5501), we can
now allow pool users to stake directly and vice versa. This update
introduces a configurable filter mechanism to determine which accounts
can join a nomination pool.

To permit all accounts to join a nomination pool, use the `Nothing`
filter:

```rust
impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = Nothing;
}
```

To prevent direct stakers from joining a nomination pool, use
`pallet_staking::AllStakers`:
```rust
impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = pallet_staking::AllStakers<Runtime>;
}
```

For more granular control, you can define a custom filter:
```rust
struct MyCustomFilter<T: Config>(core::marker::PhantomData<T>);

impl<T: Config> Contains<T::AccountId> for MyCustomFilter<T> {
    fn contains(account: &T::AccountId) -> bool {
        todo!("Implement custom logic. Return `false` to allow the account to join a pool.")
    }
}
```

---------

Co-authored-by: Bastian Köcher <[email protected]>
@kianenigma kianenigma added the A4-needs-backport Pull request must be backported to all maintained releases. label Feb 26, 2025
@paritytech-cmd-bot-polkadot-sdk
Copy link
Contributor

Created backport PR for stable2407:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-7685-to-stable2407
git worktree add --checkout .worktree/backport-7685-to-stable2407 backport-7685-to-stable2407
cd .worktree/backport-7685-to-stable2407
git reset --hard HEAD^
git cherry-pick -x f7e98b40cab7475898c99ea48809635ac069af3a
git push --force-with-lease

@paritytech-cmd-bot-polkadot-sdk
Copy link
Contributor

Created backport PR for stable2409:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-7685-to-stable2409
git worktree add --checkout .worktree/backport-7685-to-stable2409 backport-7685-to-stable2409
cd .worktree/backport-7685-to-stable2409
git reset --hard HEAD^
git cherry-pick -x f7e98b40cab7475898c99ea48809635ac069af3a
git push --force-with-lease

@paritytech-cmd-bot-polkadot-sdk
Copy link
Contributor

Created backport PR for stable2412:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-7685-to-stable2412
git worktree add --checkout .worktree/backport-7685-to-stable2412 backport-7685-to-stable2412
cd .worktree/backport-7685-to-stable2412
git reset --hard HEAD^
git cherry-pick -x f7e98b40cab7475898c99ea48809635ac069af3a
git push --force-with-lease

github-actions bot pushed a commit that referenced this pull request Feb 26, 2025
closes #5742

Need to be backported to stable2503 release.

With the migration of staking accounts to [fungible
currency](#5501), we can
now allow pool users to stake directly and vice versa. This update
introduces a configurable filter mechanism to determine which accounts
can join a nomination pool.

## Example Usage

### 1. Allow any account to join a pool
To permit all accounts to join a nomination pool, use the `Nothing`
filter:

```rust
impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = Nothing;
}
```

### 2. Restrict direct stakers from joining a pool

To prevent direct stakers from joining a nomination pool, use
`pallet_staking::AllStakers`:
```rust
impl pallet_nomination_pools::Config for Runtime {
    ...
    type Filter = pallet_staking::AllStakers<Runtime>;
}
```

### 3. Define a custom filter
For more granular control, you can define a custom filter:
```rust
struct MyCustomFilter<T: Config>(core::marker::PhantomData<T>);

impl<T: Config> Contains<T::AccountId> for MyCustomFilter<T> {
    fn contains(account: &T::AccountId) -> bool {
        todo!("Implement custom logic. Return `false` to allow the account to join a pool.")
    }
}
```

---------

Co-authored-by: Bastian Köcher <[email protected]>
(cherry picked from commit f7e98b4)
@paritytech-cmd-bot-polkadot-sdk
Copy link
Contributor

Successfully created backport PR for stable2503:

EgorPopelyaev pushed a commit that referenced this pull request Feb 27, 2025
Backport #7685 into `stable2503` from Ank4n.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Ankan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A4-needs-backport Pull request must be backported to all maintained releases. T1-FRAME This PR/Issue is related to core FRAME, the framework. T2-pallets This PR/Issue is related to a particular pallet.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Ensure nomination pool members can directly stake and vice versa.
4 participants