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: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Shulepov
2020-12-04 14:19:01 +01:00
committed by GitHub
parent 9014232903
commit 62a95fc602
2 changed files with 56 additions and 6 deletions
+32 -6
View File
@@ -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,