From c86026053d135d28d6efa794a37e0288b240917a Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 25 Dec 2023 11:10:21 +0300 Subject: [PATCH 1/2] added with-RococoBulletin bridging support to Rococo People --- Cargo.lock | 2 + .../runtimes/people/people-rococo/Cargo.toml | 7 ++ .../people/people-rococo/src/xcm_config.rs | 118 +++++++++++++++++- 3 files changed, 122 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f56868d72d24..3ddc34f00d82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11725,6 +11725,7 @@ dependencies = [ name = "people-rococo-runtime" version = "0.1.0" dependencies = [ + "bp-bridge-hub-rococo", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -11758,6 +11759,7 @@ dependencies = [ "pallet-xcm", "pallet-xcm-benchmarks", "parachains-common", + "parachains-runtimes-test-utils", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain-primitives", diff --git a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml index 81f6ed936c89..ef5033714f06 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml @@ -75,9 +75,16 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d parachain-info = { package = "staging-parachain-info", path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +# Bridges +bp-bridge-hub-rococo = { path = "../../../../../bridges/primitives/chain-bridge-hub-rococo", default-features = false } + +[dev-dependencies] +parachains-runtimes-test-utils = { path = "../../test-utils" } + [features] default = ["std"] std = [ + "bp-bridge-hub-rococo/std", "codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 7a2f28aa813e..09c38657ad88 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -208,8 +208,12 @@ pub type Barrier = TrailingSetTopicAsId< // If the message is one that immediately attemps to pay for execution, then // allow it. AllowTopLevelPaidExecutionFrom, - // Parent and its pluralities (i.e. governance bodies) get free execution. - AllowExplicitUnpaidExecutionFrom, + // Parent and its pluralities (i.e. governance bodies) + sibling bridge hub get + // free execution. + AllowExplicitUnpaidExecutionFrom<( + ParentOrParentsPlurality, + Equals, + )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), @@ -262,7 +266,7 @@ impl xcm_executor::Config for XcmConfig { XcmFeeToAccount, >; type MessageExporter = (); - type UniversalAliases = Nothing; + type UniversalAliases = (bridging::UniversalAliases,); type CallDispatcher = WithOriginFilter; type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; @@ -275,10 +279,12 @@ pub type LocalOriginToLocation = SignedToAccountId32, - // ..and XCMP to communicate with the sibling chains. + // Use XCMP to communicate with the sibling chains: XcmpQueue, + // Use XCMP with sibling bridge hub to communicate with Rococo Bulletin chain. + bridging::ToBulletinXcmRouter, )>; impl pallet_xcm::Config for Runtime { @@ -318,3 +324,105 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + +/// All configuration related to bridging +pub mod bridging { + use super::*; + use sp_std::collections::btree_set::BTreeSet; + use xcm_builder::{NetworkExportTableItem, UnpaidRemoteExporter}; + + parameter_types! { + /// Location of the sibling bridge hub. + pub SiblingBridgeHub: MultiLocation = MultiLocation::new( + 1, + X1(Parachain(bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID)), + ); + + + /// Location of the with-Bulletin messaging pallet at the sibling bridge hub. + pub SiblingBridgeHubWithRococoBulletinInstance: MultiLocation = MultiLocation::new( + 1, + X2( + Parachain(bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID), + PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX) + ) + ); + + /// Rococo Bulletin network (which is a slightly modified `PolkadotBulletin`). + pub const RococoBulletinNetwork: NetworkId = NetworkId::PolkadotBulletin; + + /// Set up exporters configuration. + pub BridgeTable: sp_std::vec::Vec = sp_std::vec![ + NetworkExportTableItem::new( + RococoBulletinNetwork::get(), + None, + SiblingBridgeHub::get(), + None, + ) + ]; + + /// Universal aliases + pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter( + sp_std::vec![ + (SiblingBridgeHubWithRococoBulletinInstance::get(), GlobalConsensus(RococoBulletinNetwork::get())) + ] + ); + } + + impl Contains<(MultiLocation, Junction)> for UniversalAliases { + fn contains(alias: &(MultiLocation, Junction)) -> bool { + UniversalAliases::get().contains(alias) + } + } + + pub type NetworkExportTable = xcm_builder::NetworkExportTable; + + pub type ToBulletinXcmRouter = + UnpaidRemoteExporter; +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{AuraId, SessionKeys}; + use frame_support::assert_ok; + use parachains_runtimes_test_utils::ExtBuilder; + use sp_std::vec; + + const ALICE: [u8; 32] = [1u8; 32]; + + #[test] + fn can_send_messages_to_rococo_bulletin() { + ExtBuilder::::default() + .with_collators(vec![AccountId::from(ALICE)]) + .with_session_keys(vec![( + AccountId::from(ALICE), + AccountId::from(ALICE), + SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, + )]) + .build() + .execute_with(|| { + let destination = MultiLocation::new( + 2, + X1(GlobalConsensus(bridging::RococoBulletinNetwork::get())), + ); + + assert_ok!(PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(bridging::SiblingBridgeHub::get()), + xcm::latest::VERSION + )); + assert_ok!(PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(destination), + xcm::latest::VERSION + )); + + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests( + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID.into(), + ); + + assert_ok!(send_xcm::(destination, vec![ClearOrigin].into())); + }); + } +} From cd13e8d3adb026a849aea29c5f6b82195d269cb4 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 25 Dec 2023 11:38:05 +0300 Subject: [PATCH 2/2] remove unneeded code --- .../runtimes/people/people-rococo/src/xcm_config.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 09c38657ad88..9dffec3b1414 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -412,11 +412,6 @@ mod tests { Box::new(bridging::SiblingBridgeHub::get()), xcm::latest::VERSION )); - assert_ok!(PolkadotXcm::force_xcm_version( - RuntimeOrigin::root(), - Box::new(destination), - xcm::latest::VERSION - )); ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests( bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID.into(),