diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 23841190d1..f743f2f7df 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -422,9 +422,16 @@ mod tests { pub struct MockExec; impl ExecuteXcm for MockExec { + type Prepared = Weightless; + + fn prepare(message: Xcm<()>) -> Result> { + Err(message) + } + fn execute_xcm_in_credit( _origin: impl Into, message: Xcm, + _hash: XcmHash, weight_limit: Weight, _credit: Weight, ) -> Outcome { @@ -442,6 +449,10 @@ mod tests { TRACE.with(|q| q.borrow_mut().push((message, o.clone()))); o } + + fn charge_fees(_location: impl Into, _fees: MultiAssets) -> XcmResult { + Err(XcmError::Unimplemented) + } } impl Config for Test { diff --git a/pallets/xcmp-queue/Cargo.toml b/pallets/xcmp-queue/Cargo.toml index b9439bb443..d457e322bd 100644 --- a/pallets/xcmp-queue/Cargo.toml +++ b/pallets/xcmp-queue/Cargo.toml @@ -13,6 +13,7 @@ scale-info = { version = "2.0.0", default-features = false, features = ["derive" # Substrate frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -30,7 +31,6 @@ frame-benchmarking = { default-features = false, optional = true, git = "https:/ # Substrate sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } # Polkadot @@ -48,6 +48,7 @@ std = [ "frame-support/std", "frame-system/std", "log/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", "xcm-executor/std", diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 41e055bfdc..03abce5291 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -1079,26 +1079,41 @@ impl XcmpMessageSource for Pallet { /// Xcm sender for sending to a sibling parachain. impl SendXcm for Pallet { - fn send_xcm(dest: impl Into, msg: Xcm<()>) -> SendResult { - let dest = dest.into(); + type Ticket = (ParaId, VersionedXcm<()>); - match &dest { + fn validate( + dest: &mut Option, + msg: &mut Option>, + ) -> SendResult<(ParaId, VersionedXcm<()>)> { + let d = dest.take().ok_or(SendError::MissingArgument)?; + let xcm = msg.take().ok_or(SendError::MissingArgument)?; + + match &d { // An HRMP message for a sibling parachain. MultiLocation { parents: 1, interior: X1(Parachain(id)) } => { - let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg) + let versioned_xcm = T::VersionWrapper::wrap_version(&d, xcm) .map_err(|()| SendError::DestinationUnsupported)?; - let hash = T::Hashing::hash_of(&versioned_xcm); - Self::send_fragment( - (*id).into(), - XcmpMessageFormat::ConcatenatedVersionedXcm, - versioned_xcm, - ) - .map_err(|e| SendError::Transport(<&'static str>::from(e)))?; - Self::deposit_event(Event::XcmpMessageSent(Some(hash))); - Ok(hash) + Ok(((*id).into(), versioned_xcm)) }, // Anything else is unhandled. This includes a message this is meant for us. - _ => Err(SendError::CannotReachDestination(dest, msg)), + _ => { + *dest = Some(d); + Err(SendError::NotApplicable) + } + } + } + + fn deliver((id, xcm): (ParaId, VersionedXcm<()>)) -> Result { + let hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + match Self::send_fragment(id, XcmpMessageFormat::ConcatenatedVersionedXcm, xcm) { + Ok(_) => { + Self::deposit_event(Event::XcmpMessageSent(Some(hash))); + Ok(hash) + } + Err(e) => { + Err(SendError::Transport(<&'static str>::from(e))) + } } } }