diff --git a/system-parachains/people/people-kusama/src/identity_ops.rs b/system-parachains/people/people-kusama/src/identity_ops.rs index c5d7f41a98..3b0df6ee99 100644 --- a/system-parachains/people/people-kusama/src/identity_ops.rs +++ b/system-parachains/people/people-kusama/src/identity_ops.rs @@ -26,7 +26,10 @@ pub mod pallet_identity_ops { pub struct Pallet(PhantomData); #[pallet::config] - pub trait Config: frame_system::Config {} + pub trait Config: frame_system::Config { + /// Overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } #[pallet::error] pub enum Error { @@ -34,6 +37,13 @@ pub mod pallet_identity_ops { NotFound, } + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// The invalid judgements have been cleared. + JudgementsCleared { target: AccountId }, + } + pub(crate) type Identity = ( pallet_identity::Registration< ::Balance, @@ -55,7 +65,7 @@ pub mod pallet_identity_ops { /// This is successful only if the `target` account has judgements to clear. The transaction /// fee is refunded to the caller if successful. #[pallet::call_index(0)] - #[pallet::weight(Pallet::::weight_clear_judgement())] + #[pallet::weight({ 0 })] // TODO generate weights pub fn clear_judgement( _origin: OriginFor, target: AccountId, @@ -66,6 +76,8 @@ pub mod pallet_identity_ops { IdentityOf::insert(&target, identity); + Self::deposit_event(Event::JudgementsCleared { target }); + Ok(Pays::No.into()) } } @@ -94,12 +106,6 @@ pub mod pallet_identity_ops { ((judgements_count - identity.0.judgements.len()) as u32, identity) } - - /// Weight calculation for the worst-case scenario of `clear_judgement`. - /// Equal to 1 identity read/write + 1 subs read + 1 reserve balance read. - fn weight_clear_judgement() -> Weight { - ::DbWeight::get().reads_writes(3, 1) - } } #[pallet::hooks] @@ -180,3 +186,45 @@ pub mod pallet_identity_ops { } } } + +#[cfg(feature = "runtime-benchmarks")] +#[frame_benchmarking::v2::benchmarks(where T: pallet_identity_ops::Config)] +mod benchmarks { + use crate::{people::IdentityInfo, *}; + use frame_benchmarking::BenchmarkError; + use frame_system::RawOrigin; + use pallet_identity::{IdentityInformationProvider, Judgement}; + use pallet_identity_ops::{Event, Identity, *}; + use parachains_common::{AccountId, Balance}; + use sp_core::Get; + use sp_runtime::traits::One; + + #[benchmark] + fn clear_judgement() -> Result<(), BenchmarkError> { + let max_registrars = + <::MaxRegistrars as Get>::get(); + let mut judgements = Vec::<(u32, Judgement)>::new(); + for i in 0..max_registrars { + judgements.push((i, Judgement::FeePaid(Balance::one()))); + } + let identity: Identity = ( + pallet_identity::Registration { + deposit: Balance::one(), + judgements: judgements.try_into().unwrap(), + info: IdentityInfo::create_identity_info(), + }, + None, + ); + + let target: AccountId = [1u8; 32].into(); + + IdentityOf::insert(&target, identity); + + #[extrinsic_call] + _(RawOrigin::None, target.clone()); + + crate::System::assert_last_event(Event::::JudgementsCleared { target }.into()); + + Ok(()) + } +} diff --git a/system-parachains/people/people-kusama/src/lib.rs b/system-parachains/people/people-kusama/src/lib.rs index 0d8fb7ae77..05b2b5d580 100644 --- a/system-parachains/people/people-kusama/src/lib.rs +++ b/system-parachains/people/people-kusama/src/lib.rs @@ -513,7 +513,9 @@ impl identity_migrator::Config for Runtime { type WeightInfo = weights::polkadot_runtime_common_identity_migrator::WeightInfo; } -impl pallet_identity_ops::Config for Runtime {} +impl pallet_identity_ops::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( @@ -579,6 +581,7 @@ mod benches { [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [pallet_identity_ops, IdentityOps] ); }