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

Make System Parachains trusted Teleporters #1368

Merged
merged 34 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5992995
migrate cumulus #2842
NachoPal Sep 2, 2023
935a95d
".git/.scripts/commands/fmt/fmt.sh"
Sep 2, 2023
5a3cebf
fix conflicts
NachoPal Sep 4, 2023
a6191b7
".git/.scripts/commands/fmt/fmt.sh"
Sep 4, 2023
0268b19
comments
NachoPal Sep 6, 2023
a888eaa
more comments
NachoPal Sep 7, 2023
478f649
remove dup comments
NachoPal Sep 7, 2023
00fcbae
rework tests
NachoPal Sep 7, 2023
be88eb6
".git/.scripts/commands/fmt/fmt.sh"
Sep 7, 2023
1f1f930
make asset location generic
NachoPal Sep 8, 2023
395d495
".git/.scripts/commands/fmt/fmt.sh"
Sep 8, 2023
ab0ff81
Merge branch 'master' into nacho/make-system-paras-teleporters
joepetrowski Sep 10, 2023
9eb2744
Merge branch 'master' into nacho/make-system-paras-teleporters
joepetrowski Sep 18, 2023
3305a55
fixes
NachoPal Sep 18, 2023
49d31ac
init AuraExt for CollectivesWestend
NachoPal Sep 18, 2023
d8b4b9f
missing header
NachoPal Sep 18, 2023
6945423
update is_system check
NachoPal Sep 20, 2023
4456661
test teleport macro comment
NachoPal Sep 20, 2023
17efd11
add BridgeHubWestend
NachoPal Sep 20, 2023
1fe08f4
Merge branch 'master' into nacho/make-system-paras-teleporters
NachoPal Sep 20, 2023
dfe4f74
".git/.scripts/commands/fmt/fmt.sh"
Sep 20, 2023
abd0a2a
merge master
NachoPal Oct 8, 2023
c358525
Merge branch 'nacho/make-system-paras-teleporters' of github.com:pari…
NachoPal Oct 8, 2023
7f5f6ce
merge master
NachoPal Oct 16, 2023
a111b4b
remove prod runtimes and clean up
NachoPal Oct 16, 2023
0d93435
remove westend colletives & bidge
NachoPal Oct 16, 2023
0e0ca41
fix conflicts
NachoPal Oct 16, 2023
5b3638d
fix conflicts 2
NachoPal Oct 16, 2023
4c1c8e1
fmt
NachoPal Oct 16, 2023
3414a52
fix conflicts 3
NachoPal Oct 16, 2023
ca30c50
fmt
NachoPal Oct 16, 2023
7c40b8c
add asset-hub-rococo to cargo.toml
NachoPal Oct 16, 2023
4c49811
fix
NachoPal Oct 16, 2023
d52181d
address comments
NachoPal Oct 16, 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
54 changes: 33 additions & 21 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ members = [
"cumulus/parachain-template/pallets/template",
"cumulus/parachain-template/runtime",
"cumulus/parachains/common",
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo",
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend",
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/common",
Expand Down
83 changes: 83 additions & 0 deletions cumulus/parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use crate::impls::AccountIdOf;
use core::marker::PhantomData;
use cumulus_primitives_core::{IsSystem, ParaId};
use frame_support::{
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair},
weights::Weight,
Expand Down Expand Up @@ -78,3 +79,85 @@ impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
}
}

/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for ConcreteAssetFromSystem<AssetLocation>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "ConcreteAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
let is_system = match origin {
// The Relay Chain
MultiLocation { parents: 1, interior: Here } => true,
georgepisaltu marked this conversation as resolved.
Show resolved Hide resolved
// System parachain
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
ParaId::from(*id).is_system(),
// Others
_ => false,
};
matches!(asset.id, Concrete(id) if id == AssetLocation::get()) && is_system
}
}

#[cfg(test)]
mod tests {
use frame_support::parameter_types;

use super::{
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
PalletInstance, Parachain, Parent,
};

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
}

#[test]
fn concrete_asset_from_relay_works() {
let expected_asset: MultiAsset = (Parent, 1000000).into();
let expected_origin: MultiLocation = (Parent, Here).into();

assert!(<ConcreteAssetFromSystem<RelayLocation>>::contains(
&expected_asset,
&expected_origin
));
}

#[test]
fn concrete_asset_from_sibling_system_para_fails_for_wrong_asset() {
let unexpected_assets: Vec<MultiAsset> = vec![
(Here, 1000000).into(),
((PalletInstance(50), GeneralIndex(1)), 1000000).into(),
((Parent, Parachain(1000), PalletInstance(50), GeneralIndex(1)), 1000000).into(),
];
let expected_origin: MultiLocation = (Parent, Parachain(1000)).into();

unexpected_assets.iter().for_each(|asset| {
assert!(!<ConcreteAssetFromSystem<RelayLocation>>::contains(asset, &expected_origin));
});
}

#[test]
fn concrete_asset_from_sibling_system_para_works_for_correct_asset() {
// (para_id, expected_result)
let test_data = vec![
(0, true),
(1, true),
(1000, true),
(1999, true),
(2000, false), // Not a System Parachain
(2001, false), // Not a System Parachain
];

let expected_asset: MultiAsset = (Parent, 1000000).into();

for (para_id, expected_result) in test_data {
let origin: MultiLocation = (Parent, Parachain(para_id)).into();
assert_eq!(
expected_result,
<ConcreteAssetFromSystem<RelayLocation>>::contains(&expected_asset, &origin)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "asset-hub-rococo-integration-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
description = "Asset Hub Rococo runtime integration tests with xcm-emulator"
publish = false

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }

# Substrate
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}

# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
integration-tests-common = { path = "../../common", default-features = false}

[features]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"integration-tests-common/runtime-benchmarks",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.

pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, test_parachain_is_trusted_teleporter,
AssetHubRococo, AssetHubRococoPallet, AssetHubRococoSender, BridgeHubRococo,
BridgeHubRococoReceiver,
};
pub use xcm::prelude::*;
pub use xcm_emulator::{assert_expected_events, bx, Chain, Parachain, TestExt};

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.

mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

use crate::*;

#[test]
fn teleport_to_other_system_parachains_works() {
let amount = ASSET_HUB_ROCOCO_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();

test_parachain_is_trusted_teleporter!(
AssetHubRococo, // Origin
vec![BridgeHubRococo], // Destinations
(native_asset, amount)
);
}
Loading
Loading