diff --git a/polkadot/runtime/common/src/paras_sudo_wrapper.rs b/polkadot/runtime/common/src/paras_sudo_wrapper.rs index 1ff03a3640..c0eb9426fc 100644 --- a/polkadot/runtime/common/src/paras_sudo_wrapper.rs +++ b/polkadot/runtime/common/src/paras_sudo_wrapper.rs @@ -88,5 +88,29 @@ decl_module! { Error::::ExceedsMaxMessageSize.into(), }) } + + /// Forcefully establish a channel from the sender to the recipient. + /// + /// This is equivalent to sending an `Hrmp::hrmp_init_open_channel` extrinsic followed by + /// `Hrmp::hrmp_accept_open_channel`. + #[weight = (1_000, DispatchClass::Operational)] + pub fn sudo_establish_hrmp_channel( + origin, + sender: ParaId, + recipient: ParaId, + max_capacity: u32, + max_message_size: u32, + ) -> DispatchResult { + ensure_root(origin)?; + + >::init_open_channel( + sender, + recipient, + max_capacity, + max_message_size, + )?; + >::accept_open_channel(recipient, sender)?; + Ok(()) + } } } diff --git a/polkadot/runtime/parachains/src/hrmp.rs b/polkadot/runtime/parachains/src/hrmp.rs index 9ce7220e2d..8021ebf2e3 100644 --- a/polkadot/runtime/parachains/src/hrmp.rs +++ b/polkadot/runtime/parachains/src/hrmp.rs @@ -325,8 +325,18 @@ decl_module! { pub struct Module for enum Call where origin: ::Origin { type Error = Error; + /// Initiate opening a channel from a parachain to a given recipient with given channel + /// parameters. + /// + /// - `proposed_max_capacity` - specifies how many messages can be in the channel at once. + /// - `proposed_max_message_size` - specifies the maximum size of any of the messages. + /// + /// These numbers are a subject to the relay-chain configuration limits. + /// + /// The channel can be opened only after the recipient confirms it and only on a session + /// change. #[weight = 0] - fn hrmp_init_open_channel( + pub fn hrmp_init_open_channel( origin, recipient: ParaId, proposed_max_capacity: u32, @@ -342,15 +352,22 @@ decl_module! { Ok(()) } + /// Accept a pending open channel request from the given sender. + /// + /// The channel will be opened only on the next session boundary. #[weight = 0] - fn hrmp_accept_open_channel(origin, sender: ParaId) -> DispatchResult { + pub fn hrmp_accept_open_channel(origin, sender: ParaId) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; Self::accept_open_channel(origin, sender)?; Ok(()) } + /// Initiate unilateral closing of a channel. The origin must be either the sender or the + /// recipient in the channel being closed. + /// + /// The closure can only happen on a session change. #[weight = 0] - fn hrmp_close_channel(origin, channel_id: HrmpChannelId) -> DispatchResult { + pub fn hrmp_close_channel(origin, channel_id: HrmpChannelId) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; Self::close_channel(origin, channel_id)?; Ok(()) @@ -808,7 +825,12 @@ impl Module { weight } - pub(super) fn init_open_channel( + /// Initiate opening a channel from a parachain to a given recipient with given channel + /// parameters. + /// + /// Basically the same as [`hrmp_init_open_channel`](Module::hrmp_init_open_channel) but intendend for calling directly from + /// other pallets rather than dispatched. + pub fn init_open_channel( origin: ParaId, recipient: ParaId, proposed_max_capacity: u32, @@ -902,7 +924,11 @@ impl Module { Ok(()) } - pub(super) fn accept_open_channel(origin: ParaId, sender: ParaId) -> Result<(), Error> { + /// Accept a pending open channel request from the given sender. + /// + /// Basically the same as [`hrmp_accept_open_channel`](Module::hrmp_accept_open_channel) but intendend for calling directly from + /// other pallets rather than dispatched. + pub fn accept_open_channel(origin: ParaId, sender: ParaId) -> Result<(), Error> { let channel_id = HrmpChannelId { sender, recipient: origin, @@ -958,7 +984,7 @@ impl Module { Ok(()) } - pub(super) fn close_channel(origin: ParaId, channel_id: HrmpChannelId) -> Result<(), Error> { + fn close_channel(origin: ParaId, channel_id: HrmpChannelId) -> Result<(), Error> { // check if the origin is allowed to close the channel. ensure!( origin == channel_id.sender || origin == channel_id.recipient,