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

[Cumulus] Add GeneralKey variant to AggregateMessageOrigin #2338

Closed
Closed
Changes from all commits
Commits
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
34 changes: 29 additions & 5 deletions cumulus/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,37 @@ pub enum AggregateMessageOrigin {
///
/// This is used by the HRMP queue.
Sibling(ParaId),
/// The message came from an abstract origin that can be identified by
/// a 32-byte ID.
///
/// Due to its versatility, this can be used by subsystems other than
/// the DMP and HRMP queue.
///
/// If multiple subsystems want to enqueue messages using this variant,
/// potential conflicts can be prevented by generating keys using the
/// following pattern:
///
/// ```nocompile
/// let key = blake2_256(("subsystem", key).encode());
/// ^^^ Some ID for a subsystem or pallet
/// let origin = AggregateMessageOrigin::GeneralKey(key);
/// ```
GeneralKey([u8; 32]),
}

impl From<AggregateMessageOrigin> for xcm::v3::MultiLocation {
fn from(origin: AggregateMessageOrigin) -> Self {
use AggregateMessageOrigin::*;
match origin {
AggregateMessageOrigin::Here => MultiLocation::here(),
AggregateMessageOrigin::Parent => MultiLocation::parent(),
AggregateMessageOrigin::Sibling(id) =>
MultiLocation::new(1, Junction::Parachain(id.into())),
Here => MultiLocation::here(),
Parent => MultiLocation::parent(),
Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())),
GeneralKey(id) => MultiLocation::new(0, Junction::GeneralKey { length: 32, data: id }),
}
}
}

#[cfg(feature = "runtime-benchmarks")]
#[cfg(any(test, feature = "runtime-benchmarks"))]
impl From<u32> for AggregateMessageOrigin {
fn from(x: u32) -> Self {
match x {
Expand All @@ -115,6 +132,13 @@ impl From<u32> for AggregateMessageOrigin {
}
}

#[cfg(any(test, feature = "runtime-benchmarks"))]
impl From<[u8; 32]> for AggregateMessageOrigin {
fn from(x: [u8; 32]) -> Self {
Self::GeneralKey(x)
}
}

/// Information about an XCMP channel.
pub struct ChannelInfo {
/// The maximum number of messages that can be pending in the channel at once.
Expand Down
Loading