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 16 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
23 changes: 23 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ members = [
"cumulus/parachains/common",
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama",
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot",
"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/collectives/collectives-polkadot",
"cumulus/parachains/integration-tests/emulated/collectives/collectives-westend",
"cumulus/parachains/integration-tests/emulated/common",
"cumulus/parachains/pallets/parachain-info",
"cumulus/parachains/pallets/ping",
Expand Down
82 changes: 82 additions & 0 deletions cumulus/parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,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
// TODO: reuse SystemParachains matcher when https://github.com/paritytech/polkadot-sdk/pull/1234 is merged
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => *id < 2000,
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
// Others
_ => false,
};
matches!(asset.id, Concrete(id) if id == AssetLocation::get() && is_system)
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[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
Expand Up @@ -25,10 +25,12 @@ pub use integration_tests_common::{
asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD,
REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, Kusama,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet,
PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet,
AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender,
BridgeHubKusama, BridgeHubKusamaReceiver, Kusama, KusamaPallet, KusamaReceiver, KusamaSender,
PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB,
PenpalKusamaBPallet,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,16 @@ fn teleport_native_assets_from_relay_to_system_para_works() {
// // Receiver's balance does not change
// assert_eq!(receiver_balance_after, receiver_balance_before);
// }

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

// Works for the right origin and asset
test_parachain_is_trusted_teleporter!(
AssetHubKusama, // Origin
vec![BridgeHubKusama], // Destinations
(expected_asset, amount)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ pub use integration_tests_common::{
asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender,
BridgeHubPolkadot, BridgeHubPolkadotReceiver, CollectivesPolkadot, CollectivesPolkadotReceiver,
PenpalPolkadotA, PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotB,
PenpalPolkadotBPallet, Polkadot, PolkadotPallet, PolkadotReceiver, PolkadotSender,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,15 @@ fn teleport_native_assets_from_relay_to_system_para_works() {
// // Receiver's balance does not change
// assert_eq!(receiver_balance_after, receiver_balance_before);
// }

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

test_parachain_is_trusted_teleporter!(
AssetHubPolkadot, // Origin
vec![CollectivesPolkadot, BridgeHubPolkadot], // Destinations
(native_asset, amount)
);
}
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,27 @@
// 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_polkadot::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)]
#[cfg(not(feature = "runtime-benchmarks"))]
Copy link
Member

Choose a reason for hiding this comment

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

why doesn't it work with runtime-benchmarks feature? AFAIK, we only run tests with the feature enabled in CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing, it wasn't like that before: #1335

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)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ pub use integration_tests_common::{
asset_hub_westend::ED as ASSET_HUB_WESTEND_ED, westend::ED as WESTEND_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender,
PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend,
WestendPallet, WestendReceiver, WestendSender,
CollectivesWestend, CollectivesWestendReceiver, PenpalWestendA, PenpalWestendAPallet,
PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendPallet, WestendReceiver,
WestendSender,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,15 @@ fn teleport_native_assets_from_relay_to_system_para_works() {
// // Receiver's balance does not change
// assert_eq!(receiver_balance_after, receiver_balance_before);
// }

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

test_parachain_is_trusted_teleporter!(
AssetHubWestend, // Origin
vec![CollectivesWestend], // Destinations
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
(native_asset, amount)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ pub use bp_messages::LaneId;
pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::{
asset_hub_kusama::ED as ASSET_HUB_ROCOCO_ED, kusama::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD,
REF_TIME_THRESHOLD, XCM_V3,
asset_hub_kusama::ED as ASSET_HUB_ROCOCO_ED, bridge_hub_rococo::ED as BRIDGE_HUB_ROCOCO_ED,
kusama::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubRococo, AssetHubRococoReceiver, AssetHubWococo, BridgeHubRococo, BridgeHubWococo,
PenpalRococoA, Rococo, RococoPallet,
AssetHubRococo, AssetHubRococoReceiver, AssetHubWococo, BridgeHubPolkadot,
BridgeHubPolkadotReceiver, BridgeHubRococo, BridgeHubRococoPallet, BridgeHubRococoSender,
BridgeHubWococo, CollectivesPolkadot, CollectivesPolkadotReceiver, PenpalRococoA, Rococo,
RococoPallet,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
// limitations under the License.

mod example;
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 = BRIDGE_HUB_ROCOCO_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();

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