-
Notifications
You must be signed in to change notification settings - Fork 2.6k
update_roles for nomination pools
#11373
Changes from 4 commits
54e412f
3d403fe
18d3ad2
964c5ca
610681f
ee098c3
b70a514
5901ca2
ff560a3
f8f6608
375fb36
5e04c3d
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 |
|---|---|---|
|
|
@@ -348,7 +348,7 @@ pub const POINTS_TO_BALANCE_INIT_RATIO: u32 = 1; | |
|
|
||
| /// Possible operations on the configuration values of this pallet. | ||
| #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound, PartialEq, Clone)] | ||
| pub enum ConfigOp<T: Default + Codec + Debug> { | ||
| pub enum ConfigOp<T: Codec + Debug> { | ||
| /// Don't change. | ||
| Noop, | ||
| /// Set the given value. | ||
|
|
@@ -505,11 +505,11 @@ pub enum PoolState { | |
| /// Pool adminstration roles. | ||
| #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Debug, PartialEq, Clone)] | ||
| pub struct PoolRoles<AccountId> { | ||
| /// Creates the pool and is the initial member. They can only leave the pool once all | ||
| /// other members have left. Once they fully leave, the pool is destroyed. | ||
| /// Creates the pool and is the initial member. They can only leave the pool once all other | ||
| /// members have left. Once they fully leave, the pool is destroyed. | ||
| pub depositor: AccountId, | ||
| /// Can change the nominator, state-toggler, or itself and can perform any of the actions | ||
| /// the nominator or state-toggler can. | ||
| /// Can change the nominator, state-toggler, or itself and can perform any of the actions the | ||
| /// nominator or state-toggler can. | ||
| pub root: AccountId, | ||
| /// Can select which validators the pool nominates. | ||
| pub nominator: AccountId, | ||
|
|
@@ -1141,9 +1141,14 @@ pub mod pallet { | |
| pub type Metadata<T: Config> = | ||
| CountedStorageMap<_, Twox64Concat, PoolId, BoundedVec<u8, T::MaxMetadataLen>, ValueQuery>; | ||
|
|
||
| /// The last pool id. | ||
| #[pallet::storage] | ||
| pub type LastPoolId<T: Config> = StorageValue<_, u32, ValueQuery>; | ||
|
|
||
| /// A reverse lookup from the pool's account id to its id. | ||
| /// | ||
| /// This is only used for slashing. In all other instances, the pool id is used, and the | ||
| /// accounts are deterministically derived from it. | ||
| #[pallet::storage] | ||
| pub type ReversePoolIdLookup<T: Config> = | ||
| CountedStorageMap<_, Twox64Concat, T::AccountId, PoolId, OptionQuery>; | ||
|
|
@@ -1209,6 +1214,8 @@ pub mod pallet { | |
| /// | ||
| /// The removal can be voluntary (withdrawn all unbonded funds) or involuntary (kicked). | ||
| MemberRemoved { pool_id: PoolId, member: T::AccountId }, | ||
| /// The roles of a pool have been updated to the given new roles. | ||
| RolesUpdated { root: T::AccountId, state_toggler: T::AccountId, nominator: T::AccountId }, | ||
|
ggwpez marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #[pallet::error] | ||
|
|
@@ -1269,6 +1276,8 @@ pub mod pallet { | |
| NotEnoughPointsToUnbond, | ||
| /// Partial unbonding now allowed permissionlessly. | ||
| PartialUnbondNotAllowedPermissionlessly, | ||
| /// Cannot remove any of the roles, they can only be set ot left unchanged. | ||
|
kianenigma marked this conversation as resolved.
Outdated
|
||
| CannotRemoveRole, | ||
| } | ||
|
|
||
| #[pallet::call] | ||
|
|
@@ -1436,9 +1445,9 @@ pub mod pallet { | |
|
|
||
| bonded_pool.ok_to_unbond_with(&caller, &member_account, &member, unbonding_points)?; | ||
|
|
||
| // Claim the the payout prior to unbonding. Once the user is unbonding their points | ||
| // no longer exist in the bonded pool and thus they can no longer claim their payouts. | ||
| // It is not strictly necessary to claim the rewards, but we do it here for UX. | ||
| // Claim the the payout prior to unbonding. Once the user is unbonding their points no | ||
| // longer exist in the bonded pool and thus they can no longer claim their payouts. It | ||
| // is not strictly necessary to claim the rewards, but we do it here for UX. | ||
| Self::do_reward_payout( | ||
| &member_account, | ||
| &mut member, | ||
|
|
@@ -1827,6 +1836,50 @@ pub mod pallet { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Update the roles of the pool. | ||
| /// | ||
| /// The root is the only entity that can change any of the roles, including itself, | ||
| /// excluding the depositor, who can never change. | ||
| /// | ||
| /// It emits an event, notifying UIs of the role change. This event is quite relevant to | ||
| /// most pool members and they should be informed of changes to pool roles. | ||
| #[pallet::weight(T::WeightInfo::update_roles())] | ||
| pub fn update_roles( | ||
| origin: OriginFor<T>, | ||
| pool_id: PoolId, | ||
| root: ConfigOp<T::AccountId>, | ||
|
ggwpez marked this conversation as resolved.
Outdated
|
||
| nominator: ConfigOp<T::AccountId>, | ||
| state_toggler: ConfigOp<T::AccountId>, | ||
| ) -> DispatchResult { | ||
| let who = ensure_signed(origin)?; | ||
| let mut bonded_pool = BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?; | ||
|
Member
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. Ahh damn, I think unsigned extrinsics could now cause a DB-Read without paying for it?
Contributor
Author
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. they still pay for the full transaction, as if it set all values.
Member
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. not an unsigned message though, since it wouldnt fail the extrinsic test until the origin check
Member
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. nit pick fix here #11391 |
||
| ensure!(bonded_pool.roles.root == who, Error::<T>::DoesNotHavePermission); | ||
|
Member
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. if you can forsee it being useful, could also make this callable by
Contributor
Author
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. good point, yeah I think it is.
Contributor
Author
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. |
||
|
|
||
| match root { | ||
| ConfigOp::Noop => (), | ||
| ConfigOp::Set(v) => bonded_pool.roles.root = v, | ||
| ConfigOp::Remove => Err(Error::<T>::CannotRemoveRole)?, | ||
| }; | ||
| match nominator { | ||
| ConfigOp::Noop => (), | ||
| ConfigOp::Set(v) => bonded_pool.roles.nominator = v, | ||
| ConfigOp::Remove => Err(Error::<T>::CannotRemoveRole)?, | ||
|
ggwpez marked this conversation as resolved.
Outdated
|
||
| }; | ||
| match state_toggler { | ||
| ConfigOp::Noop => (), | ||
| ConfigOp::Set(v) => bonded_pool.roles.state_toggler = v, | ||
| ConfigOp::Remove => Err(Error::<T>::CannotRemoveRole)?, | ||
| }; | ||
|
|
||
| Self::deposit_event(Event::<T>::RolesUpdated { | ||
| root: bonded_pool.roles.root.clone(), | ||
| nominator: bonded_pool.roles.nominator.clone(), | ||
| state_toggler: bonded_pool.roles.state_toggler.clone(), | ||
| }); | ||
| bonded_pool.put(); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[pallet::hooks] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.