Unverified Commit fad52682 authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by GitHub
Browse files

Sudo utility for establishing an HRMP channel (#2067)



* Clean up of visibility of helper fns

* Document HRMP channel dispatchables

* Provide the sudo_establish_hrmp_channel dispatchable function

* Apply suggestions from code review

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
parent 41e134ea
Pipeline #116128 passed with stages
in 18 minutes and 39 seconds
......@@ -88,5 +88,29 @@ decl_module! {
Error::<T>::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)?;
<hrmp::Module<T>>::init_open_channel(
sender,
recipient,
max_capacity,
max_message_size,
)?;
<hrmp::Module<T>>::accept_open_channel(recipient, sender)?;
Ok(())
}
}
}
......@@ -325,8 +325,18 @@ decl_module! {
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
type Error = Error<T>;
/// 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(<T as Config>::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(<T as Config>::Origin::from(origin))?;
Self::close_channel(origin, channel_id)?;
Ok(())
......@@ -808,7 +825,12 @@ impl<T: Config> Module<T> {
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<T: Config> Module<T> {
Ok(())
}
pub(super) fn accept_open_channel(origin: ParaId, sender: ParaId) -> Result<(), Error<T>> {
/// 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<T>> {
let channel_id = HrmpChannelId {
sender,
recipient: origin,
......@@ -958,7 +984,7 @@ impl<T: Config> Module<T> {
Ok(())
}
pub(super) fn close_channel(origin: ParaId, channel_id: HrmpChannelId) -> Result<(), Error<T>> {
fn close_channel(origin: ParaId, channel_id: HrmpChannelId) -> Result<(), Error<T>> {
// check if the origin is allowed to close the channel.
ensure!(
origin == channel_id.sender || origin == channel_id.recipient,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment