diff --git a/pallets/xcm-handler/src/lib.rs b/pallets/xcm-handler/src/lib.rs index 9b34e0a47ef..23efc97ec0d 100644 --- a/pallets/xcm-handler/src/lib.rs +++ b/pallets/xcm-handler/src/lib.rs @@ -27,8 +27,7 @@ use cumulus_primitives_core::{ DownwardMessageHandler, HrmpMessageHandler, HrmpMessageSender, InboundDownwardMessage, InboundHrmpMessage, OutboundHrmpMessage, ParaId, UpwardMessageSender, }; -use frame_support::{decl_error, decl_event, decl_module, sp_runtime::traits::Hash}; -use frame_system::ensure_root; +use frame_support::{decl_error, decl_event, decl_module, sp_runtime::traits::Hash, traits::EnsureOrigin}; use sp_std::convert::{TryFrom, TryInto}; use xcm::{ v0::{Error as XcmError, ExecuteXcm, Junction, MultiLocation, SendXcm, Xcm}, @@ -43,6 +42,9 @@ pub trait Config: frame_system::Config { type UpwardMessageSender: UpwardMessageSender; /// Something to send an HRMP message. type HrmpMessageSender: HrmpMessageSender; + /// Required origin for sending XCM messages. Typically Root or parachain + /// council majority. + type SendXcmOrigin: EnsureOrigin; } decl_event! { @@ -57,7 +59,7 @@ decl_event! { BadFormat(Hash), /// An upward message was sent to the relay chain. UpwardMessageSent(Hash), - /// An HRMP message was sent to a sibling parachainchain. + /// An HRMP message was sent to a sibling parachain. HrmpMessageSent(Hash), } } @@ -74,21 +76,21 @@ decl_module! { fn deposit_event() = default; #[weight = 1_000] - fn sudo_send_xcm(origin, dest: MultiLocation, message: Xcm) { - ensure_root(origin)?; - Self::send_xcm(dest, message).map_err(|_| Error::::FailedToSend)?; + fn send_xcm(origin, dest: MultiLocation, message: Xcm) { + T::SendXcmOrigin::ensure_origin(origin)?; + ::send_xcm(dest, message).map_err(|_| Error::::FailedToSend)?; } #[weight = 1_000] - fn sudo_send_upward_xcm(origin, message: VersionedXcm) { - ensure_root(origin)?; + fn send_upward_xcm(origin, message: VersionedXcm) { + T::SendXcmOrigin::ensure_origin(origin)?; let data = message.encode(); T::UpwardMessageSender::send_upward_message(data).map_err(|_| Error::::FailedToSend)?; } #[weight = 1_000] - fn sudo_send_hrmp_xcm(origin, recipient: ParaId, message: VersionedXcm) { - ensure_root(origin)?; + fn send_hrmp_xcm(origin, recipient: ParaId, message: VersionedXcm) { + T::SendXcmOrigin::ensure_origin(origin)?; let data = message.encode(); let outbound_message = OutboundHrmpMessage { recipient, diff --git a/rococo-parachains/runtime/src/lib.rs b/rococo-parachains/runtime/src/lib.rs index 4789bf6669a..b3bee48c142 100644 --- a/rococo-parachains/runtime/src/lib.rs +++ b/rococo-parachains/runtime/src/lib.rs @@ -46,7 +46,7 @@ pub use frame_support::{ }, StorageValue, }; -use frame_system::limits::{BlockLength, BlockWeights}; +use frame_system::{EnsureRoot, limits::{BlockLength, BlockWeights}}; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] @@ -289,6 +289,7 @@ impl cumulus_pallet_xcm_handler::Config for Runtime { type XcmExecutor = XcmExecutor; type UpwardMessageSender = ParachainSystem; type HrmpMessageSender = ParachainSystem; + type SendXcmOrigin = EnsureRoot; } construct_runtime! {