From 903ec3d77d94cd7d7a39075be44f49786ac0571e Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 16 Jan 2024 20:04:38 +0100 Subject: [PATCH 1/5] simpler next step --- .../runtimes/people/people-rococo/src/lib.rs | 14 +++----------- .../people/people-rococo/src/xcm_config.rs | 18 +++++++++++------- .../people/people-westend/src/xcm_config.rs | 18 +++++++++++------- polkadot/runtime/rococo/src/lib.rs | 7 +++---- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 7805e0ad9829..81aedc3c5dd1 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -30,8 +30,7 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, EverythingBut, - TransformOrigin, + ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -124,7 +123,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("people-rococo"), impl_name: create_runtime_str!("people-rococo"), authoring_version: 1, - spec_version: 1_000, + spec_version: 1_006_001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 0, @@ -162,16 +161,9 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } -pub struct IdentityCalls; -impl Contains for IdentityCalls { - fn contains(c: &RuntimeCall) -> bool { - matches!(c, RuntimeCall::Identity(_)) - } -} - #[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = EverythingBut; + type BaseCallFilter = Everything; type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type AccountId = AccountId; diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 7a2f28aa813e..e3b5306065d5 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -169,13 +169,17 @@ impl Contains for SafeCallFilter { matches!( call, - RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) | - RuntimeCall::System( - frame_system::Call::set_heap_pages { .. } | - frame_system::Call::set_code { .. } | - frame_system::Call::set_code_without_checks { .. } | - frame_system::Call::kill_prefix { .. }, - ) | RuntimeCall::ParachainSystem(..) | + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | + pallet_xcm::Call::force_default_xcm_version { .. } + ) | RuntimeCall::System( + frame_system::Call::set_heap_pages { .. } | + frame_system::Call::set_code { .. } | + frame_system::Call::set_code_without_checks { .. } | + frame_system::Call::authorize_upgrade { .. } | + frame_system::Call::authorize_upgrade_without_checks { .. } | + frame_system::Call::kill_prefix { .. }, + ) | RuntimeCall::ParachainSystem(..) | RuntimeCall::Timestamp(..) | RuntimeCall::Balances(..) | RuntimeCall::CollatorSelection( diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index 0a51cf72d5b4..4b930cecd33e 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -172,13 +172,17 @@ impl Contains for SafeCallFilter { matches!( call, - RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) | - RuntimeCall::System( - frame_system::Call::set_heap_pages { .. } | - frame_system::Call::set_code { .. } | - frame_system::Call::set_code_without_checks { .. } | - frame_system::Call::kill_prefix { .. }, - ) | RuntimeCall::ParachainSystem(..) | + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | + pallet_xcm::Call::force_default_xcm_version { .. } + ) | RuntimeCall::System( + frame_system::Call::set_heap_pages { .. } | + frame_system::Call::set_code { .. } | + frame_system::Call::set_code_without_checks { .. } | + frame_system::Call::authorize_upgrade { .. } | + frame_system::Call::authorize_upgrade_without_checks { .. } | + frame_system::Call::kill_prefix { .. }, + ) | RuntimeCall::ParachainSystem(..) | RuntimeCall::Timestamp(..) | RuntimeCall::Balances(..) | RuntimeCall::CollatorSelection( diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e492caddc8fc..ddb58734917c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -79,7 +79,7 @@ use frame_support::{ weights::{ConstantMultiplier, WeightMeter}, PalletId, }; -use frame_system::EnsureRoot; +use frame_system::{EnsureRoot, EnsureSigned}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; use pallet_session::historical as session_historical; @@ -153,7 +153,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("rococo"), impl_name: create_runtime_str!("parity-rococo-v2.0"), authoring_version: 0, - spec_version: 1_006_001, + spec_version: 1_006_002, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 24, @@ -1145,8 +1145,7 @@ impl auctions::Config for Runtime { impl identity_migrator::Config for Runtime { type RuntimeEvent = RuntimeEvent; - // To be changed to `EnsureSigned` once there is a People Chain to migrate to. - type Reaper = EnsureRoot; + type Reaper = EnsureSigned; type ReapIdentityHandler = ToParachainIdentityReaper; type WeightInfo = weights::runtime_common_identity_migrator::WeightInfo; } From 96ce18befa32337007b48c0f072518549019bc7e Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 16 Jan 2024 21:27:50 +0100 Subject: [PATCH 2/5] fix test --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 2902f359dfb5..58bb9504dbd6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -291,7 +291,7 @@ fn assert_reap_id_relay(total_deposit: Balance, id: &Identity) { assert_eq!(reserved_balance, total_deposit); assert_ok!(RococoIdentityMigrator::reap_identity( - RococoOrigin::root(), + RococoOrigin::signed(RococoRelaySender::get()), RococoRelaySender::get() )); From 78b7db7eec1341520da6b2890faa2bad9d13585a Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 17 Jan 2024 08:07:48 +0100 Subject: [PATCH 3/5] fix poke_deposit --- .../runtimes/people/people-rococo/src/lib.rs | 12 +++- substrate/frame/identity/src/lib.rs | 71 +++++++++++-------- substrate/frame/identity/src/tests.rs | 51 +++++++++++++ 3 files changed, 104 insertions(+), 30 deletions(-) diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 81aedc3c5dd1..23e432dc165c 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -30,7 +30,8 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, + ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, EverythingBut, + TransformOrigin, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -161,9 +162,16 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +pub struct IdentityCalls; +impl Contains for IdentityCalls { + fn contains(c: &RuntimeCall) -> bool { + matches!(c, RuntimeCall::Identity(_)) + } +} + #[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = Everything; + type BaseCallFilter = EverythingBut; type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type AccountId = AccountId; diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 1df0a619ea40..384ed274430c 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1377,34 +1377,49 @@ impl Pallet { target: &T::AccountId, ) -> Result<(BalanceOf, BalanceOf), DispatchError> { // Identity Deposit - let new_id_deposit = IdentityOf::::try_mutate( - &target, - |identity_of| -> Result, DispatchError> { - let (reg, _) = identity_of.as_mut().ok_or(Error::::NoIdentity)?; - // Calculate what deposit should be - let encoded_byte_size = reg.info.encoded_size() as u32; - let byte_deposit = - T::ByteDeposit::get().saturating_mul(>::from(encoded_byte_size)); - let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); - - // Update account - Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; - - reg.deposit = new_id_deposit; - Ok(new_id_deposit) - }, - )?; - - // Subs Deposit - let new_subs_deposit = SubsOf::::try_mutate( - &target, - |(current_subs_deposit, subs_of)| -> Result, DispatchError> { - let new_subs_deposit = Self::subs_deposit(subs_of.len() as u32); - Self::rejig_deposit(&target, *current_subs_deposit, new_subs_deposit)?; - *current_subs_deposit = new_subs_deposit; - Ok(new_subs_deposit) - }, - )?; + let has_identity = IdentityOf::::contains_key(&target); + // This should really always be true, but don't insert random storage on the off chance it's + // not. + let new_id_deposit = if has_identity { + IdentityOf::::try_mutate( + &target, + |identity_of| -> Result, DispatchError> { + let (reg, _) = identity_of.as_mut().ok_or(Error::::NoIdentity)?; + // Calculate what deposit should be + let encoded_byte_size = reg.info.encoded_size() as u32; + let byte_deposit = T::ByteDeposit::get() + .saturating_mul(>::from(encoded_byte_size)); + let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); + + // Update account + Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; + + reg.deposit = new_id_deposit; + Ok(new_id_deposit) + }, + )? + } else { + // If the item doesn't exist, there is no "old" deposit, and the new one is zero, so no + // need to call rejig, it'd just be zero -> zero. + Zero::zero() + }; + + let has_subs = SubsOf::::contains_key(&target); + let new_subs_deposit = if has_subs { + SubsOf::::try_mutate( + &target, + |(current_subs_deposit, subs_of)| -> Result, DispatchError> { + let new_subs_deposit = Self::subs_deposit(subs_of.len() as u32); + Self::rejig_deposit(&target, *current_subs_deposit, new_subs_deposit)?; + *current_subs_deposit = new_subs_deposit; + Ok(new_subs_deposit) + }, + )? + } else { + // If the item doesn't exist, there is no "old" deposit, and the new one is zero, so no + // need to call rejig, it'd just be zero -> zero. + Zero::zero() + }; Ok((new_id_deposit, new_subs_deposit)) } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 4da317822611..e6107cda0f00 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -952,6 +952,57 @@ fn poke_deposit_works() { }); } +#[test] +fn poke_deposit_does_not_insert_new_subs_storage() { + new_test_ext().execute_with(|| { + let [_, _, _, _, ten, _, _, _] = accounts(); + let ten_info = infoof_ten(); + // Set a custom registration with 0 deposit + IdentityOf::::insert::< + _, + ( + Registration>, + Option>, + ), + >( + &ten, + ( + Registration { + judgements: Default::default(), + deposit: Zero::zero(), + info: ten_info.clone(), + }, + None::>, + ), + ); + assert!(Identity::identity(ten.clone()).is_some()); + + // Balance is free + assert_eq!(Balances::free_balance(ten.clone()), 1000); + + // poke + assert_ok!(Identity::poke_deposit(&ten)); + + // free balance reduced correctly + let id_deposit = id_deposit(&ten_info); + assert_eq!(Balances::free_balance(ten.clone()), 1000 - id_deposit); + // new registration deposit is 10 + assert_eq!( + Identity::identity(&ten), + Some(( + Registration { + judgements: Default::default(), + deposit: id_deposit, + info: infoof_ten() + }, + None + )) + ); + // No new subs storage item. + assert!(!SubsOf::::contains_key(&ten)); + }); +} + #[test] fn adding_and_removing_authorities_should_work() { new_test_ext().execute_with(|| { From 7eddcf338131829f148e2320511e7064f002041f Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 17 Jan 2024 09:32:13 +0100 Subject: [PATCH 4/5] tidy --- substrate/frame/identity/src/lib.rs | 48 ++++++++++++----------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 384ed274430c..78d59180b3f2 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1377,35 +1377,25 @@ impl Pallet { target: &T::AccountId, ) -> Result<(BalanceOf, BalanceOf), DispatchError> { // Identity Deposit - let has_identity = IdentityOf::::contains_key(&target); - // This should really always be true, but don't insert random storage on the off chance it's - // not. - let new_id_deposit = if has_identity { - IdentityOf::::try_mutate( - &target, - |identity_of| -> Result, DispatchError> { - let (reg, _) = identity_of.as_mut().ok_or(Error::::NoIdentity)?; - // Calculate what deposit should be - let encoded_byte_size = reg.info.encoded_size() as u32; - let byte_deposit = T::ByteDeposit::get() - .saturating_mul(>::from(encoded_byte_size)); - let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); - - // Update account - Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; - - reg.deposit = new_id_deposit; - Ok(new_id_deposit) - }, - )? - } else { - // If the item doesn't exist, there is no "old" deposit, and the new one is zero, so no - // need to call rejig, it'd just be zero -> zero. - Zero::zero() - }; - - let has_subs = SubsOf::::contains_key(&target); - let new_subs_deposit = if has_subs { + let new_id_deposit = IdentityOf::::try_mutate( + &target, + |identity_of| -> Result, DispatchError> { + let (reg, _) = identity_of.as_mut().ok_or(Error::::NoIdentity)?; + // Calculate what deposit should be + let encoded_byte_size = reg.info.encoded_size() as u32; + let byte_deposit = + T::ByteDeposit::get().saturating_mul(>::from(encoded_byte_size)); + let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); + + // Update account + Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; + + reg.deposit = new_id_deposit; + Ok(new_id_deposit) + }, + )?; + + let new_subs_deposit = if SubsOf::::contains_key(&target) { SubsOf::::try_mutate( &target, |(current_subs_deposit, subs_of)| -> Result, DispatchError> { From 0bb69ce45d7fa12760f6ef1107d86e3e4f41d3a4 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 17 Jan 2024 13:14:54 +0100 Subject: [PATCH 5/5] let people use identity --- .../runtimes/people/people-rococo/src/lib.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 23e432dc165c..773b88711396 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -30,8 +30,7 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, EverythingBut, - TransformOrigin, + ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -124,7 +123,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("people-rococo"), impl_name: create_runtime_str!("people-rococo"), authoring_version: 1, - spec_version: 1_006_001, + spec_version: 1_006_002, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 0, @@ -162,16 +161,9 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } -pub struct IdentityCalls; -impl Contains for IdentityCalls { - fn contains(c: &RuntimeCall) -> bool { - matches!(c, RuntimeCall::Identity(_)) - } -} - #[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = EverythingBut; + type BaseCallFilter = Everything; type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type AccountId = AccountId;