-
Notifications
You must be signed in to change notification settings - Fork 725
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
(DNM) Prevent users from both directly staking and joining pool #4804
Changes from all commits
05f0d28
d479b4f
e13e836
22b03ea
b65de87
d3cb87d
1285dcd
cf5cb46
1ccf2e6
4eb3700
f86fc86
6872c2e
b3e964c
9cc9ef8
2b1739d
f77ddfc
ecec1f7
f2fae10
357788f
11a9066
941f288
179863a
5ec27dc
8f48031
8b945d1
e7d55e3
d6fcb0d
8fdbdf7
9072e0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: Make pool and staking mutually exclusive | ||
|
||
doc: | ||
- audience: Runtime User | ||
description: | | ||
This PR aims to make pool accounts and staking accounts mutually exclusive. Accounts doing both are still | ||
able to withdraw funds completely from one of them after which they can do all normal operations with other | ||
pallet. This mitigates the risk of using same fund to double stake. | ||
|
||
crates: | ||
- name: westend-runtime | ||
bump: minor | ||
- name: pallet-nomination-pools-benchmarking | ||
bump: minor | ||
- name: pallet-nomination-pools | ||
bump: minor | ||
- name: pallet-staking | ||
bump: minor | ||
- name: pallet-delegated-staking | ||
bump: minor | ||
- name: sp-staking | ||
bump: minor | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -360,7 +360,7 @@ use frame_support::{ | |||||
traits::{ | ||||||
fungible::{Inspect, InspectFreeze, Mutate, MutateFreeze}, | ||||||
tokens::{Fortitude, Preservation}, | ||||||
Defensive, DefensiveOption, DefensiveResult, DefensiveSaturating, Get, | ||||||
Contains, Defensive, DefensiveOption, DefensiveResult, DefensiveSaturating, Get, | ||||||
}, | ||||||
DefaultNoBound, PalletError, | ||||||
}; | ||||||
|
@@ -1648,6 +1648,9 @@ pub mod pallet { | |||||
|
||||||
/// The origin that can manage pool configurations. | ||||||
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||||||
|
||||||
/// Blacklist some accounts from participating in pools. | ||||||
type Blacklist: Contains<Self::AccountId>; | ||||||
} | ||||||
|
||||||
/// The sum of funds across all pools. | ||||||
|
@@ -1946,6 +1949,9 @@ pub mod pallet { | |||||
NotMigrated, | ||||||
/// This call is not allowed in the current state of the pallet. | ||||||
NotSupported, | ||||||
/// Account is blacklisted from participation in pools. This may happen if the account is | ||||||
/// staking in another way already. | ||||||
Blacklisted, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above, I think "BlackListed" may be too overwhelming for a end-user as it seems it's excluding the user from bonding/staking for malicious reasons. Maybe we could rename it to OTOH naming the config types as |
||||||
} | ||||||
|
||||||
#[derive(Encode, Decode, PartialEq, TypeInfo, PalletError, RuntimeDebug)] | ||||||
|
@@ -1983,8 +1989,9 @@ pub mod pallet { | |||||
|
||||||
#[pallet::call] | ||||||
impl<T: Config> Pallet<T> { | ||||||
/// Stake funds with a pool. The amount to bond is transferred from the member to the | ||||||
/// pools account and immediately increases the pools bond. | ||||||
/// Stake funds with a pool. The amount to bond is delegated (or transferred based on | ||||||
/// [`adapter::StakeStrategyType`]) from the member to the pool account and immediately | ||||||
/// increases the pools bond. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// | ||||||
/// # Note | ||||||
/// | ||||||
|
@@ -2001,6 +2008,7 @@ pub mod pallet { | |||||
pool_id: PoolId, | ||||||
) -> DispatchResult { | ||||||
let who = ensure_signed(origin)?; | ||||||
ensure!(!T::Blacklist::contains(&who), Error::<T>::Blacklisted); | ||||||
|
||||||
ensure!(amount >= MinJoinBond::<T>::get(), Error::<T>::MinimumBondNotMet); | ||||||
// If a member already exists that means they already belong to a pool | ||||||
|
@@ -2063,6 +2071,7 @@ pub mod pallet { | |||||
)] | ||||||
pub fn bond_extra(origin: OriginFor<T>, extra: BondExtra<BalanceOf<T>>) -> DispatchResult { | ||||||
let who = ensure_signed(origin)?; | ||||||
ensure!(!T::Blacklist::contains(&who), Error::<T>::Blacklisted); | ||||||
Self::do_bond_extra(who.clone(), who, extra) | ||||||
} | ||||||
|
||||||
|
@@ -2411,6 +2420,7 @@ pub mod pallet { | |||||
bouncer: AccountIdLookupOf<T>, | ||||||
) -> DispatchResult { | ||||||
let depositor = ensure_signed(origin)?; | ||||||
ensure!(!T::Blacklist::contains(&depositor), Error::<T>::Blacklisted); | ||||||
|
||||||
let pool_id = LastPoolId::<T>::try_mutate::<_, Error<T>, _>(|id| { | ||||||
*id = id.checked_add(1).ok_or(Error::<T>::OverflowRisk)?; | ||||||
|
@@ -2437,6 +2447,7 @@ pub mod pallet { | |||||
pool_id: PoolId, | ||||||
) -> DispatchResult { | ||||||
let depositor = ensure_signed(origin)?; | ||||||
ensure!(!T::Blacklist::contains(&depositor), Error::<T>::Blacklisted); | ||||||
|
||||||
ensure!(!BondedPools::<T>::contains_key(pool_id), Error::<T>::PoolIdInUse); | ||||||
ensure!(pool_id < LastPoolId::<T>::get(), Error::<T>::InvalidPoolId); | ||||||
|
@@ -2692,7 +2703,9 @@ pub mod pallet { | |||||
extra: BondExtra<BalanceOf<T>>, | ||||||
) -> DispatchResult { | ||||||
let who = ensure_signed(origin)?; | ||||||
Self::do_bond_extra(who, T::Lookup::lookup(member)?, extra) | ||||||
let member = T::Lookup::lookup(member)?; | ||||||
ensure!(!T::Blacklist::contains(&member), Error::<T>::Blacklisted); | ||||||
Self::do_bond_extra(who, member, extra) | ||||||
} | ||||||
|
||||||
/// Allows a pool member to set a claim permission to allow or disallow permissionless | ||||||
|
@@ -2916,6 +2929,8 @@ pub mod pallet { | |||||
); | ||||||
|
||||||
let member_account = T::Lookup::lookup(member_account)?; | ||||||
ensure!(!T::Blacklist::contains(&member_account), Error::<T>::Blacklisted); | ||||||
|
||||||
let member = | ||||||
PoolMembers::<T>::get(&member_account).ok_or(Error::<T>::PoolMemberNotFound)?; | ||||||
|
||||||
|
@@ -3948,3 +3963,10 @@ impl<T: Config> sp_staking::OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pall | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add some rustdoc to this struct? |
||||||
pub struct AllPoolMembers<T: Config>(PhantomData<T>); | ||||||
impl<T: Config> Contains<T::AccountId> for AllPoolMembers<T> { | ||||||
fn contains(t: &T::AccountId) -> bool { | ||||||
PoolMembers::<T>::contains_key(t) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this error too dramatic. If I was a user and didn't know what Blacklisted meant in this context, I'd probably panic. Maybe we could rename it to
Error::UnableToBond
instead or something else?