Skip to content

Commit

Permalink
Add BridgeHubDualMessageRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Dec 5, 2024
1 parent 1befeed commit 27403eb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = bridge_hub_common::BridgeHubMessageRouter<
type MessageProcessor = bridge_hub_common::BridgeHubDualMessageRouter<
xcm_builder::ProcessXcmMessage<
AggregateMessageOrigin,
xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
Expand Down
4 changes: 3 additions & 1 deletion cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,45 @@ impl From<u32> for AggregateMessageOrigin {
}
}

pub struct BridgeHubMessageRouter<XcmpProcessor, SnowbridgeProcessor>(
PhantomData<(XcmpProcessor, SnowbridgeProcessor)>,
)
where
XcmpProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
SnowbridgeProcessor: ProcessMessage<Origin = AggregateMessageOrigin>;
impl<XcmpProcessor, SnowbridgeProcessor> ProcessMessage
for BridgeHubMessageRouter<XcmpProcessor, SnowbridgeProcessor>
where
XcmpProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
SnowbridgeProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
{
type Origin = AggregateMessageOrigin;
fn process_message(
message: &[u8],
origin: Self::Origin,
meter: &mut WeightMeter,
id: &mut [u8; 32],
) -> Result<bool, ProcessMessageError> {
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<XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2>(
pub struct BridgeHubDualMessageRouter<XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2>(
PhantomData<(XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2)>,
)
where
XcmpProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
SnowbridgeProcessor: ProcessMessage<Origin = AggregateMessageOrigin>;

impl<XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2> ProcessMessage
for BridgeHubMessageRouter<XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2>
for BridgeHubDualMessageRouter<XcmpProcessor, SnowbridgeProcessor, SnowbridgeProcessorV2>
where
XcmpProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
SnowbridgeProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
Expand Down

0 comments on commit 27403eb

Please sign in to comment.