git.delta.rocks / unique-network / refs/commits / 42b7bebae7e5

difftreelog

feat(identity) force set subs

Fahrrader2023-01-18parent: #9505eb6.patch.diff
in: master

4 files changed

modifiedMakefilediffbeforeafterboth
--- 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
modifiedpallets/identity/src/benchmarking.rsdiffbeforeafterboth
417 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)
448
449 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)
448462
449 add_sub {463 add_sub {
450 let s in 0 .. T::MaxSubAccounts::get() - 1;464 let s in 0 .. T::MaxSubAccounts::get() - 1;
modifiedpallets/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(())
+		}
 	}
 }
 
modifiedpallets/identity/src/weights.rsdiffbeforeafterboth
--- a/pallets/identity/src/weights.rs
+++ b/pallets/identity/src/weights.rs
@@ -78,6 +78,7 @@
 	fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;
 	fn force_insert_identities(x: u32, n: u32, ) -> Weight;
 	fn force_remove_identities(x: u32, n: u32, ) -> Weight;
+	fn force_set_subs(s: u32, n: u32, ) -> Weight;
 	fn add_sub(s: u32, ) -> Weight;
 	fn rename_sub(s: u32, ) -> Weight;
 	fn remove_sub(s: u32, ) -> Weight;
@@ -273,6 +274,20 @@
 			.saturating_add(T::DbWeight::get().reads(1 as u64))
 			.saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))
 	}
+	// Storage: Identity IdentityOf (r:1 w:1)
+	// todo:collator
+	/// The range of component `s` is `[0, 100]`.
+	/// The range of component `n` is `[0, 600]`.
+	fn force_set_subs(s: u32, n: u32) -> Weight {
+		// Minimum execution time: 41_872 nanoseconds.
+		Weight::from_ref_time(40_230_216 as u64)
+			// Standard Error: 2_342
+			.saturating_add(Weight::from_ref_time(145_168 as u64))
+			// Standard Error: 457
+			.saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))
+			.saturating_add(T::DbWeight::get().reads(1 as u64))
+			.saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))
+	}
 	// Storage: Identity IdentityOf (r:1 w:0)
 	// Storage: Identity SuperOf (r:1 w:1)
 	// Storage: Identity SubsOf (r:1 w:1)
@@ -509,6 +524,20 @@
 			.saturating_add(RocksDbWeight::get().reads(1 as u64))
 			.saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))
 	}
+	// Storage: Identity IdentityOf (r:1 w:1)
+	// todo:collator
+	/// The range of component `xs is `[0, 100]`.
+	/// The range of component `n` is `[0, 600]`.
+	fn force_set_subs(s: u32, n: u32) -> Weight {
+		// Minimum execution time: 41_872 nanoseconds.
+		Weight::from_ref_time(40_230_216 as u64)
+			// Standard Error: 2_342
+			.saturating_add(Weight::from_ref_time(145_168 as u64))
+			// Standard Error: 457
+			.saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))
+			.saturating_add(RocksDbWeight::get().reads(1 as u64))
+			.saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))
+	}
 	// Storage: Identity IdentityOf (r:1 w:0)
 	// Storage: Identity SuperOf (r:1 w:1)
 	// Storage: Identity SubsOf (r:1 w:1)