From f900dede87efcfd91eb5656ed78077ed3877f323 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Mon, 17 Jul 2023 08:32:52 +0200 Subject: [PATCH] Put HRMP Channel Management on General Admin Track (#7477) * create ManagerOrigin for HRMP * missed one * fix mock * update GeneralAdmin docs --- runtime/kusama/src/governance/origins.rs | 2 +- runtime/kusama/src/lib.rs | 1 + runtime/parachains/src/hrmp.rs | 45 +++++++++++++--------- runtime/parachains/src/mock.rs | 1 + runtime/polkadot/src/governance/origins.rs | 2 +- runtime/polkadot/src/lib.rs | 1 + runtime/rococo/src/lib.rs | 1 + runtime/test-runtime/src/lib.rs | 1 + runtime/westend/src/lib.rs | 1 + 9 files changed, 35 insertions(+), 20 deletions(-) diff --git a/runtime/kusama/src/governance/origins.rs b/runtime/kusama/src/governance/origins.rs index 85bca7dd975b..c5cb035a5269 100644 --- a/runtime/kusama/src/governance/origins.rs +++ b/runtime/kusama/src/governance/origins.rs @@ -38,7 +38,7 @@ pub mod pallet_custom_origins { Treasurer, /// Origin for managing the composition of the fellowship. FellowshipAdmin, - /// Origin for managing the registrar. + /// Origin for managing the registrar and permissioned HRMP channel operations. GeneralAdmin, /// Origin for starting auctions. AuctionAdmin, diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 76a54a1ad971..17d5d8b4bdac 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1155,6 +1155,7 @@ impl parachains_dmp::Config for Runtime {} impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = EitherOf, GeneralAdmin>; type Currency = Balances; type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 4fbffc45e563..c876749e853d 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -249,6 +249,9 @@ pub mod pallet { + From<::RuntimeOrigin> + Into::RuntimeOrigin>>; + /// The origin that can perform "force" actions on channels. + type ChannelManager: EnsureOrigin<::RuntimeOrigin>; + /// An interface for reserving deposits for opening channels. /// /// NOTE that this Currency instance will be charged with the amounts defined in the @@ -513,13 +516,13 @@ pub mod pallet { Ok(()) } - /// This extrinsic triggers the cleanup of all the HRMP storage items that - /// a para may have. Normally this happens once per session, but this allows - /// you to trigger the cleanup immediately for a specific parachain. + /// This extrinsic triggers the cleanup of all the HRMP storage items that a para may have. + /// Normally this happens once per session, but this allows you to trigger the cleanup + /// immediately for a specific parachain. /// - /// Origin must be Root. + /// Number of inbound and outbound channels for `para` must be provided as witness data. /// - /// Number of inbound and outbound channels for `para` must be provided as witness data of weighing. + /// Origin must be the `ChannelManager`. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::force_clean_hrmp(*_inbound, *_outbound))] pub fn force_clean_hrmp( @@ -528,21 +531,23 @@ pub mod pallet { _inbound: u32, _outbound: u32, ) -> DispatchResult { - ensure_root(origin)?; + T::ChannelManager::ensure_origin(origin)?; Self::clean_hrmp_after_outgoing(¶); Ok(()) } /// Force process HRMP open channel requests. /// - /// If there are pending HRMP open channel requests, you can use this - /// function process all of those requests immediately. + /// If there are pending HRMP open channel requests, you can use this function to process + /// all of those requests immediately. + /// + /// Total number of opening channels must be provided as witness data. /// - /// Total number of opening channels must be provided as witness data of weighing. + /// Origin must be the `ChannelManager`. #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::force_process_hrmp_open(*_channels))] pub fn force_process_hrmp_open(origin: OriginFor, _channels: u32) -> DispatchResult { - ensure_root(origin)?; + T::ChannelManager::ensure_origin(origin)?; let host_config = configuration::Pallet::::config(); Self::process_hrmp_open_channel_requests(&host_config); Ok(()) @@ -550,14 +555,16 @@ pub mod pallet { /// Force process HRMP close channel requests. /// - /// If there are pending HRMP close channel requests, you can use this - /// function process all of those requests immediately. + /// If there are pending HRMP close channel requests, you can use this function to process + /// all of those requests immediately. /// - /// Total number of closing channels must be provided as witness data of weighing. + /// Total number of closing channels must be provided as witness data. + /// + /// Origin must be the `ChannelManager`. #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::force_process_hrmp_close(*_channels))] pub fn force_process_hrmp_close(origin: OriginFor, _channels: u32) -> DispatchResult { - ensure_root(origin)?; + T::ChannelManager::ensure_origin(origin)?; Self::process_hrmp_close_channel_requests(); Ok(()) } @@ -588,12 +595,14 @@ pub mod pallet { Ok(()) } - /// Open a channel from a `sender` to a `recipient` `ParaId` using the Root origin. Although - /// opened by Root, the `max_capacity` and `max_message_size` are still subject to the Relay - /// Chain's configured limits. + /// Open a channel from a `sender` to a `recipient` `ParaId`. Although opened by governance, + /// the `max_capacity` and `max_message_size` are still subject to the Relay Chain's + /// configured limits. /// /// Expected use is when one of the `ParaId`s involved in the channel is governed by the /// Relay Chain, e.g. a system parachain. + /// + /// Origin must be the `ChannelManager`. #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::force_open_hrmp_channel(1))] pub fn force_open_hrmp_channel( @@ -603,7 +612,7 @@ pub mod pallet { max_capacity: u32, max_message_size: u32, ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; + T::ChannelManager::ensure_origin(origin)?; // Guard against a common footgun where someone makes a channel request to a system // parachain and then makes a proposal to open the channel via governance, which fails diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index b33559ff663c..f4043b36bafd 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -219,6 +219,7 @@ parameter_types! { impl crate::hrmp::Config for Test { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = frame_system::EnsureRoot; type Currency = pallet_balances::Pallet; type WeightInfo = crate::hrmp::TestWeightInfo; } diff --git a/runtime/polkadot/src/governance/origins.rs b/runtime/polkadot/src/governance/origins.rs index a4d13bb3c66d..551e05e556db 100644 --- a/runtime/polkadot/src/governance/origins.rs +++ b/runtime/polkadot/src/governance/origins.rs @@ -39,7 +39,7 @@ pub mod pallet_custom_origins { Treasurer, /// Origin for managing the composition of the fellowship. FellowshipAdmin, - /// Origin for managing the registrar. + /// Origin for managing the registrar and permissioned HRMP channel operations. GeneralAdmin, /// Origin for starting auctions. AuctionAdmin, diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 9b4b0252be0d..627a336b8bcb 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1171,6 +1171,7 @@ impl parachains_dmp::Config for Runtime {} impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = EitherOf, GeneralAdmin>; type Currency = Balances; type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 4da758514bb5..9c57305f8e3f 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1084,6 +1084,7 @@ impl parachains_dmp::Config for Runtime {} impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = EnsureRoot; type Currency = Balances; type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 4ab8dcfda31b..9e7057c32c04 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -543,6 +543,7 @@ parameter_types! { impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = frame_system::EnsureRoot; type Currency = Balances; type WeightInfo = parachains_hrmp::TestWeightInfo; } diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 5223fb4fabef..4a7551873b3b 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -984,6 +984,7 @@ impl parachains_dmp::Config for Runtime {} impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + type ChannelManager = EnsureRoot; type Currency = Balances; type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; }