Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Put HRMP Channel Management on General Admin Track (#7477)
Browse files Browse the repository at this point in the history
* create ManagerOrigin for HRMP

* missed one

* fix mock

* update GeneralAdmin docs
  • Loading branch information
joepetrowski authored Jul 17, 2023
1 parent 6a71a7e commit f900ded
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion runtime/kusama/src/governance/origins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type Currency = Balances;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Runtime>;
}
Expand Down
45 changes: 27 additions & 18 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ pub mod pallet {
+ From<<Self as frame_system::Config>::RuntimeOrigin>
+ Into<Result<crate::Origin, <Self as Config>::RuntimeOrigin>>;

/// The origin that can perform "force" actions on channels.
type ChannelManager: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;

/// An interface for reserving deposits for opening channels.
///
/// NOTE that this Currency instance will be charged with the amounts defined in the
Expand Down Expand Up @@ -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(<T as Config>::WeightInfo::force_clean_hrmp(*_inbound, *_outbound))]
pub fn force_clean_hrmp(
Expand All @@ -528,36 +531,40 @@ pub mod pallet {
_inbound: u32,
_outbound: u32,
) -> DispatchResult {
ensure_root(origin)?;
T::ChannelManager::ensure_origin(origin)?;
Self::clean_hrmp_after_outgoing(&para);
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(<T as Config>::WeightInfo::force_process_hrmp_open(*_channels))]
pub fn force_process_hrmp_open(origin: OriginFor<T>, _channels: u32) -> DispatchResult {
ensure_root(origin)?;
T::ChannelManager::ensure_origin(origin)?;
let host_config = configuration::Pallet::<T>::config();
Self::process_hrmp_open_channel_requests(&host_config);
Ok(())
}

/// 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(<T as Config>::WeightInfo::force_process_hrmp_close(*_channels))]
pub fn force_process_hrmp_close(origin: OriginFor<T>, _channels: u32) -> DispatchResult {
ensure_root(origin)?;
T::ChannelManager::ensure_origin(origin)?;
Self::process_hrmp_close_channel_requests();
Ok(())
}
Expand Down Expand Up @@ -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(<T as Config>::WeightInfo::force_open_hrmp_channel(1))]
pub fn force_open_hrmp_channel(
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ parameter_types! {
impl crate::hrmp::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type ChannelManager = frame_system::EnsureRoot<u64>;
type Currency = pallet_balances::Pallet<Test>;
type WeightInfo = crate::hrmp::TestWeightInfo;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/src/governance/origins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type Currency = Balances;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Self>;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId>;
type Currency = Balances;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Runtime>;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ parameter_types! {
impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type ChannelManager = frame_system::EnsureRoot<AccountId>;
type Currency = Balances;
type WeightInfo = parachains_hrmp::TestWeightInfo;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId>;
type Currency = Balances;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Self>;
}
Expand Down

0 comments on commit f900ded

Please sign in to comment.