Skip to content

Commit a883475

Browse files
rockbmbAnk4n
andauthored
Add missing events to nomination pool extrinsincs (#7377)
Found via open-web3-stack/polkadot-ecosystem-tests#165. Closes #7370 . # Description Some extrinsics from `pallet_nomination_pools` were not emitting events: * `set_configs` * `set_claim_permission` * `set_metadata` * `chill` * `nominate` ## Integration N/A ## Review Notes N/A --------- Co-authored-by: Ankan <[email protected]>
1 parent 8834a9b commit a883475

File tree

5 files changed

+254
-27
lines changed

5 files changed

+254
-27
lines changed

prdoc/pr_7377.prdoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Add missing events to nomination pool extrinsics
5+
6+
doc:
7+
- audience: [Runtime Dev, Runtime User]
8+
description: |
9+
Introduces events to extrinsics from `pallet_nomination_pools` that previously had none:
10+
- `set_metadata`
11+
- `nominate`
12+
- `chill`
13+
- `set_configs`
14+
- `set_claim_permission`
15+
16+
crates:
17+
- name: pallet-nomination-pools
18+
bump: major
19+
- name: pallet-staking
20+
bump: none

substrate/frame/nomination-pools/src/lib.rs

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! # Nomination Pools for Staking Delegation
1919
//!
2020
//! A pallet that allows members to delegate their stake to nominating pools. A nomination pool acts
21-
//! as nominator and nominates validators on the members behalf.
21+
//! as nominator and nominates validators on the members' behalf.
2222
//!
2323
//! # Index
2424
//!
@@ -178,7 +178,7 @@
178178
//!
179179
//! ### Pool Members
180180
//!
181-
//! * In general, whenever a pool member changes their total point, the chain will automatically
181+
//! * In general, whenever a pool member changes their total points, the chain will automatically
182182
//! claim all their pending rewards for them. This is not optional, and MUST happen for the reward
183183
//! calculation to remain correct (see the documentation of `bond` as an example). So, make sure
184184
//! you are warning your users about it. They might be surprised if they see that they bonded an
@@ -1865,6 +1865,24 @@ pub mod pallet {
18651865
MinBalanceDeficitAdjusted { pool_id: PoolId, amount: BalanceOf<T> },
18661866
/// Claimed excess frozen ED of af the reward pool.
18671867
MinBalanceExcessAdjusted { pool_id: PoolId, amount: BalanceOf<T> },
1868+
/// A pool member's claim permission has been updated.
1869+
MemberClaimPermissionUpdated { member: T::AccountId, permission: ClaimPermission },
1870+
/// A pool's metadata was updated.
1871+
MetadataUpdated { pool_id: PoolId, caller: T::AccountId },
1872+
/// A pool's nominating account (or the pool's root account) has nominated a validator set
1873+
/// on behalf of the pool.
1874+
PoolNominationMade { pool_id: PoolId, caller: T::AccountId },
1875+
/// The pool is chilled i.e. no longer nominating.
1876+
PoolNominatorChilled { pool_id: PoolId, caller: T::AccountId },
1877+
/// Global parameters regulating nomination pools have been updated.
1878+
GlobalParamsUpdated {
1879+
min_join_bond: BalanceOf<T>,
1880+
min_create_bond: BalanceOf<T>,
1881+
max_pools: Option<u32>,
1882+
max_members: Option<u32>,
1883+
max_members_per_pool: Option<u32>,
1884+
global_max_commission: Option<Perbill>,
1885+
},
18681886
}
18691887

18701888
#[pallet::error]
@@ -2509,13 +2527,13 @@ pub mod pallet {
25092527
/// The dispatch origin of this call must be signed by the pool nominator or the pool
25102528
/// root role.
25112529
///
2512-
/// This directly forward the call to the staking pallet, on behalf of the pool bonded
2513-
/// account.
2530+
/// This directly forwards the call to an implementation of `StakingInterface` (e.g.,
2531+
/// `pallet-staking`) through [`Config::StakeAdapter`], on behalf of the bonded pool.
25142532
///
25152533
/// # Note
25162534
///
2517-
/// In addition to a `root` or `nominator` role of `origin`, pool's depositor needs to have
2518-
/// at least `depositor_min_bond` in the pool to start nominating.
2535+
/// In addition to a `root` or `nominator` role of `origin`, the pool's depositor needs to
2536+
/// have at least `depositor_min_bond` in the pool to start nominating.
25192537
#[pallet::call_index(8)]
25202538
#[pallet::weight(T::WeightInfo::nominate(validators.len() as u32))]
25212539
pub fn nominate(
@@ -2538,7 +2556,9 @@ pub mod pallet {
25382556
Error::<T>::MinimumBondNotMet
25392557
);
25402558

2541-
T::StakeAdapter::nominate(Pool::from(bonded_pool.bonded_account()), validators)
2559+
T::StakeAdapter::nominate(Pool::from(bonded_pool.bonded_account()), validators).map(
2560+
|_| Self::deposit_event(Event::<T>::PoolNominationMade { pool_id, caller: who }),
2561+
)
25422562
}
25432563

25442564
/// Set a new state for the pool.
@@ -2603,6 +2623,8 @@ pub mod pallet {
26032623

26042624
Metadata::<T>::mutate(pool_id, |pool_meta| *pool_meta = metadata);
26052625

2626+
Self::deposit_event(Event::<T>::MetadataUpdated { pool_id, caller: who });
2627+
26062628
Ok(())
26072629
}
26082630

@@ -2646,6 +2668,16 @@ pub mod pallet {
26462668
config_op_exp!(MaxPoolMembers::<T>, max_members);
26472669
config_op_exp!(MaxPoolMembersPerPool::<T>, max_members_per_pool);
26482670
config_op_exp!(GlobalMaxCommission::<T>, global_max_commission);
2671+
2672+
Self::deposit_event(Event::<T>::GlobalParamsUpdated {
2673+
min_join_bond: MinJoinBond::<T>::get(),
2674+
min_create_bond: MinCreateBond::<T>::get(),
2675+
max_pools: MaxPools::<T>::get(),
2676+
max_members: MaxPoolMembers::<T>::get(),
2677+
max_members_per_pool: MaxPoolMembersPerPool::<T>::get(),
2678+
global_max_commission: GlobalMaxCommission::<T>::get(),
2679+
});
2680+
26492681
Ok(())
26502682
}
26512683

@@ -2710,17 +2742,18 @@ pub mod pallet {
27102742
/// The dispatch origin of this call can be signed by the pool nominator or the pool
27112743
/// root role, same as [`Pallet::nominate`].
27122744
///
2745+
/// This directly forwards the call to an implementation of `StakingInterface` (e.g.,
2746+
/// `pallet-staking`) through [`Config::StakeAdapter`], on behalf of the bonded pool.
2747+
///
27132748
/// Under certain conditions, this call can be dispatched permissionlessly (i.e. by any
27142749
/// account).
27152750
///
27162751
/// # Conditions for a permissionless dispatch:
2717-
/// * When pool depositor has less than `MinNominatorBond` staked, otherwise pool members
2752+
/// * When pool depositor has less than `MinNominatorBond` staked, otherwise pool members
27182753
/// are unable to unbond.
27192754
///
27202755
/// # Conditions for permissioned dispatch:
2721-
/// * The caller has a nominator or root role of the pool.
2722-
/// This directly forward the call to the staking pallet, on behalf of the pool bonded
2723-
/// account.
2756+
/// * The caller is the pool's nominator or root.
27242757
#[pallet::call_index(13)]
27252758
#[pallet::weight(T::WeightInfo::chill())]
27262759
pub fn chill(origin: OriginFor<T>, pool_id: PoolId) -> DispatchResult {
@@ -2739,7 +2772,9 @@ pub mod pallet {
27392772
ensure!(bonded_pool.can_nominate(&who), Error::<T>::NotNominator);
27402773
}
27412774

2742-
T::StakeAdapter::chill(Pool::from(bonded_pool.bonded_account()))
2775+
T::StakeAdapter::chill(Pool::from(bonded_pool.bonded_account())).map(|_| {
2776+
Self::deposit_event(Event::<T>::PoolNominatorChilled { pool_id, caller: who })
2777+
})
27432778
}
27442779

27452780
/// `origin` bonds funds from `extra` for some pool member `member` into their respective
@@ -2794,10 +2829,15 @@ pub mod pallet {
27942829
Error::<T>::NotMigrated
27952830
);
27962831

2797-
ClaimPermissions::<T>::mutate(who, |source| {
2832+
ClaimPermissions::<T>::mutate(who.clone(), |source| {
27982833
*source = permission;
27992834
});
28002835

2836+
Self::deposit_event(Event::<T>::MemberClaimPermissionUpdated {
2837+
member: who,
2838+
permission,
2839+
});
2840+
28012841
Ok(())
28022842
}
28032843

@@ -2913,9 +2953,20 @@ pub mod pallet {
29132953

29142954
/// Claim pending commission.
29152955
///
2916-
/// The dispatch origin of this call must be signed by the `root` role of the pool. Pending
2917-
/// commission is paid out and added to total claimed commission`. Total pending commission
2918-
/// is reset to zero. the current.
2956+
/// The `root` role of the pool is _always_ allowed to claim the pool's commission.
2957+
///
2958+
/// If the pool has set `CommissionClaimPermission::Permissionless`, then any account can
2959+
/// trigger the process of claiming the pool's commission.
2960+
///
2961+
/// If the pool has set its `CommissionClaimPermission` to `Account(acc)`, then only
2962+
/// accounts
2963+
/// * `acc`, and
2964+
/// * the pool's root account
2965+
///
2966+
/// may call this extrinsic on behalf of the pool.
2967+
///
2968+
/// Pending commissions are paid out and added to the total claimed commission.
2969+
/// The total pending commission is reset to zero.
29192970
#[pallet::call_index(20)]
29202971
#[pallet::weight(T::WeightInfo::claim_commission())]
29212972
pub fn claim_commission(origin: OriginFor<T>, pool_id: PoolId) -> DispatchResult {

0 commit comments

Comments
 (0)