Unverified Commit 120d5dde authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by GitHub
Browse files

sudo_queue_downward_message (#1941)



* Add a sudo wrapper for Dmp::queue_downward_message

* Apply suggestions from code review
Co-authored-by: default avatarPeter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>

* Stylistic changes

* Remove trailing whitespaces
Co-authored-by: default avatarPeter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
parent c7708818
Pipeline #114169 passed with stages
in 25 minutes and 25 seconds
......@@ -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<T: Trait> { }
pub enum Error for Module<T: Trait> {
/// 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::<T>(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<u8>) -> DispatchResult {
ensure_root(origin)?;
ensure!(<paras::Module<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
let config = <configuration::Module<T>>::config();
<dmp::Module<T>>::queue_downward_message(&config, id, payload)
.map_err(|e| match e {
dmp::QueueDownwardMessageError::ExceedsMaxMessageSize =>
Error::<T>::ExceedsMaxMessageSize.into(),
})
}
}
}
......@@ -542,7 +542,7 @@ impl<T: Trait> Module<T> {
}
/// 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)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment