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

Remove Identity from Kusama Relay #315

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ccef841
remove identity from kusama relay
joepetrowski May 18, 2024
1f024f9
remove emulated tests
joepetrowski May 18, 2024
abad601
merge main
joepetrowski May 18, 2024
2953271
renames
joepetrowski May 18, 2024
9de5e21
changelog
joepetrowski May 18, 2024
f18365f
remove migrator from people chain
joepetrowski May 19, 2024
f5abded
Merge remote-tracking branch 'origin' into remove-kusama-relay-identity
joepetrowski May 21, 2024
2b582af
changelog
joepetrowski May 21, 2024
f650f28
Update relay/kusama/src/lib.rs
joepetrowski May 22, 2024
2e4c593
Merge branch 'main' into remove-kusama-relay-identity
joepetrowski May 22, 2024
35fef62
change proxy
joepetrowski May 22, 2024
3972f48
Merge branch 'main' into remove-kusama-relay-identity
joepetrowski May 29, 2024
e0d600e
Update CHANGELOG.md
joepetrowski May 30, 2024
3624f68
use codec indices
joepetrowski May 30, 2024
104a046
also remove migrator pallet
joepetrowski May 30, 2024
38482ff
remove pallet from parachain too
joepetrowski May 30, 2024
89a2f5b
judgement proxy migration
liamaharon Jun 2, 2024
6644f4a
clippy
liamaharon Jun 2, 2024
4404b34
remove k/v when proxies is empty
liamaharon Jun 3, 2024
9f070f1
fix: comment
liamaharon Jun 6, 2024
276adc5
Update relay/kusama/src/lib.rs
liamaharon Jun 6, 2024
60294a2
fix: use .min
liamaharon Jun 6, 2024
5ac3c58
debug asset deposit is zero prior to removing proxies
liamaharon Jun 6, 2024
d58802e
merge main
joepetrowski Jun 7, 2024
57566a5
remove benchmark
joepetrowski Jun 7, 2024
40ea467
Merge pull request #4 from liamaharon/liam-proxy-migration
joepetrowski Jun 10, 2024
0a065b6
Update CHANGELOG.md
joepetrowski Jun 11, 2024
df0a4c6
fix changelog
joepetrowski Jun 11, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pallet-fast-unstake = { workspace = true }
frame-executive = { workspace = true }
pallet-grandpa = { workspace = true }
pallet-nis = { workspace = true }
pallet-identity = { workspace = true }
pallet-indices = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-mmr = { workspace = true }
Expand Down Expand Up @@ -152,7 +151,6 @@ std = [
"pallet-election-provider-support-benchmarking?/std",
"pallet-fast-unstake/std",
"pallet-grandpa/std",
"pallet-identity/std",
"pallet-indices/std",
"pallet-message-queue/std",
"pallet-mmr/std",
Expand Down Expand Up @@ -225,7 +223,6 @@ runtime-benchmarks = [
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
Expand Down Expand Up @@ -280,7 +277,6 @@ try-runtime = [
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-identity/try-runtime",
"pallet-indices/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-mmr/try-runtime",
Expand Down
160 changes: 1 addition & 159 deletions relay/kusama/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,167 +16,9 @@

use super::*;
use core::marker::PhantomData;
use frame_support::{
defensive, pallet_prelude::DispatchResult, traits::tokens::ConversionFromAssetBalance,
};
use frame_system::RawOrigin;
use kusama_runtime_constants::system_parachain::PEOPLE_ID;
use parity_scale_codec::{Decode, Encode};
use frame_support::traits::tokens::ConversionFromAssetBalance;
use primitives::Id as ParaId;
use runtime_common::identity_migrator::{OnReapIdentity, WeightInfo};
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::IsChildSystemParachain;
use xcm_executor::traits::TransactAsset;

/// A type containing the encoding of the People Chain pallets in its runtime. Used to construct any
/// remote calls. The codec index must correspond to the index of `IdentityMigrator` in the
/// `construct_runtime` of the remote chain.
#[derive(Encode, Decode)]
enum PeopleRuntimePallets<AccountId: Encode> {
#[codec(index = 248)]
IdentityMigrator(IdentityMigratorCalls<AccountId>),
}

/// Call encoding for the calls needed from the Identity Migrator pallet.
#[derive(Encode, Decode)]
enum IdentityMigratorCalls<AccountId: Encode> {
#[codec(index = 1)]
PokeDeposit(AccountId),
}

/// 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<Runtime, AccountId>(PhantomData<(Runtime, AccountId)>);
impl<Runtime, AccountId> ToParachainIdentityReaper<Runtime, AccountId> {
/// Calculate the balance needed on the remote chain based on the `IdentityInfo` and `Subs` on
/// this chain. The total includes:
///
/// - Identity basic deposit
/// - `IdentityInfo` byte deposit
/// - Sub accounts deposit
/// - 2x existential deposit (1 for account existence, 1 such that the user can transact)
fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance {
// Remote deposit constants. Parachain uses `deposit / 100`
// Source:
// https://github.com/polkadot-fellows/runtimes/blob/55e97c5/system-parachains/constants/src/kusama.rs#L29
//
// Parachain Deposit Configuration:
//
// pub const BasicDeposit: Balance = deposit(1, 17);
// pub const ByteDeposit: Balance = deposit(0, 1);
// pub const SubAccountDeposit: Balance = deposit(1, 53);
// pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
let para_basic_deposit = deposit(1, 17) / 100;
let para_byte_deposit = deposit(0, 1) / 100;
let para_sub_account_deposit = deposit(1, 53) / 100;
let para_existential_deposit = EXISTENTIAL_DEPOSIT / 10;

// pallet deposits
let id_deposit =
para_basic_deposit.saturating_add(para_byte_deposit.saturating_mul(bytes 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))
}
}

// Note / Warning: This implementation should only be used in a transactional context. If not, then
// an error could result in assets being burned.
impl<Runtime, AccountId> OnReapIdentity<AccountId> for ToParachainIdentityReaper<Runtime, AccountId>
where
Runtime: frame_system::Config + pallet_xcm::Config,
AccountId: Into<[u8; 32]> + Clone + Encode,
{
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult {
use crate::{
impls::IdentityMigratorCalls::PokeDeposit,
weights::runtime_common_identity_migrator::WeightInfo as MigratorWeights,
};

let total_to_send = Self::calculate_remote_deposit(fields, subs);

// define asset / destination from relay perspective
let ksm = Asset { id: AssetId(Here.into_location()), fun: Fungible(total_to_send) };
// People Chain
let destination: Location = Location::new(0, Parachain(PEOPLE_ID));

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

// withdraw the asset from `who`
let who_origin =
Junction::AccountId32 { network: None, id: who.clone().into() }.into_location();
let _withdrawn = xcm_config::LocalAssetTransactor::withdraw_asset(&ksm, &who_origin, None)
.map_err(|err| {
defensive!(
"runtime::on_reap_identity: withdraw_asset(what: {:?}, who_origin: {:?}) error: {:?}",
(&ksm, &who_origin, err)
);
pallet_xcm::Error::<Runtime>::LowBalance
})?;

// check out
xcm_config::LocalAssetTransactor::can_check_out(
&destination,
&ksm,
// not used in AssetTransactor
&XcmContext { origin: None, message_id: [0; 32], topic: None },
)
.map_err(|err| {
log::error!(
target: "runtime::on_reap_identity",
"can_check_out(destination: {:?}, asset: {:?}, _) error: {:?}",
destination, ksm, err
);
pallet_xcm::Error::<Runtime>::CannotCheckOutTeleport
})?;
xcm_config::LocalAssetTransactor::check_out(
&destination,
&ksm,
// not used in AssetTransactor
&XcmContext { origin: None, message_id: [0; 32], topic: None },
);

// reanchor
let ksm_reanchored: Assets =
vec![Asset { id: AssetId(Location::new(1, Here)), fun: Fungible(total_to_send) }]
.into();

let poke = PeopleRuntimePallets::<AccountId>::IdentityMigrator(PokeDeposit(who.clone()));
let remote_weight_limit = MigratorWeights::<Runtime>::poke_deposit().saturating_mul(2);

// 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(ksm_reanchored),
// Deposit into the user's account.
DepositAsset {
assets: Wild(AllCounted(1)),
beneficiary: Junction::AccountId32 { network: None, id: who.clone().into() }
.into_location(),
},
// Poke the deposit to reserve the appropriate amount on the parachain.
Transact {
origin_kind: OriginKind::Superuser,
require_weight_at_most: remote_weight_limit,
call: poke.encode().into(),
},
]);

// send
<pallet_xcm::Pallet<Runtime>>::send(
RawOrigin::Root.into(),
Box::new(VersionedLocation::V4(destination)),
Box::new(VersionedXcm::V4(program)),
)?;
Ok(())
}
}

// TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659
/// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without
Expand Down
Loading
Loading