mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 12:41:07 +00:00
sudo_queue_downward_message (#1941)
* Add a sudo wrapper for Dmp::queue_downward_message * Apply suggestions from code review Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com> * Stylistic changes * Remove trailing whitespaces Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
This commit is contained in:
@@ -16,22 +16,32 @@
|
|||||||
|
|
||||||
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
|
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
|
||||||
|
|
||||||
|
use sp_std::prelude::*;
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_error, decl_module,
|
decl_error, decl_module, ensure,
|
||||||
dispatch::DispatchResult,
|
dispatch::DispatchResult,
|
||||||
weights::DispatchClass,
|
weights::DispatchClass,
|
||||||
};
|
};
|
||||||
use frame_system::ensure_root;
|
use frame_system::ensure_root;
|
||||||
use runtime_parachains::{
|
use runtime_parachains::{
|
||||||
dmp, ump, hrmp, paras::{self, ParaGenesisArgs},
|
configuration, dmp, ump, hrmp, paras::{self, ParaGenesisArgs},
|
||||||
};
|
};
|
||||||
use primitives::v1::Id as ParaId;
|
use primitives::v1::Id as ParaId;
|
||||||
|
|
||||||
/// The module's configuration trait.
|
/// 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! {
|
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! {
|
decl_module! {
|
||||||
@@ -58,5 +68,21 @@ decl_module! {
|
|||||||
runtime_parachains::schedule_para_cleanup::<T>(id);
|
runtime_parachains::schedule_para_cleanup::<T>(id);
|
||||||
Ok(())
|
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.
|
/// 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::parachains().binary_search(&id).is_ok()
|
||||||
|| Self::is_parathread(id)
|
|| Self::is_parathread(id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user