mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 18:35:41 +00:00
Update para sudo wrapper pallet to FRAME v2 (#3074)
* Migrate para sudo wrapper pallet to pallet attribute macro. * Apply review suggestions.
This commit is contained in:
@@ -16,13 +16,8 @@
|
|||||||
|
|
||||||
//! 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::pallet_prelude::*;
|
||||||
use frame_support::{
|
use frame_system::pallet_prelude::*;
|
||||||
decl_error, decl_module, ensure,
|
|
||||||
dispatch::DispatchResult,
|
|
||||||
weights::DispatchClass,
|
|
||||||
};
|
|
||||||
use frame_system::ensure_root;
|
|
||||||
use runtime_parachains::{
|
use runtime_parachains::{
|
||||||
configuration, dmp, ump, hrmp,
|
configuration, dmp, ump, hrmp,
|
||||||
ParaLifecycle,
|
ParaLifecycle,
|
||||||
@@ -30,15 +25,24 @@ use runtime_parachains::{
|
|||||||
};
|
};
|
||||||
use primitives::v1::Id as ParaId;
|
use primitives::v1::Id as ParaId;
|
||||||
use parity_scale_codec::Encode;
|
use parity_scale_codec::Encode;
|
||||||
|
pub use pallet::*;
|
||||||
|
|
||||||
/// The module's configuration trait.
|
#[frame_support::pallet]
|
||||||
pub trait Config:
|
pub mod pallet {
|
||||||
configuration::Config + paras::Config + dmp::Config + ump::Config + hrmp::Config
|
use super::*;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
decl_error! {
|
#[pallet::pallet]
|
||||||
pub enum Error for Module<T: Config> {
|
#[pallet::generate_store(pub(super) trait Store)]
|
||||||
|
pub struct Pallet<T>(_);
|
||||||
|
|
||||||
|
#[pallet::config]
|
||||||
|
#[pallet::disable_frame_system_supertrait_check]
|
||||||
|
pub trait Config:
|
||||||
|
configuration::Config + paras::Config + dmp::Config + ump::Config + hrmp::Config {}
|
||||||
|
|
||||||
|
|
||||||
|
#[pallet::error]
|
||||||
|
pub enum Error<T> {
|
||||||
/// The specified parachain or parathread is not registered.
|
/// The specified parachain or parathread is not registered.
|
||||||
ParaDoesntExist,
|
ParaDoesntExist,
|
||||||
/// The specified parachain or parathread is already registered.
|
/// The specified parachain or parathread is already registered.
|
||||||
@@ -57,50 +61,58 @@ decl_error! {
|
|||||||
/// Cannot downgrade parachain.
|
/// Cannot downgrade parachain.
|
||||||
CannotDowngrade,
|
CannotDowngrade,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
decl_module! {
|
#[pallet::hooks]
|
||||||
/// A sudo wrapper to call into v1 paras module.
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||||
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
|
|
||||||
type Error = Error<T>;
|
|
||||||
|
|
||||||
|
#[pallet::call]
|
||||||
|
impl<T: Config> Pallet<T> {
|
||||||
/// Schedule a para to be initialized at the start of the next session.
|
/// Schedule a para to be initialized at the start of the next session.
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_schedule_para_initialize(
|
pub fn sudo_schedule_para_initialize(
|
||||||
origin,
|
origin: OriginFor<T>,
|
||||||
id: ParaId,
|
id: ParaId,
|
||||||
genesis: ParaGenesisArgs,
|
genesis: ParaGenesisArgs,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
runtime_parachains::schedule_para_initialize::<T>(id, genesis).map_err(|_| Error::<T>::ParaAlreadyExists)?;
|
runtime_parachains::schedule_para_initialize::<T>(id, genesis)
|
||||||
|
.map_err(|_| Error::<T>::ParaAlreadyExists)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schedule a para to be cleaned up at the start of the next session.
|
/// Schedule a para to be cleaned up at the start of the next session.
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_schedule_para_cleanup(origin, id: ParaId) -> DispatchResult {
|
pub fn sudo_schedule_para_cleanup(origin: OriginFor<T>, id: ParaId) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
runtime_parachains::schedule_para_cleanup::<T>(id).map_err(|_| Error::<T>::CouldntCleanup)?;
|
runtime_parachains::schedule_para_cleanup::<T>(id).map_err(|_| Error::<T>::CouldntCleanup)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upgrade a parathread to a parachain
|
/// Upgrade a parathread to a parachain
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_schedule_parathread_upgrade(origin, id: ParaId) -> DispatchResult {
|
pub fn sudo_schedule_parathread_upgrade(origin: OriginFor<T>, id: ParaId) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
// Para backend should think this is a parathread...
|
// Para backend should think this is a parathread...
|
||||||
ensure!(paras::Module::<T>::lifecycle(id) == Some(ParaLifecycle::Parathread), Error::<T>::NotParathread);
|
ensure!(
|
||||||
runtime_parachains::schedule_parathread_upgrade::<T>(id).map_err(|_| Error::<T>::CannotUpgrade)?;
|
paras::Pallet::<T>::lifecycle(id) == Some(ParaLifecycle::Parathread),
|
||||||
|
Error::<T>::NotParathread,
|
||||||
|
);
|
||||||
|
runtime_parachains::schedule_parathread_upgrade::<T>(id)
|
||||||
|
.map_err(|_| Error::<T>::CannotUpgrade)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Downgrade a parachain to a parathread
|
/// Downgrade a parachain to a parathread
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_schedule_parachain_downgrade(origin, id: ParaId) -> DispatchResult {
|
pub fn sudo_schedule_parachain_downgrade(origin: OriginFor<T>, id: ParaId) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
// Para backend should think this is a parachain...
|
// Para backend should think this is a parachain...
|
||||||
ensure!(paras::Module::<T>::lifecycle(id) == Some(ParaLifecycle::Parachain), Error::<T>::NotParachain);
|
ensure!(
|
||||||
runtime_parachains::schedule_parachain_downgrade::<T>(id).map_err(|_| Error::<T>::CannotDowngrade)?;
|
paras::Pallet::<T>::lifecycle(id) == Some(ParaLifecycle::Parachain),
|
||||||
|
Error::<T>::NotParachain,
|
||||||
|
);
|
||||||
|
runtime_parachains::schedule_parachain_downgrade::<T>(id)
|
||||||
|
.map_err(|_| Error::<T>::CannotDowngrade)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,12 +120,16 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// The given parachain should exist and the payload should not exceed the preconfigured size
|
/// The given parachain should exist and the payload should not exceed the preconfigured size
|
||||||
/// `config.max_downward_message_size`.
|
/// `config.max_downward_message_size`.
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_queue_downward_xcm(origin, id: ParaId, xcm: xcm::opaque::VersionedXcm) -> DispatchResult {
|
pub fn sudo_queue_downward_xcm(
|
||||||
|
origin: OriginFor<T>,
|
||||||
|
id: ParaId,
|
||||||
|
xcm: xcm::opaque::VersionedXcm,
|
||||||
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
ensure!(<paras::Module<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
|
ensure!(<paras::Pallet<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
|
||||||
let config = <configuration::Module<T>>::config();
|
let config = <configuration::Pallet<T>>::config();
|
||||||
<dmp::Module<T>>::queue_downward_message(&config, id, xcm.encode())
|
<dmp::Pallet<T>>::queue_downward_message(&config, id, xcm.encode())
|
||||||
.map_err(|e| match e {
|
.map_err(|e| match e {
|
||||||
dmp::QueueDownwardMessageError::ExceedsMaxMessageSize =>
|
dmp::QueueDownwardMessageError::ExceedsMaxMessageSize =>
|
||||||
Error::<T>::ExceedsMaxMessageSize.into(),
|
Error::<T>::ExceedsMaxMessageSize.into(),
|
||||||
@@ -124,9 +140,9 @@ decl_module! {
|
|||||||
///
|
///
|
||||||
/// This is equivalent to sending an `Hrmp::hrmp_init_open_channel` extrinsic followed by
|
/// This is equivalent to sending an `Hrmp::hrmp_init_open_channel` extrinsic followed by
|
||||||
/// `Hrmp::hrmp_accept_open_channel`.
|
/// `Hrmp::hrmp_accept_open_channel`.
|
||||||
#[weight = (1_000, DispatchClass::Operational)]
|
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||||
pub fn sudo_establish_hrmp_channel(
|
pub fn sudo_establish_hrmp_channel(
|
||||||
origin,
|
origin: OriginFor<T>,
|
||||||
sender: ParaId,
|
sender: ParaId,
|
||||||
recipient: ParaId,
|
recipient: ParaId,
|
||||||
max_capacity: u32,
|
max_capacity: u32,
|
||||||
@@ -134,13 +150,13 @@ decl_module! {
|
|||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
|
|
||||||
<hrmp::Module<T>>::init_open_channel(
|
<hrmp::Pallet<T>>::init_open_channel(
|
||||||
sender,
|
sender,
|
||||||
recipient,
|
recipient,
|
||||||
max_capacity,
|
max_capacity,
|
||||||
max_message_size,
|
max_message_size,
|
||||||
)?;
|
)?;
|
||||||
<hrmp::Module<T>>::accept_open_channel(recipient, sender)?;
|
<hrmp::Pallet<T>>::accept_open_channel(recipient, sender)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user