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 4 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
56 changes: 56 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,59 @@ 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 native asset from the system (Relay Chain or system parachain).
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
pub struct ConcreteNativeAssetFromSystem;
impl ContainsPair<MultiAsset, MultiLocation> for ConcreteNativeAssetFromSystem {
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "ConcreteNativeAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
let parent = MultiLocation::parent();
bkontur marked this conversation as resolved.
Show resolved Hide resolved
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)) } if *id < 2000 => true,
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
// Others
_ => false,
};
matches!(asset.id, Concrete(id) if id == parent && is_system)
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[cfg(test)]
mod tests {
use super::{
ConcreteNativeAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
PalletInstance, Parachain, Parent,
};

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

assert!(ConcreteNativeAssetFromSystem::contains(&expected_asset, &expected_origin));
}

#[test]
fn native_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!(!ConcreteNativeAssetFromSystem::contains(asset, &expected_origin));
});
}

#[test]
fn native_asset_from_sibling_system_para_fails_for_wrong_origin() {
bkontur marked this conversation as resolved.
Show resolved Hide resolved
let expected_asset: MultiAsset = (Parent, 1000000).into();
let unexpected_origin: MultiLocation = (Parent, Parachain(2000)).into();

assert!(!ConcreteNativeAssetFromSystem::contains(&expected_asset, &unexpected_origin));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,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 @@ -362,3 +362,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 @@ -26,8 +26,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 @@ -362,3 +362,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,28 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.

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,17 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
NachoPal marked this conversation as resolved.
Show resolved Hide resolved

mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.

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 @@ -28,10 +28,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 @@ -362,3 +362,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 @@ -18,12 +18,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 @@ -15,3 +15,4 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

mod example;
mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.

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)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ pub use frame_support::{assert_ok, sp_runtime::AccountId32};
pub use integration_tests_common::{
constants::{
accounts::ALICE, asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED,
polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
collectives::ED as COLLECTIVES_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, Collectives,
PenpalPolkadotA, Polkadot,
AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, BridgeHubPolkadot,
BridgeHubPolkadotReceiver, CollectivesPolkadot, CollectivesPolkadotPallet,
CollectivesPolkadotSender, PenpalPolkadotA, Polkadot,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ fn pay_salary() {
assert_ok!(<AssetHubAssets as Mutate<_>>::mint_into(asset_id, &pay_from, pay_amount * 2));
});

Collectives::execute_with(|| {
type RuntimeEvent = <Collectives as Chain>::RuntimeEvent;
CollectivesPolkadot::execute_with(|| {
type RuntimeEvent = <CollectivesPolkadot as Chain>::RuntimeEvent;

assert_ok!(FellowshipSalaryPaymaster::pay(&pay_to, (), pay_amount));
assert_expected_events!(
Collectives,
CollectivesPolkadot,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
Expand Down
Loading