difftreelog
feat(identity) force set subs
in: master
4 files changed
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -146,5 +146,5 @@
make _bench PALLET=app-promotion PALLET_DIR=app-promotion
.PHONY: bench
-# Disabled: bench-scheduler, bench-collator-selection, bench-rmrk-core, bench-rmrk-equip
-bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-identity
+# Disabled: bench-scheduler, bench-collator-selection, bench-identity, bench-rmrk-core, bench-rmrk-equip
+bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets
pallets/identity/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -417,7 +417,7 @@
let n in 0..600;
use frame_benchmarking::account;
let identities = (0..n).map(|i| (
- account("caller", i, 0),
+ account("caller", i, SEED),
Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
judgements: Default::default(),
deposit: Default::default(),
@@ -433,7 +433,7 @@
use frame_benchmarking::account;
let origin = T::ForceOrigin::successful_origin();
let identities = (0..n).map(|i| (
- account("caller", i, 0),
+ account("caller", i, SEED),
Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
judgements: Default::default(),
deposit: Default::default(),
@@ -446,6 +446,20 @@
let identities = identities.into_iter().map(|(acc, _)| acc).collect::<Vec<_>>();
}: _<T::RuntimeOrigin>(origin, identities)
+ force_set_subs {
+ let s in 0 .. T::MaxSubAccounts::get();
+ let n in 0..600;
+ use frame_benchmarking::account;
+ let identities = (0..n).map(|i| (
+ account("caller", i, SEED),
+ (
+ BalanceOf::<T>::max_value(),
+ create_sub_accounts::<T>(&caller, s)?.try_into().unwrap(),
+ ),
+ )).collect::<Vec<_>>();
+ let origin = T::ForceOrigin::successful_origin();
+ }: _<T::RuntimeOrigin>(origin, identities)
+
add_sub {
let s in 0 .. T::MaxSubAccounts::get() - 1;
pallets/identity/src/lib.rsdiffbeforeafterboth--- a/pallets/identity/src/lib.rs
+++ b/pallets/identity/src/lib.rs
@@ -314,6 +314,8 @@
main: T::AccountId,
deposit: BalanceOf<T>,
},
+ /// A number of identities were forcibly updated with new sub-identities.
+ SubIdentitiesInserted { amount: u32 },
}
#[pallet::call]
@@ -1137,13 +1139,64 @@
) -> DispatchResult {
T::ForceOrigin::ensure_origin(origin)?;
for identity in identities.clone() {
- IdentityOf::<T>::set(identity, None);
+ let (_, sub_ids) = <SubsOf<T>>::take(&identity);
+ <IdentityOf<T>>::remove(&identity);
+ for sub in sub_ids.iter() {
+ <SuperOf<T>>::remove(sub);
+ }
}
Self::deposit_event(Event::IdentitiesRemoved {
amount: identities.len() as u32,
});
Ok(())
}
+
+ /// Set sub-identities to be associated with the provided accounts as force origin.
+ ///
+ /// This is not meant to operate in tandem with the identity pallet as is,
+ /// and be instead used to keep identities made and verified externally,
+ /// forbidden from interacting with an ordinary user, since it ignores any safety mechanism.
+ #[pallet::call_index(17)]
+ #[pallet::weight(T::WeightInfo::force_set_subs(
+ T::MaxSubAccounts::get(), // S
+ subs.len() as u32, // N
+ ))]
+ pub fn force_set_subs(
+ origin: OriginFor<T>,
+ subs: Vec<(
+ T::AccountId,
+ (
+ BalanceOf<T>,
+ BoundedVec<(T::AccountId, Data), T::MaxSubAccounts>,
+ ),
+ )>,
+ ) -> DispatchResult {
+ T::ForceOrigin::ensure_origin(origin)?;
+ for identity in subs.clone() {
+ let account = identity.0;
+ let (_, old_subs) = <SubsOf<T>>::get(&account);
+ for old_sub in old_subs {
+ <SuperOf<T>>::remove(old_sub);
+ }
+
+ let mut ids = BoundedVec::<T::AccountId, T::MaxSubAccounts>::default();
+ for (id, name) in identity.1 .1 {
+ <SuperOf<T>>::insert(&id, (account.clone(), name));
+ ids.try_push(id)
+ .expect("subs length is less than T::MaxSubAccounts; qed");
+ }
+
+ if ids.is_empty() {
+ <SubsOf<T>>::remove(&account);
+ } else {
+ <SubsOf<T>>::insert(account, (identity.1 .0, ids));
+ }
+ }
+ Self::deposit_event(Event::SubIdentitiesInserted {
+ amount: subs.len() as u32,
+ });
+ Ok(())
+ }
}
}
pallets/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)