From a7f55a82ede125c02c3d480e413d6ede2376595f Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Tue, 14 Nov 2023 15:08:13 +0200 Subject: [PATCH] add channel-id support --- Cargo.lock | 4 +- .../bridge-hub-rococo/src/tests/snowbridge.rs | 22 +++-- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 7 +- .../bridge-hub-polkadot/src/lib.rs | 7 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 19 ++-- .../bridge-hubs/bridge-hub-westend/src/lib.rs | 8 +- .../runtimes/bridge-hubs/common/src/lib.rs | 2 +- .../bridge-hubs/common/src/message_queue.rs | 99 +------------------ .../src/chain_spec/bridge_hubs.rs | 4 + cumulus/primitives/core/src/lib.rs | 7 ++ 10 files changed, 48 insertions(+), 131 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 656d18e97676..f9c720cdebff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17493,6 +17493,7 @@ dependencies = [ "ethabi-decode", "frame-support", "frame-system", + "hex-literal", "parity-scale-codec", "polkadot-parachain-primitives", "scale-info", @@ -17500,6 +17501,7 @@ dependencies = [ "snowbridge-beacon-primitives", "sp-arithmetic", "sp-core", + "sp-io", "sp-runtime", "sp-std 8.0.0", "staging-xcm", @@ -17587,7 +17589,7 @@ dependencies = [ name = "snowbridge-outbound-queue" version = "0.1.1" dependencies = [ - "bridge-hub-common", + "cumulus-primitives-core", "ethabi-decode", "frame-benchmarking", "frame-support", diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 6dce66c6d256..fa697e5cc240 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -13,9 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. use crate::*; +use codec::Encode; use hex_literal::hex; use integration_tests_common::{AssetHubRococoPallet, BridgeHubRococoPallet}; use snowbridge_control; +use snowbridge_core::outbound::OperatingMode; use snowbridge_router_primitives::inbound::{Command, Destination, MessageV1, VersionedMessage}; use sp_core::H256; @@ -31,10 +33,12 @@ const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EB #[test] fn create_agent() { + let origin_para: u32 = 1001; + BridgeHubRococo::fund_accounts(vec![( BridgeHubRococo::sovereign_account_id_of(MultiLocation { parents: 1, - interior: X1(Parachain(DEST_PARA_ID)), + interior: X1(Parachain(origin_para)), }), INITIAL_FUND, )]); @@ -44,11 +48,11 @@ fn create_agent() { let remote_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - DescendOrigin(X1(Parachain(DEST_PARA_ID))), + DescendOrigin(X1(Parachain(origin_para))), Transact { require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![51, 1].into(), + call: vec![51, 2].into(), }, ])); @@ -91,7 +95,9 @@ fn create_agent() { #[test] fn create_channel() { - let source_location = MultiLocation { parents: 1, interior: X1(Parachain(DEST_PARA_ID)) }; + let origin_para: u32 = 1001; + + let source_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para)) }; BridgeHubRococo::fund_accounts(vec![( BridgeHubRococo::sovereign_account_id_of(source_location), @@ -104,21 +110,21 @@ fn create_channel() { let create_agent_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - DescendOrigin(X1(Parachain(DEST_PARA_ID))), + DescendOrigin(X1(Parachain(origin_para))), Transact { require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![51, 1].into(), + call: vec![51, 2].into(), }, ])); let create_channel_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - DescendOrigin(X1(Parachain(DEST_PARA_ID))), + DescendOrigin(X1(Parachain(origin_para))), Transact { require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![51, 2].into(), + call: ([51u8, 3u8], OperatingMode::Normal, 1u128).encode().into(), }, ])); diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 4d66071d6cfc..ebba4790456c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -41,11 +41,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, -}; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -62,6 +58,7 @@ use frame_system::{ EnsureRoot, }; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{FellowshipLocation, GovernanceLocation, XcmOriginToTransactDispatchOrigin}; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 079b6f18eb65..b7d5da0f1cb7 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -41,11 +41,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, -}; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -62,6 +58,7 @@ use frame_system::{ EnsureRoot, }; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{FellowshipLocation, GovernanceLocation, XcmOriginToTransactDispatchOrigin}; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 308369aad454..82e4bb50d895 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -60,7 +60,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -76,17 +76,14 @@ use frame_system::{ }; use pallet_xcm::EnsureXcm; - +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm::VersionedMultiLocation; use xcm_config::{TreasuryAccount, XcmOriginToTransactDispatchOrigin, XcmRouter}; use bp_runtime::HeaderId; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, BridgeHubMessageRouter, -}; +use bridge_hub_common::BridgeHubMessageRouter; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -404,7 +401,7 @@ impl pallet_message_queue::Config for Runtime { type Size = u32; // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: type QueueChangeHandler = NarrowOriginToSibling; - type QueuePausedQuery = (NarrowOriginToSibling, EthereumOutboundQueue); + type QueuePausedQuery = NarrowOriginToSibling; type HeapSize = sp_core::ConstU32<{ 64 * 1024 }>; type MaxStale = sp_core::ConstU32<8>; type ServiceWeight = MessageQueueServiceWeight; @@ -549,7 +546,7 @@ impl snowbridge_inbound_queue::Config for Runtime { type XcmSender = XcmRouter; #[cfg(feature = "runtime-benchmarks")] type XcmSender = DoNothingRouter; - type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; + type ChannelLookup = EthereumControl; type GatewayAddress = GatewayAddress; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; @@ -562,6 +559,7 @@ impl snowbridge_inbound_queue::Config for Runtime { Balance, >; type WeightToFee = WeightToFee; + type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; } impl snowbridge_outbound_queue::Config for Runtime { @@ -571,7 +569,6 @@ impl snowbridge_outbound_queue::Config for Runtime { type Decimals = ConstU8<12>; type MaxMessagePayloadSize = ConstU32<2048>; type MaxMessagesPerBlock = ConstU32<32>; - type OwnParaId = ParachainInfo; type GasMeter = snowbridge_core::outbound::ConstantGasMeter; type Balance = Balance; type WeightToFee = WeightToFee; @@ -646,9 +643,7 @@ impl snowbridge_control::BenchmarkHelper for () { impl snowbridge_control::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OwnParaId = ParachainInfo; type OutboundQueue = EthereumOutboundQueue; - type MessageHasher = BlakeTwo256; type SiblingOrigin = EnsureXcm; type AgentIdOf = xcm_config::AgentIdOf; type TreasuryAccount = TreasuryAccount; @@ -729,7 +724,7 @@ construct_runtime!( EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Storage, Event} = 60, EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Call, Storage, Event} = 61, EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event} = 62, - EthereumControl: snowbridge_control::{Pallet, Call, Storage, Event} = 63, + EthereumControl: snowbridge_control::{Pallet, Call, Storage, Config, Event} = 63, // Message Queue. Registered after EthereumOutboundQueue so that their `on_initialize` handlers // run in the desired order. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index a115fa37527b..f3bb2660acef 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -32,12 +32,8 @@ pub mod bridge_to_rococo_config; mod weights; pub mod xcm_config; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, -}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use cumulus_primitives_core::ParaId; + use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -52,6 +48,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -65,6 +62,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{XcmOriginToTransactDispatchOrigin, XcmRouter}; diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs index 0ed671ae4f1c..58e6264d1b70 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs @@ -16,4 +16,4 @@ pub mod message_queue; -pub use message_queue::{AggregateMessageOrigin, BridgeHubMessageRouter, SnowbridgeMessageOrigin}; +pub use message_queue::BridgeHubMessageRouter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs b/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs index fbbaa17b5a6f..3d53d985af1d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs @@ -13,76 +13,17 @@ // See the License for the specific language governing permissions and // limitations under the License. //! Runtime configuration for MessageQueue pallet -use codec::{Decode, Encode, MaxEncodedLen}; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ - traits::{ProcessMessage, ProcessMessageError, QueueFootprint, QueuePausedQuery}, + traits::{ProcessMessage, ProcessMessageError}, weights::WeightMeter, }; -use pallet_message_queue::OnQueueChanged; -use scale_info::TypeInfo; -use sp_std::{marker::PhantomData, prelude::*}; -use xcm::v3::{Junction, MultiLocation}; - -/// The aggregate origin of an inbound message. -/// This is specialized for BridgeHub, as the snowbridge-outbound-queue pallet is also using -/// the shared MessageQueue pallet. -#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)] -pub enum AggregateMessageOrigin { - /// The message came from the para-chain itself. - Here, - /// The message came from the relay-chain. - /// - /// This is used by the DMP queue. - Parent, - /// The message came from a sibling para-chain. - /// - /// This is used by the HRMP queue. - Sibling(ParaId), - Snowbridge(SnowbridgeMessageOrigin), -} - -/// The origin of an inbound message for Snowbridge. -#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)] -pub enum SnowbridgeMessageOrigin { - /// The message came from the para-chain itself. - Here, - /// The message came from a sibling para-chain. - Sibling(ParaId), -} - -impl From for MultiLocation { - fn from(origin: AggregateMessageOrigin) -> Self { - use AggregateMessageOrigin::*; - match origin { - Here => MultiLocation::here(), - Parent => MultiLocation::parent(), - Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())), - // NOTE: We don't need this conversion for Snowbridge. However we have to - // implement it anyway as xcm_builder::ProcessXcmMessage requires it. - Snowbridge(_) => MultiLocation::default(), - } - } -} - -#[cfg(feature = "runtime-benchmarks")] -impl From for AggregateMessageOrigin { - fn from(x: u32) -> Self { - match x { - 0 => Self::Here, - 1 => Self::Parent, - p => Self::Sibling(ParaId::from(p)), - } - } -} +use sp_std::marker::PhantomData; /// Routes messages to either the XCMP or Snowbridge processor. pub struct BridgeHubMessageRouter( PhantomData<(XcmpProcessor, SnowbridgeProcessor)>, -) -where - XcmpProcessor: ProcessMessage, - SnowbridgeProcessor: ProcessMessage; +); impl ProcessMessage for BridgeHubMessageRouter @@ -102,37 +43,7 @@ where match origin { Here | Parent | Sibling(_) => XcmpProcessor::process_message(message, origin, meter, id), - Snowbridge(_) => SnowbridgeProcessor::process_message(message, origin, meter, id), - } - } -} - -pub struct NarrowOriginToSibling(PhantomData); -impl> QueuePausedQuery - for NarrowOriginToSibling -{ - fn is_paused(origin: &AggregateMessageOrigin) -> bool { - match origin { - AggregateMessageOrigin::Sibling(id) => Inner::is_paused(id), - _ => false, + GeneralKey(_) => SnowbridgeProcessor::process_message(message, origin, meter, id), } } } - -impl> OnQueueChanged - for NarrowOriginToSibling -{ - fn on_queue_changed(origin: AggregateMessageOrigin, fp: QueueFootprint) { - if let AggregateMessageOrigin::Sibling(id) = origin { - Inner::on_queue_changed(id, fp) - } - } -} - -/// Convert a sibling `ParaId` to an `AggregateMessageOrigin`. -pub struct ParaIdToSibling; -impl sp_runtime::traits::Convert for ParaIdToSibling { - fn convert(para_id: ParaId) -> AggregateMessageOrigin { - AggregateMessageOrigin::Sibling(para_id) - } -} diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 71fb9e5b1404..05a6c48fd7ac 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -328,6 +328,10 @@ pub mod rococo { "bridgeWestendMessages": { "owner": bridges_pallet_owner.clone(), }, + "ethereumControl": { + "paraId": id, + "assetHubParaId": 1000 + } }) } } diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index 835c9de649ea..2f972203ab54 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -91,6 +91,11 @@ pub enum AggregateMessageOrigin { /// /// This is used by the HRMP queue. Sibling(ParaId), + /// The message came from some origin identified by a 32-byte ID. + /// + /// Due to its generality, this is can be used by pallets + /// other than the DMP and HRMP queue. + GeneralKey([u8; 32]), } impl From for xcm::v3::MultiLocation { @@ -100,6 +105,8 @@ impl From for xcm::v3::MultiLocation { AggregateMessageOrigin::Parent => MultiLocation::parent(), AggregateMessageOrigin::Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())), + AggregateMessageOrigin::GeneralKey(id) => + MultiLocation::new(0, Junction::GeneralKey { length: 32, data: id }), } } }