Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rococo Identity Migration Part 2 + Bug Fix #2946

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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,
Expand Down
18 changes: 11 additions & 7 deletions cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ impl Contains<RuntimeCall> 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 { .. } |
seadanda marked this conversation as resolved.
Show resolved Hide resolved
frame_system::Call::authorize_upgrade_without_checks { .. } |
frame_system::Call::kill_prefix { .. },
) | RuntimeCall::ParachainSystem(..) |
RuntimeCall::Timestamp(..) |
RuntimeCall::Balances(..) |
RuntimeCall::CollatorSelection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,17 @@ impl Contains<RuntimeCall> 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(
Expand Down
7 changes: 3 additions & 4 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<AccountId>;
type Reaper = EnsureSigned<AccountId>;
type ReapIdentityHandler = ToParachainIdentityReaper<Runtime, Self::AccountId>;
type WeightInfo = weights::runtime_common_identity_migrator::WeightInfo<Runtime>;
}
Expand Down
25 changes: 15 additions & 10 deletions substrate/frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,16 +1395,21 @@ impl<T: Config> Pallet<T> {
},
)?;

// Subs Deposit
let new_subs_deposit = SubsOf::<T>::try_mutate(
&target,
|(current_subs_deposit, subs_of)| -> Result<BalanceOf<T>, 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 new_subs_deposit = if SubsOf::<T>::contains_key(&target) {
SubsOf::<T>::try_mutate(
&target,
|(current_subs_deposit, subs_of)| -> Result<BalanceOf<T>, 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the identity migrator impl, calling Call::poke_deposit with a non existing target will never pay any fees -- is this the expected behaviour? I guess it should be fine since the call is gated by root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is gated by root, and the only use in the impl of reap_identity would return an error if the target did not exist, so it shouldn't end up calling into poke_deposit at all.

};
Ok((new_id_deposit, new_subs_deposit))
}

Expand Down
51 changes: 51 additions & 0 deletions substrate/frame/identity/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::insert::<
_,
(
Registration<u64, MaxRegistrars, IdentityInfo<MaxAdditionalFields>>,
Option<Username<Test>>,
),
>(
&ten,
(
Registration {
judgements: Default::default(),
deposit: Zero::zero(),
info: ten_info.clone(),
},
None::<Username<Test>>,
),
);
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::<Test>::contains_key(&ten));
});
}

#[test]
fn adding_and_removing_authorities_should_work() {
new_test_ext().execute_with(|| {
Expand Down