diff --git a/runtime/common/src/paras_sudo_wrapper.rs b/runtime/common/src/paras_sudo_wrapper.rs index 19245ac873d1..c6b1817f0ada 100644 --- a/runtime/common/src/paras_sudo_wrapper.rs +++ b/runtime/common/src/paras_sudo_wrapper.rs @@ -16,22 +16,32 @@ //! A simple wrapper allowing `Sudo` to call into `paras` routines. +use sp_std::prelude::*; use frame_support::{ - decl_error, decl_module, + decl_error, decl_module, ensure, dispatch::DispatchResult, weights::DispatchClass, }; use frame_system::ensure_root; use runtime_parachains::{ - dmp, ump, hrmp, paras::{self, ParaGenesisArgs}, + configuration, dmp, ump, hrmp, paras::{self, ParaGenesisArgs}, }; use primitives::v1::Id as ParaId; /// The module's configuration trait. -pub trait Trait: paras::Trait + dmp::Trait + ump::Trait + hrmp::Trait { } +pub trait Trait: + configuration::Trait + paras::Trait + dmp::Trait + ump::Trait + hrmp::Trait +{ +} decl_error! { - pub enum Error for Module { } + pub enum Error for Module { + /// The specified parachain or parathread is not registered. + ParaDoesntExist, + /// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward + /// message. + ExceedsMaxMessageSize, + } } decl_module! { @@ -58,5 +68,21 @@ decl_module! { runtime_parachains::schedule_para_cleanup::(id); Ok(()) } + + /// Send a downward message to the given para. + /// + /// The given parachain should exist and the payload should not exceed the preconfigured size + /// `config.max_downward_message_size`. + #[weight = (1_000, DispatchClass::Operational)] + pub fn sudo_queue_downward_message(origin, id: ParaId, payload: Vec) -> DispatchResult { + ensure_root(origin)?; + ensure!(>::is_valid_para(id), Error::::ParaDoesntExist); + let config = >::config(); + >::queue_downward_message(&config, id, payload) + .map_err(|e| match e { + dmp::QueueDownwardMessageError::ExceedsMaxMessageSize => + Error::::ExceedsMaxMessageSize.into(), + }) + } } } diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index ab811f0f7d48..869a7cff740c 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -542,7 +542,7 @@ impl Module { } /// Returns whether the given ID refers to a valid para. - pub(crate) fn is_valid_para(id: ParaId) -> bool { + pub fn is_valid_para(id: ParaId) -> bool { Self::parachains().binary_search(&id).is_ok() || Self::is_parathread(id) }