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

Identity Deposits Relay to Parachain Migration #1814

Merged
merged 50 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
20fa029
add migration extrinsics to identity
joepetrowski Oct 6, 2023
7becd9e
add to runtimes
joepetrowski Oct 6, 2023
fd39b82
adjust trait
joepetrowski Oct 6, 2023
24b9d0d
Add OnReapIdentity implementation for Relay Chain
joepetrowski Oct 7, 2023
96b2add
add license
joepetrowski Oct 9, 2023
54d15a1
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Oct 9, 2023
f9ac75e
add ability to lock and unlock pallet
joepetrowski Oct 10, 2023
4f45cc8
address most of review comments
joepetrowski Oct 10, 2023
64acbb9
Merge branch 'joe-identity-deposit-migration' of https://github.com/p…
joepetrowski Oct 10, 2023
0b3708e
fix alliance test config
joepetrowski Oct 10, 2023
7ae9df0
benchmark reap_identity properly
joepetrowski Oct 11, 2023
b517c91
put deposit info into separate function
joepetrowski Oct 11, 2023
f6e8220
merge master
joepetrowski Oct 11, 2023
c4b45d7
update benchmarks to v2
joepetrowski Oct 11, 2023
cff4f4c
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Oct 11, 2023
776910c
test that correct functions get locked
joepetrowski Oct 14, 2023
c2eb330
Merge remote-tracking branch 'origin' into joe-identity-deposit-migra…
joepetrowski Oct 17, 2023
88a9923
no need to filter with pallet lock
joepetrowski Oct 17, 2023
67de971
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Oct 23, 2023
a46e4ef
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Oct 24, 2023
390ce01
fix compile errors on merge
joepetrowski Oct 24, 2023
9da0726
add poke call encoding to handler impl
joepetrowski Oct 25, 2023
255893d
don't need RuntimeDebug
joepetrowski Oct 25, 2023
298931a
Reduce Impact on Identity Pallet in Migration (#2088)
joepetrowski Oct 31, 2023
cd08c4f
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Nov 3, 2023
1f03941
merge master
joepetrowski Nov 3, 2023
8e70450
actually merge master
joepetrowski Nov 3, 2023
4aaa862
update identity pallet
joepetrowski Nov 3, 2023
70f708b
migrator updates
joepetrowski Nov 3, 2023
e56874c
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Nov 5, 2023
180352d
reap benchmark
joepetrowski Nov 5, 2023
9bf6499
remove migration benchmarks from pallet_identity
joepetrowski Nov 6, 2023
48a33d6
add to define_benchmarks
joepetrowski Nov 6, 2023
750c440
fix runtime errors
joepetrowski Nov 7, 2023
11e2999
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Nov 7, 2023
0030969
remove pallet lock leftovers
joepetrowski Nov 7, 2023
ed0d8e9
disable calls to identity (again)
joepetrowski Nov 7, 2023
cb7bda0
fix benchmark test suite
joepetrowski Nov 7, 2023
76258be
make unused imports happy
joepetrowski Nov 7, 2023
ace6f41
correct and clarify some docs
joepetrowski Nov 9, 2023
de3e4e8
nits
joepetrowski Nov 11, 2023
be38015
add westend config
joepetrowski Nov 11, 2023
1c670b7
fmt
joepetrowski Nov 11, 2023
836f824
set deposits for parachains
joepetrowski Nov 14, 2023
d698705
replace accidentally deleted docs
joepetrowski Nov 14, 2023
ea5d6a3
use benchmarked weight
joepetrowski Nov 15, 2023
f5df158
Merge remote-tracking branch 'origin' into joe-identity-deposit-migra…
joepetrowski Nov 15, 2023
bf42286
new xcm errors
joepetrowski Nov 15, 2023
73426e7
apply basti review
joepetrowski Nov 15, 2023
f18914f
Merge branch 'master' into joe-identity-deposit-migration
joepetrowski Nov 15, 2023
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
130 changes: 130 additions & 0 deletions polkadot/runtime/rococo/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::xcm_config;
use frame_support::pallet_prelude::DispatchResult;
use frame_system::RawOrigin;
use pallet_identity::OnReapIdentity;
use primitives::Balance;
use rococo_runtime_constants::currency::*;
use sp_std::{marker::PhantomData, prelude::*};
use xcm::{latest::prelude::*, /* v2::OriginKind, */ VersionedMultiLocation, VersionedXcm};
use xcm_executor::traits::TransactAsset;

/// Type that implements `OnReapIdentity` that will send the deposit needed to store the same
/// information on a parachain, sends the deposit there, and then updates it.
pub struct ToParachainIdentityReaper<T>(PhantomData<T>);
impl<T> ToParachainIdentityReaper<T> {
/// Calculate the balance needed on the remote chain based on the `IdentityInfo` and `Subs` on
/// this chain. The total includes:
///
/// - Identity basic deposit
/// - Extra fields deposit
/// - Sub accounts deposit
/// - 2x existential deposit (1 for account existence, 1 such that the user can transact)
///
/// This implementation is speculative and subject to change based on the remote chain's
/// configuration.
fn calculate_remote_deposit(fields: u32, subs: u32) -> Balance {
// remote deposit constants
let para_basic_deposit = 1000 * CENTS / 100;
let para_field_deposit = 250 * CENTS / 100;
let para_sub_account_deposit = 200 * CENTS / 100;
let para_existential_deposit = EXISTENTIAL_DEPOSIT / 10;
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved

// pallet deposits
let id_deposit =
para_basic_deposit.saturating_add(para_field_deposit.saturating_mul(fields as Balance));
let subs_deposit = para_sub_account_deposit.saturating_mul(subs as Balance);

id_deposit
.saturating_add(subs_deposit)
.saturating_add(para_existential_deposit.saturating_mul(2))
}
}

impl<AccountId, T> OnReapIdentity<AccountId> for ToParachainIdentityReaper<T>
where
T: frame_system::Config + pallet_xcm::Config,
AccountId: Into<[u8; 32]> + Clone,
{
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult {
let total_to_send = Self::calculate_remote_deposit(fields, subs);

// define asset / destination from relay perspective
let roc: MultiAssets =
vec![MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(total_to_send) }]
.into();
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
// todo: people chain para id
let destination: MultiLocation = MultiLocation::new(0, Parachain(1000));

// Do `check_out` accounting since the XCM Executor's `InitiateTeleport` doesn't support
// unpaid teleports.

// check out
xcm_config::LocalAssetTransactor::can_check_out(
&destination,
&roc.inner().first().unwrap(), // <- safe unwrap since we just set `roc`.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
// not used in AssetTransactor
&XcmContext { origin: None, message_id: [0; 32], topic: None },
)
.map_err(|_| pallet_xcm::Error::<T>::InvalidAsset)?;
xcm_config::LocalAssetTransactor::check_out(
&destination,
&roc.inner().first().unwrap(), // <- safe unwrap since we just set `roc`.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
// not used in AssetTransactor
&XcmContext { origin: None, message_id: [0; 32], topic: None },
);

// reanchor
let roc_reanchored: MultiAssets = vec![MultiAsset {
id: Concrete(MultiLocation::new(1, Here)),
fun: Fungible(total_to_send),
}]
.into();

// Actual program to execute on People Chain.
let program: Xcm<()> = Xcm(vec![
// Unpaid as this is constructed by the system, once per user. The user shouldn't have
// their balance reduced by teleport fees for the favor of migrating.
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
// Receive the asset into holding.
ReceiveTeleportedAsset(roc_reanchored),
// Deposit into the user's account.
DepositAsset {
assets: Wild(AllCounted(1)),
beneficiary: Junction::AccountId32 { network: None, id: who.clone().into() }
.into_location()
.into(),
},
// // Poke the deposit to reserve the appropriate amount on the parachain.
// Transact {
// origin_kind: OriginKind::Superuser,
// require_weight_at_most: Weight {ref_time: 2_000_000_000, proof_size: 16_384},
// // Need People Chain runtime to encode call.
// call: DoubleEncoded { encoded: /* pallet_identity::poke_deposit(who) */ },
// },
]);

// send
let _ = <pallet_xcm::Pallet<T>>::send(
RawOrigin::Root.into(),
Box::new(VersionedMultiLocation::V3(destination)),
Box::new(VersionedXcm::V3(program)),
)?;
Ok(())
}
}
9 changes: 9 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ mod weights;
// XCM configurations.
pub mod xcm_config;

