-
Notifications
You must be signed in to change notification settings - Fork 709
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
Reduce Impact on Identity Pallet in Migration #2088
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! This pallet is designed to go into a source chain and destination chain to migrate data. The | ||
//! design motivations are: | ||
//! | ||
//! - Call some function on the source chain that executes some migration (clearing state, | ||
//! forwarding an XCM program). | ||
//! - Call some function (probably from an XCM program) on the destination chain. | ||
//! - Avoid cluttering the source pallet with new dispatchables that are unrelated to its | ||
//! functionality and only used for migration. | ||
//! | ||
//! After the migration is complete, the pallet may be removed from both chains' runtimes. | ||
|
||
use frame_support::{dispatch::DispatchResult, traits::Currency}; | ||
pub use pallet::*; | ||
use pallet_identity::{self, WeightInfo}; | ||
use sp_core::Get; | ||
|
||
type BalanceOf<T> = <<T as pallet_identity::Config>::Currency as Currency< | ||
<T as frame_system::Config>::AccountId, | ||
>>::Balance; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::{ | ||
dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, | ||
pallet_prelude::*, | ||
traits::EnsureOrigin, | ||
}; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config + pallet_identity::Config { | ||
/// Overarching event type. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The origin that can reap identities. Expected to be `EnsureSigned<AccountId>` on the | ||
/// source chain such that anyone can all this function. | ||
type Reaper: EnsureOrigin<Self::RuntimeOrigin>; | ||
|
||
/// A handler for what to do when an identity is reaped. | ||
type ReapIdentityHandler: OnReapIdentity<Self::AccountId>; | ||
|
||
/// Weight information for the extrinsics in the pallet. | ||
type WeightInfo: pallet_identity::WeightInfo; | ||
} | ||
|
||
#[pallet::event] | ||
#[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
/// The identity and all sub accounts were reaped for `who`. | ||
IdentityReaped { who: T::AccountId }, | ||
/// The deposits held for `who` were updated. `identity` is the new deposit held for | ||
/// identity info, and `subs` is the new deposit held for the sub-accounts. | ||
DepositUpdated { who: T::AccountId, identity: BalanceOf<T>, subs: BalanceOf<T> }, | ||
} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
/// Reap the Identity Info of `who` from the Relay Chain, unreserving any deposits held and | ||
/// removing storage items associated with `who`. | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(<T as pallet::Config>::WeightInfo::reap_identity( | ||
T::MaxRegistrars::get(), | ||
T::MaxSubAccounts::get() | ||
))] | ||
pub fn reap_identity( | ||
origin: OriginFor<T>, | ||
who: T::AccountId, | ||
) -> DispatchResultWithPostInfo { | ||
T::Reaper::ensure_origin(origin)?; | ||
let (registrars, fields, subs) = pallet_identity::Pallet::<T>::reap_identity(&who)?; | ||
T::ReapIdentityHandler::on_reap_identity(&who, fields, subs)?; | ||
Self::deposit_event(Event::IdentityReaped { who }); | ||
let post = PostDispatchInfo { | ||
actual_weight: Some(<T as pallet::Config>::WeightInfo::reap_identity( | ||
registrars, subs, | ||
)), | ||
pays_fee: Pays::No, | ||
}; | ||
Ok(post) | ||
} | ||
|
||
/// Update the deposit of `who`. Meant to be called by the system with an XCM `Transact` | ||
/// Instruction. | ||
#[pallet::call_index(1)] | ||
#[pallet::weight(<T as pallet::Config>::WeightInfo::poke_deposit())] | ||
pub fn poke_deposit(origin: OriginFor<T>, who: T::AccountId) -> DispatchResultWithPostInfo { | ||
ensure_root(origin)?; | ||
let (id_deposit, subs_deposit) = pallet_identity::Pallet::<T>::poke_deposit(&who)?; | ||
Self::deposit_event(Event::DepositUpdated { | ||
who, | ||
identity: id_deposit, | ||
subs: subs_deposit, | ||
}); | ||
Ok(Pays::No.into()) | ||
} | ||
} | ||
} | ||
|
||
/// Trait to handle reaping identity from state. | ||
pub trait OnReapIdentity<AccountId> { | ||
/// What to do when an identity is reaped. For example, the implementation could send an XCM | ||
/// program to another chain. Concretely, a type implementing this trait in the Polkadot | ||
/// runtime would teleport enough DOT to the People Chain to cover the Identity deposit there. | ||
/// | ||
/// This could also directly include `Transact { poke_deposit(..), ..}`. | ||
/// | ||
/// Inputs | ||
/// - `who`: Whose identity was reaped. | ||
/// - `fields`: The number of `additional_fields` they had. | ||
/// - `subs`: The number of sub-accounts they had. | ||
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult; | ||
} | ||
|
||
impl<AccountId> OnReapIdentity<AccountId> for () { | ||
fn on_reap_identity(_who: &AccountId, _fields: u32, _subs: u32) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,10 @@ | |
use crate::xcm_config; | ||
use frame_support::pallet_prelude::DispatchResult; | ||
use frame_system::RawOrigin; | ||
use pallet_identity::OnReapIdentity; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use primitives::Balance; | ||
use rococo_runtime_constants::currency::*; | ||
use runtime_common::identity_migrator::OnReapIdentity; | ||
use sp_std::{marker::PhantomData, prelude::*}; | ||
use xcm::{latest::prelude::*, VersionedMultiLocation, VersionedXcm}; | ||
use xcm_executor::traits::TransactAsset; | ||
|
@@ -29,14 +29,14 @@ use xcm_executor::traits::TransactAsset; | |
/// remote calls. | ||
#[derive(Encode, Decode)] | ||
enum PeopleRuntimePallets<AccountId: Encode> { | ||
#[codec(index = 50)] | ||
Identity(IdentityCalls<AccountId>), | ||
#[codec(index = 248)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this references the index on the relay chain now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, definitely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably should use |
||
IdentityMigrator(IdentityMigratorCalls<AccountId>), | ||
} | ||
|
||
/// Call encoding for the calls needed from the Identity pallet. | ||
#[derive(Encode, Decode)] | ||
enum IdentityCalls<AccountId: Encode> { | ||
#[codec(index = 16)] | ||
enum IdentityMigratorCalls<AccountId: Encode> { | ||
#[codec(index = 1)] | ||
PokeDeposit(AccountId), | ||
} | ||
|
||
|
@@ -78,7 +78,7 @@ where | |
AccountId: Into<[u8; 32]> + Clone + Encode, | ||
{ | ||
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult { | ||
use crate::impls::IdentityCalls::PokeDeposit; | ||
use crate::impls::IdentityMigratorCalls::PokeDeposit; | ||
|
||
let total_to_send = Self::calculate_remote_deposit(fields, subs); | ||
|
||
|
@@ -114,7 +114,7 @@ where | |
}] | ||
.into(); | ||
|
||
let poke = PeopleRuntimePallets::<AccountId>::Identity(PokeDeposit(who.clone())); | ||
let poke = PeopleRuntimePallets::<AccountId>::IdentityMigrator(PokeDeposit(who.clone())); | ||
|
||
// Actual program to execute on People Chain. | ||
let program: Xcm<()> = Xcm(vec![ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fields should not be required anymore after @georgepisaltu pr. So, you can also directly remove it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I will address any downstream changes. My PR is still more a proposal on how to do the migration. George's should definitely be merged first.