From 6cec5c8912aa1e99615d9d844ab8c57014ec372d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 9 Mar 2022 18:57:24 -0800 Subject: [PATCH] Fixes --- pallets/xcm/src/lib.rs | 6 +++--- primitives/utility/src/lib.rs | 35 +++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pallets/xcm/src/lib.rs b/pallets/xcm/src/lib.rs index 60c5d4b356..4b8432a2ab 100644 --- a/pallets/xcm/src/lib.rs +++ b/pallets/xcm/src/lib.rs @@ -67,13 +67,13 @@ pub mod pallet { pub enum Event { /// Downward message is invalid XCM. /// \[ id \] - InvalidFormat([u8; 8]), + InvalidFormat([u8; 32]), /// Downward message is unsupported version of XCM. /// \[ id \] - UnsupportedVersion([u8; 8]), + UnsupportedVersion([u8; 32]), /// Downward message executed with the given outcome. /// \[ id, outcome \] - ExecutedDownward([u8; 8], Outcome), + ExecutedDownward([u8; 32], Outcome), } /// Origin for the parachains module. diff --git a/primitives/utility/src/lib.rs b/primitives/utility/src/lib.rs index a53e9286fc..0686cd05d8 100644 --- a/primitives/utility/src/lib.rs +++ b/primitives/utility/src/lib.rs @@ -20,7 +20,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::Encode; -use cumulus_primitives_core::UpwardMessageSender; +use cumulus_primitives_core::{MessageSendError, UpwardMessageSender}; use sp_std::marker::PhantomData; use xcm::{latest::prelude::*, WrapVersion}; @@ -33,22 +33,37 @@ use xcm::{latest::prelude::*, WrapVersion}; /// for the `SendXcm` implementation. pub struct ParentAsUmp(PhantomData<(T, W)>); impl SendXcm for ParentAsUmp { - fn send_xcm(dest: impl Into, msg: Xcm<()>) -> SendResult { - let dest = dest.into(); + type Ticket = Vec; - if dest.contains_parents_only(1) { + fn validate( + dest: &mut Option, + msg: &mut Option>, + ) -> SendResult> { + let d = dest.take().ok_or(SendError::MissingArgument)?; + let xcm = msg.take().ok_or(SendError::MissingArgument)?; + + if d.contains_parents_only(1) { // An upward message for the relay chain. let versioned_xcm = - W::wrap_version(&dest, msg).map_err(|()| SendError::DestinationUnsupported)?; + W::wrap_version(&d, msg).map_err(|()| SendError::DestinationUnsupported)?; let data = versioned_xcm.encode(); - let hash = data.using_encoded(sp_io::hashing::blake2_256); - T::send_upward_message(data).map_err(|e| SendError::Transport(e.into()))?; - - Ok(hash) + Ok(data, MultiAssets::new()) } else { + *dest = Some(d.clone()); // Anything else is unhandled. This includes a message this is meant for us. - Err(SendError::CannotReachDestination(dest, msg)) + Err(SendError::NotApplicable(d, xcm)) } } + + fn deliver(blob: Vec) -> Result { + let hash = data.using_encoded(sp_io::hashing::blake2_256); + + T::send_upward_message(data).map_err(|e| match e { + MessageSendError::TooBig => SendError::ExceedsMaxMessageSize, + e => SendError::Transport(e.into()), + })?; + + Ok(hash) + } }