// Implemented types.
mod impls;
use impls::ToParachainIdentityReaper;

// Governance and configurations.
pub mod governance;
use governance::{
Expand Down Expand Up @@ -616,6 +620,11 @@ impl pallet_identity::Config for Runtime {
type Slashed = Treasury;
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type RegistrarOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
// Should be `EnsureRoot` until the parachain launches with Identity state. Then, it will be
// `EnsureSigned<Self::AccountId>` to allow deposit migration.
type ReapOrigin = EnsureRoot<Self::AccountId>;
type ReapIdentityHandler = ToParachainIdentityReaper<Runtime>;
type LockerOrigin = EnsureRoot<Self::AccountId>;
type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
}

Expand Down
73 changes: 73 additions & 0 deletions polkadot/runtime/rococo/src/weights/pallet_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,77 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Identity::IdentityOf` (r:1 w:1)
/// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`)
/// Storage: `Identity::SubsOf` (r:1 w:1)
/// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0)
/// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `XcmPallet::SupportedVersion` (r:1 w:0)
/// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1)
/// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1)
/// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Identity::SuperOf` (r:0 w:100)
/// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`)
/// The range of component `s` is `[0, 100]`.
/// The range of component `r` is `[0, 20]`.
fn reap_identity(s: u32, r: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `882 + r * (5 ±0) + s * (32 ±0)`
// Estimated: `11003 + r * (8 ±1) + s * (33 ±0)`
// Minimum execution time: 890_684_000 picoseconds.
Weight::from_parts(985_014_414, 0)
.saturating_add(Weight::from_parts(0, 11003))
// Standard Error: 512_018
.saturating_add(Weight::from_parts(14_124_295, 0).saturating_mul(s.into()))
// Standard Error: 2_560_094
.saturating_add(Weight::from_parts(219_854, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().writes(5))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into())))
.saturating_add(Weight::from_parts(0, 8).saturating_mul(r.into()))
.saturating_add(Weight::from_parts(0, 33).saturating_mul(s.into()))
}
/// Storage: `Identity::IdentityOf` (r:1 w:1)
/// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Identity::SubsOf` (r:1 w:1)
/// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`)
fn poke_deposit() -> Weight {
// Proof Size summary in bytes:
// Measured: `628`
// Estimated: `11003`
// Minimum execution time: 525_039_000 picoseconds.
Weight::from_parts(554_552_000, 0)
.saturating_add(Weight::from_parts(0, 11003))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Identity::Locked` (r:0 w:1)
/// Proof: `Identity::Locked` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn lock_pallet() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 43_286_000 picoseconds.
Weight::from_parts(51_523_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Identity::Locked` (r:0 w:1)
/// Proof: `Identity::Locked` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn unlock_pallet() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 42_243_000 picoseconds.
Weight::from_parts(52_907_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
}
3 changes: 3 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ impl pallet_identity::Config for Runtime {
type MaxRegistrars = MaxRegistrars;
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type RegistrarOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type ReapOrigin = EnsureRoot<Self::AccountId>;
type ReapIdentityHandler = ();
type LockerOrigin = EnsureRoot<Self::AccountId>;
type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
}

Expand Down
73 changes: 73 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,77 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Identity::IdentityOf` (r:1 w:1)
/// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`)
/// Storage: `Identity::SubsOf` (r:1 w:1)
/// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0)
/// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `XcmPallet::SupportedVersion` (r:1 w:0)
/// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1)
/// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1)
/// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Identity::SuperOf` (r:0 w:100)
/// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`)
/// The range of component `s` is `[0, 100]`.
/// The range of component `r` is `[0, 20]`.
fn reap_identity(s: u32, r: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `882 + r * (5 ±0) + s * (32 ±0)`
// Estimated: `11003 + r * (8 ±1) + s * (33 ±0)`
// Minimum execution time: 890_684_000 picoseconds.
Weight::from_parts(985_014_414, 0)
.saturating_add(Weight::from_parts(0, 11003))
// Standard Error: 512_018
.saturating_add(Weight::from_parts(14_124_295, 0).saturating_mul(s.into()))
// Standard Error: 2_560_094
.saturating_add(Weight::from_parts(219_854, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().writes(5))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into())))
.saturating_add(Weight::from_parts(0, 8).saturating_mul(r.into()))
.saturating_add(Weight::from_parts(0, 33).saturating_mul(s.into()))
}
/// Storage: `Identity::IdentityOf` (r:1 w:1)
/// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Identity::SubsOf` (r:1 w:1)
/// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`)
fn poke_deposit() -> Weight {
// Proof Size summary in bytes:
// Measured: `628`
// Estimated: `11003`
// Minimum execution time: 525_039_000 picoseconds.
Weight::from_parts(554_552_000, 0)
.saturating_add(Weight::from_parts(0, 11003))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `Identity::Locked` (r:0 w:1)
/// Proof: `Identity::Locked` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn lock_pallet() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 43_286_000 picoseconds.
Weight::from_parts(51_523_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `Identity::Locked` (r:0 w:1)
/// Proof: `Identity::Locked` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn unlock_pallet() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 42_243_000 picoseconds.
Weight::from_parts(52_907_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
}
3 changes: 3 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,9 @@ impl pallet_identity::Config for Runtime {
type Slashed = Treasury;
type ForceOrigin = EnsureRootOrHalfCouncil;
type RegistrarOrigin = EnsureRootOrHalfCouncil;
type ReapOrigin = EnsureRoot<Self::AccountId>;
type ReapIdentityHandler = ();
type LockerOrigin = EnsureRoot<Self::AccountId>;
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
}

Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ impl pallet_identity::Config for Test {
type MaxRegistrars = MaxRegistrars;
type Slashed = ();
type RegistrarOrigin = EnsureOneOrRoot;
type ReapOrigin = EnsureOneOrRoot;
type ReapIdentityHandler = ();
type ForceOrigin = EnsureTwoOrRoot;
type LockerOrigin = EnsureTwoOrRoot;
type WeightInfo = ();
}

Expand Down
Loading
Loading