difftreelog
feat(identity) force set subs
in: master
4 files changed
Makefilediffbeforeafterboth146 make _bench PALLET=app-promotion PALLET_DIR=app-promotion146 make _bench PALLET=app-promotion PALLET_DIR=app-promotion147 147 148.PHONY: bench148.PHONY: bench149# Disabled: bench-scheduler, bench-collator-selection, bench-rmrk-core, bench-rmrk-equip149# Disabled: bench-scheduler, bench-collator-selection, bench-identity, bench-rmrk-core, bench-rmrk-equip150bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-identity150bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets151151pallets/identity/src/benchmarking.rsdiffbeforeafterboth417 let n in 0..600;417 let n in 0..600;418 use frame_benchmarking::account;418 use frame_benchmarking::account;419 let identities = (0..n).map(|i| (419 let identities = (0..n).map(|i| (420 account("caller", i, 0),420 account("caller", i, SEED),421 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {421 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {422 judgements: Default::default(),422 judgements: Default::default(),423 deposit: Default::default(),423 deposit: Default::default(),433 use frame_benchmarking::account;433 use frame_benchmarking::account;434 let origin = T::ForceOrigin::successful_origin();434 let origin = T::ForceOrigin::successful_origin();435 let identities = (0..n).map(|i| (435 let identities = (0..n).map(|i| (436 account("caller", i, 0),436 account("caller", i, SEED),437 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {437 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {438 judgements: Default::default(),438 judgements: Default::default(),439 deposit: Default::default(),439 deposit: Default::default(),444 Identity::<T>::force_insert_identities(origin.clone(), identities.clone()),444 Identity::<T>::force_insert_identities(origin.clone(), identities.clone()),445 );445 );446 let identities = identities.into_iter().map(|(acc, _)| acc).collect::<Vec<_>>();446 let identities = identities.into_iter().map(|(acc, _)| acc).collect::<Vec<_>>();447 }: _<T::RuntimeOrigin>(origin, identities)447 }: _<T::RuntimeOrigin>(origin, identities)448449 force_set_subs {450 let s in 0 .. T::MaxSubAccounts::get();451 let n in 0..600;452 use frame_benchmarking::account;453 let identities = (0..n).map(|i| (454 account("caller", i, SEED),455 (456 BalanceOf::<T>::max_value(),457 create_sub_accounts::<T>(&caller, s)?.try_into().unwrap(),458 ),459 )).collect::<Vec<_>>();460 let origin = T::ForceOrigin::successful_origin();461 }: _<T::RuntimeOrigin>(origin, identities)448462449 add_sub {463 add_sub {450 let s in 0 .. T::MaxSubAccounts::get() - 1;464 let s in 0 .. T::MaxSubAccounts::get() - 1;pallets/identity/src/lib.rsdiffbeforeafterboth314 main: T::AccountId,314 main: T::AccountId,315 deposit: BalanceOf<T>,315 deposit: BalanceOf<T>,316 },316 },317 /// A number of identities were forcibly updated with new sub-identities.318 SubIdentitiesInserted { amount: u32 },317 }319 }318320319 #[pallet::call]321 #[pallet::call]1137 ) -> DispatchResult {1139 ) -> DispatchResult {1138 T::ForceOrigin::ensure_origin(origin)?;1140 T::ForceOrigin::ensure_origin(origin)?;1139 for identity in identities.clone() {1141 for identity in identities.clone() {1142 let (_, sub_ids) = <SubsOf<T>>::take(&identity);1140 IdentityOf::<T>::set(identity, None);1143 <IdentityOf<T>>::remove(&identity);1144 for sub in sub_ids.iter() {1145 <SuperOf<T>>::remove(sub);1146 }1141 }1147 }1142 Self::deposit_event(Event::IdentitiesRemoved {1148 Self::deposit_event(Event::IdentitiesRemoved {1143 amount: identities.len() as u32,1149 amount: identities.len() as u32,1144 });1150 });1145 Ok(())1151 Ok(())1146 }1152 }11531154 /// Set sub-identities to be associated with the provided accounts as force origin.1155 ///1156 /// This is not meant to operate in tandem with the identity pallet as is,1157 /// and be instead used to keep identities made and verified externally,1158 /// forbidden from interacting with an ordinary user, since it ignores any safety mechanism.1159 #[pallet::call_index(17)]1160 #[pallet::weight(T::WeightInfo::force_set_subs(1161 T::MaxSubAccounts::get(), // S1162 subs.len() as u32, // N1163 ))]1164 pub fn force_set_subs(1165 origin: OriginFor<T>,1166 subs: Vec<(1167 T::AccountId,1168 (1169 BalanceOf<T>,1170 BoundedVec<(T::AccountId, Data), T::MaxSubAccounts>,1171 ),1172 )>,1173 ) -> DispatchResult {1174 T::ForceOrigin::ensure_origin(origin)?;1175 for identity in subs.clone() {1176 let account = identity.0;1177 let (_, old_subs) = <SubsOf<T>>::get(&account);1178 for old_sub in old_subs {1179 <SuperOf<T>>::remove(old_sub);1180 }11811182 let mut ids = BoundedVec::<T::AccountId, T::MaxSubAccounts>::default();1183 for (id, name) in identity.1 .1 {1184 <SuperOf<T>>::insert(&id, (account.clone(), name));1185 ids.try_push(id)1186 .expect("subs length is less than T::MaxSubAccounts; qed");1187 }11881189 if ids.is_empty() {1190 <SubsOf<T>>::remove(&account);1191 } else {1192 <SubsOf<T>>::insert(account, (identity.1 .0, ids));1193 }1194 }1195 Self::deposit_event(Event::SubIdentitiesInserted {1196 amount: subs.len() as u32,1197 });1198 Ok(())1199 }1147 }1200 }1148}1201}11491202pallets/identity/src/weights.rsdiffbeforeafterboth78 fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;78 fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;79 fn force_insert_identities(x: u32, n: u32, ) -> Weight;79 fn force_insert_identities(x: u32, n: u32, ) -> Weight;80 fn force_remove_identities(x: u32, n: u32, ) -> Weight;80 fn force_remove_identities(x: u32, n: u32, ) -> Weight;81 fn force_set_subs(s: u32, n: u32, ) -> Weight;81 fn add_sub(s: u32, ) -> Weight;82 fn add_sub(s: u32, ) -> Weight;82 fn rename_sub(s: u32, ) -> Weight;83 fn rename_sub(s: u32, ) -> Weight;83 fn remove_sub(s: u32, ) -> Weight;84 fn remove_sub(s: u32, ) -> Weight;273 .saturating_add(T::DbWeight::get().reads(1 as u64))274 .saturating_add(T::DbWeight::get().reads(1 as u64))274 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))275 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))275 }276 }277 // Storage: Identity IdentityOf (r:1 w:1)278 // todo:collator279 /// The range of component `s` is `[0, 100]`.280 /// The range of component `n` is `[0, 600]`.281 fn force_set_subs(s: u32, n: u32) -> Weight {282 // Minimum execution time: 41_872 nanoseconds.283 Weight::from_ref_time(40_230_216 as u64)284 // Standard Error: 2_342285 .saturating_add(Weight::from_ref_time(145_168 as u64))286 // Standard Error: 457287 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))288 .saturating_add(T::DbWeight::get().reads(1 as u64))289 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))290 }276 // Storage: Identity IdentityOf (r:1 w:0)291 // Storage: Identity IdentityOf (r:1 w:0)277 // Storage: Identity SuperOf (r:1 w:1)292 // Storage: Identity SuperOf (r:1 w:1)278 // Storage: Identity SubsOf (r:1 w:1)293 // Storage: Identity SubsOf (r:1 w:1)509 .saturating_add(RocksDbWeight::get().reads(1 as u64))524 .saturating_add(RocksDbWeight::get().reads(1 as u64))510 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))525 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))511 }526 }527 // Storage: Identity IdentityOf (r:1 w:1)528 // todo:collator529 /// The range of component `xs is `[0, 100]`.530 /// The range of component `n` is `[0, 600]`.531 fn force_set_subs(s: u32, n: u32) -> Weight {532 // Minimum execution time: 41_872 nanoseconds.533 Weight::from_ref_time(40_230_216 as u64)534 // Standard Error: 2_342535 .saturating_add(Weight::from_ref_time(145_168 as u64))536 // Standard Error: 457537 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))538 .saturating_add(RocksDbWeight::get().reads(1 as u64))539 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))540 }512 // Storage: Identity IdentityOf (r:1 w:0)541 // Storage: Identity IdentityOf (r:1 w:0)513 // Storage: Identity SuperOf (r:1 w:1)542 // Storage: Identity SuperOf (r:1 w:1)514 // Storage: Identity SubsOf (r:1 w:1)543 // Storage: Identity SubsOf (r:1 w:1)