From 27403eb01a67e324314e17b63f2783eabbff733a Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 5 Dec 2024 21:11:53 +0800 Subject: [PATCH] Add BridgeHubDualMessageRouter --- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 - .../bridge-hubs/bridge-hub-westend/src/lib.rs | 2 +- .../runtimes/bridge-hubs/common/src/lib.rs | 4 ++- .../bridge-hubs/common/src/message_queue.rs | 33 +++++++++++++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) 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 a090d1e9799c..1809d78cf0b6 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 @@ -419,7 +419,6 @@ impl pallet_message_queue::Config for Runtime { RuntimeCall, >, EthereumOutboundQueue, - EthereumOutboundQueue, >; type Size = u32; // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: 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 bf91526ab079..1d837efa7c13 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 @@ -392,7 +392,7 @@ impl pallet_message_queue::Config for Runtime { type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor; #[cfg(not(feature = "runtime-benchmarks"))] - type MessageProcessor = bridge_hub_common::BridgeHubMessageRouter< + type MessageProcessor = bridge_hub_common::BridgeHubDualMessageRouter< xcm_builder::ProcessXcmMessage< AggregateMessageOrigin, xcm_executor::XcmExecutor, diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs index b806b8cdb22d..13585ddf0840 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs @@ -19,4 +19,6 @@ pub mod message_queue; pub mod xcm_version; pub use digest_item::CustomDigestItem; -pub use message_queue::{AggregateMessageOrigin, BridgeHubMessageRouter}; +pub use message_queue::{ + AggregateMessageOrigin, BridgeHubDualMessageRouter, 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 cdc4c741d863..1e6404fcd008 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs @@ -83,8 +83,37 @@ impl From for AggregateMessageOrigin { } } +pub struct BridgeHubMessageRouter( + PhantomData<(XcmpProcessor, SnowbridgeProcessor)>, +) +where + XcmpProcessor: ProcessMessage, + SnowbridgeProcessor: ProcessMessage; +impl ProcessMessage + for BridgeHubMessageRouter +where + XcmpProcessor: ProcessMessage, + SnowbridgeProcessor: ProcessMessage, +{ + type Origin = AggregateMessageOrigin; + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + use AggregateMessageOrigin::*; + match origin { + Here | Parent | Sibling(_) => + XcmpProcessor::process_message(message, origin, meter, id), + Snowbridge(_) => SnowbridgeProcessor::process_message(message, origin, meter, id), + SnowbridgeV2(_) => Err(ProcessMessageError::Unsupported), + } + } +} + /// Routes messages to either the XCMP or Snowbridge processor. -pub struct BridgeHubMessageRouter( +pub struct BridgeHubDualMessageRouter( PhantomData<(XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2)>, ) where @@ -92,7 +121,7 @@ where SnowbridgeProcessor: ProcessMessage; impl ProcessMessage - for BridgeHubMessageRouter + for BridgeHubDualMessageRouter where XcmpProcessor: ProcessMessage, SnowbridgeProcessor: ProcessMessage,