From e0bee2add17f05be73252f7de4bd716b3934b3b6 Mon Sep 17 00:00:00 2001 From: noandrea Date: Wed, 3 Apr 2024 06:31:33 -0700 Subject: [PATCH 1/7] Add new origin for opening a Hrmp channel --- pallets/xcm-transactor/src/lib.rs | 20 +++++++++++++++++--- pallets/xcm-transactor/src/mock.rs | 1 + precompiles/relay-encoder/src/mock.rs | 1 + precompiles/xcm-transactor/src/mock.rs | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index 0dd8ecd0cf..f140e89b26 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -95,7 +95,10 @@ pub mod pallet { use crate::weights::WeightInfo; use crate::CurrencyIdOf; use cumulus_primitives_core::{relay_chain::HrmpChannelId, ParaId}; - use frame_support::{pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_SECOND}; + use frame_support::traits::EitherOfDiverse; + use frame_support::{ + dispatch::DispatchResult, pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_SECOND, + }; use frame_system::{ensure_signed, pallet_prelude::*}; use orml_traits::location::{Parse, Reserve}; use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, Convert}; @@ -143,9 +146,12 @@ pub mod pallet { // The origin that is allowed to register derivative address indices type DerivativeAddressRegistrationOrigin: EnsureOrigin; - // The origin that is allowed to register derivative address indices + // The origin that is allowed to manipulate (open, close, accept, cancel) an Hrmp channel type HrmpManipulatorOrigin: EnsureOrigin; + // The origin that is allowed to open an Hrmp channel + type HrmpOpenOrigin: EnsureOrigin; + /// Convert `T::AccountId` to `Location`. type AccountIdToLocation: Convert; @@ -862,7 +868,15 @@ pub mod pallet { // BuyExecution // SetAppendix(RefundSurplus, DepositAsset(sov account)) // Transact - T::HrmpManipulatorOrigin::ensure_origin(origin)?; + + if let HrmpOperation::InitOpen(_) = &action { + >::ensure_origin( + origin, + )?; + } else { + T::HrmpManipulatorOrigin::ensure_origin(origin)?; + } + let call_bytes = match action.clone() { HrmpOperation::InitOpen(params) => { Self::hrmp_encode_call(HrmpAvailableCalls::InitOpenChannel( diff --git a/pallets/xcm-transactor/src/mock.rs b/pallets/xcm-transactor/src/mock.rs index cc55c474aa..d82411b73f 100644 --- a/pallets/xcm-transactor/src/mock.rs +++ b/pallets/xcm-transactor/src/mock.rs @@ -396,6 +396,7 @@ impl Config for Test { type ReserveProvider = orml_traits::location::RelativeReserveProvider; type WeightInfo = (); type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; type MaxHrmpFee = MaxHrmpRelayFee; } diff --git a/precompiles/relay-encoder/src/mock.rs b/precompiles/relay-encoder/src/mock.rs index 15bfc3a0ba..b528a46347 100644 --- a/precompiles/relay-encoder/src/mock.rs +++ b/precompiles/relay-encoder/src/mock.rs @@ -309,6 +309,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = orml_traits::location::RelativeReserveProvider; type WeightInfo = (); type HrmpManipulatorOrigin = frame_system::EnsureRoot; + type HrmpOpenOrigin = frame_system::EnsureRoot; type MaxHrmpFee = (); } diff --git a/precompiles/xcm-transactor/src/mock.rs b/precompiles/xcm-transactor/src/mock.rs index 83e100478a..03d014f5a1 100644 --- a/precompiles/xcm-transactor/src/mock.rs +++ b/precompiles/xcm-transactor/src/mock.rs @@ -334,6 +334,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = orml_traits::location::RelativeReserveProvider; type WeightInfo = (); type HrmpManipulatorOrigin = frame_system::EnsureRoot; + type HrmpOpenOrigin = frame_system::EnsureRoot; type MaxHrmpFee = (); } From 5f9afe58a729850da0477b6a0bb45bf5b6ca638b Mon Sep 17 00:00:00 2001 From: noandrea Date: Wed, 3 Apr 2024 06:34:31 -0700 Subject: [PATCH 2/7] update Moonbase to support the HrmpOpen origin --- runtime/moonbase/src/governance/referenda.rs | 4 ++-- runtime/moonbase/src/xcm_config.rs | 5 +++-- runtime/moonbase/tests/xcm_mock/parachain.rs | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/moonbase/src/governance/referenda.rs b/runtime/moonbase/src/governance/referenda.rs index e694bfd6a9..96bb3628d2 100644 --- a/runtime/moonbase/src/governance/referenda.rs +++ b/runtime/moonbase/src/governance/referenda.rs @@ -51,8 +51,8 @@ parameter_types! { pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; -/// The policy allows for Root, GeneralAdmin, or FastGeneralAdmin. -pub type FastGeneralAdminOrRoot = EitherOf; +/// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; impl custom_origins::Config for Runtime {} diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 4c438a17ff..caa15f5ff3 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -72,7 +72,7 @@ use sp_std::{ use orml_traits::parameter_type_with_key; -use crate::governance::referenda::FastGeneralAdminOrRoot; +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { // The network Id of the relay @@ -658,7 +658,8 @@ impl pallet_xcm_transactor::Config for Runtime { type AssetTransactor = AssetTransactors; type ReserveProvider = AbsoluteAndRelativeReserve; type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; - type HrmpManipulatorOrigin = FastGeneralAdminOrRoot; + type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; type MaxHrmpFee = xcm_builder::Case; } diff --git a/runtime/moonbase/tests/xcm_mock/parachain.rs b/runtime/moonbase/tests/xcm_mock/parachain.rs index 6ef68c0e9f..20c6d4d477 100644 --- a/runtime/moonbase/tests/xcm_mock/parachain.rs +++ b/runtime/moonbase/tests/xcm_mock/parachain.rs @@ -840,6 +840,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; type MaxHrmpFee = xcm_builder::Case; } From b12435b5a37dbf0f248e37f2796011d95c19a460 Mon Sep 17 00:00:00 2001 From: noandrea Date: Wed, 3 Apr 2024 06:35:25 -0700 Subject: [PATCH 3/7] add new track fast_general_admin to open hrmp channels on Moonriver --- runtime/moonriver/src/governance/origins.rs | 5 ++++- runtime/moonriver/src/governance/referenda.rs | 2 ++ runtime/moonriver/src/governance/tracks.rs | 16 +++++++++++++++- runtime/moonriver/src/xcm_config.rs | 3 ++- runtime/moonriver/tests/xcm_mock/parachain.rs | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/runtime/moonriver/src/governance/origins.rs b/runtime/moonriver/src/governance/origins.rs index cbed5b9ecb..ef4675d629 100644 --- a/runtime/moonriver/src/governance/origins.rs +++ b/runtime/moonriver/src/governance/origins.rs @@ -40,6 +40,8 @@ pub mod custom_origins { ReferendumCanceller, /// Origin able to kill referenda. ReferendumKiller, + /// Fast General Admin + FastGeneralAdmin, } macro_rules! decl_unit_ensures { @@ -76,6 +78,7 @@ pub mod custom_origins { ReferendumCanceller, ReferendumKiller, WhitelistedCaller, - GeneralAdmin + GeneralAdmin, + FastGeneralAdmin, ); } diff --git a/runtime/moonriver/src/governance/referenda.rs b/runtime/moonriver/src/governance/referenda.rs index 48a326f77e..8177e88e38 100644 --- a/runtime/moonriver/src/governance/referenda.rs +++ b/runtime/moonriver/src/governance/referenda.rs @@ -50,6 +50,8 @@ parameter_types! { // Origin for general admin or root pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; +// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; impl custom_origins::Config for Runtime {} diff --git a/runtime/moonriver/src/governance/tracks.rs b/runtime/moonriver/src/governance/tracks.rs index b4e23ba032..8dddbeca61 100644 --- a/runtime/moonriver/src/governance/tracks.rs +++ b/runtime/moonriver/src/governance/tracks.rs @@ -28,7 +28,7 @@ const fn permill(x: i32) -> sp_runtime::FixedI64 { } use pallet_referenda::Curve; -const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] = [ +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 6] = [ ( 0, pallet_referenda::TrackInfo { @@ -111,6 +111,20 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), }, ), + ( + 5, + pallet_referenda::TrackInfo { + name: "fast_general_admin", + max_deciding: 10, + decision_deposit: 500 * MOVR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(5, 14, percent(1), percent(0), percent(50)), + }, + ), ]; pub struct TracksInfo; diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index 8cbe08114b..58cc41b321 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -72,7 +72,7 @@ use sp_std::{ use orml_traits::parameter_type_with_key; -use crate::governance::referenda::GeneralAdminOrRoot; +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { // The network Id of the relay @@ -664,6 +664,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = AbsoluteAndRelativeReserve; type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; type MaxHrmpFee = xcm_builder::Case; } diff --git a/runtime/moonriver/tests/xcm_mock/parachain.rs b/runtime/moonriver/tests/xcm_mock/parachain.rs index ac8b749c8a..201b479627 100644 --- a/runtime/moonriver/tests/xcm_mock/parachain.rs +++ b/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -805,6 +805,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; type MaxHrmpFee = xcm_builder::Case; } From e9fee93af836e45d4f422fa19e89dcab9d88ac21 Mon Sep 17 00:00:00 2001 From: noandrea Date: Wed, 3 Apr 2024 06:35:54 -0700 Subject: [PATCH 4/7] add new track fast_general_admin to open new hrmp channels on Moonbeam --- runtime/moonbeam/src/governance/origins.rs | 5 ++++- runtime/moonbeam/src/governance/referenda.rs | 2 ++ runtime/moonbeam/src/governance/tracks.rs | 16 +++++++++++++++- runtime/moonbeam/src/xcm_config.rs | 3 ++- runtime/moonbeam/tests/xcm_mock/parachain.rs | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/runtime/moonbeam/src/governance/origins.rs b/runtime/moonbeam/src/governance/origins.rs index d873cc96e0..48154cd178 100644 --- a/runtime/moonbeam/src/governance/origins.rs +++ b/runtime/moonbeam/src/governance/origins.rs @@ -41,6 +41,8 @@ pub mod custom_origins { ReferendumCanceller, /// Origin able to kill referenda. ReferendumKiller, + /// Fast General Admin + FastGeneralAdmin, } macro_rules! decl_unit_ensures { @@ -77,6 +79,7 @@ pub mod custom_origins { ReferendumCanceller, ReferendumKiller, WhitelistedCaller, - GeneralAdmin + GeneralAdmin, + FastGeneralAdmin, ); } diff --git a/runtime/moonbeam/src/governance/referenda.rs b/runtime/moonbeam/src/governance/referenda.rs index 78d1a18fbd..62720a0d60 100644 --- a/runtime/moonbeam/src/governance/referenda.rs +++ b/runtime/moonbeam/src/governance/referenda.rs @@ -50,6 +50,8 @@ parameter_types! { // Origin for general admin or root pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; +// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; impl custom_origins::Config for Runtime {} diff --git a/runtime/moonbeam/src/governance/tracks.rs b/runtime/moonbeam/src/governance/tracks.rs index 34b527c987..a69cd6456d 100644 --- a/runtime/moonbeam/src/governance/tracks.rs +++ b/runtime/moonbeam/src/governance/tracks.rs @@ -28,7 +28,7 @@ const fn permill(x: i32) -> sp_runtime::FixedI64 { } use pallet_referenda::Curve; -const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] = [ +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 6] = [ ( 0, pallet_referenda::TrackInfo { @@ -111,6 +111,20 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), }, ), + ( + 5, + pallet_referenda::TrackInfo { + name: "fast_general_admin", + max_deciding: 10, + decision_deposit: 100 * GLMR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(5, 14, percent(1), percent(0), percent(50)), + }, + ), ]; pub struct TracksInfo; diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index d4646f650d..7042ac8f9f 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -72,7 +72,7 @@ use sp_std::{ use orml_traits::parameter_type_with_key; -use crate::governance::referenda::GeneralAdminOrRoot; +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { // The network Id of the relay @@ -651,6 +651,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = AbsoluteAndRelativeReserve; type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; type MaxHrmpFee = xcm_builder::Case; } diff --git a/runtime/moonbeam/tests/xcm_mock/parachain.rs b/runtime/moonbeam/tests/xcm_mock/parachain.rs index b1e0e16728..3ed310daa4 100644 --- a/runtime/moonbeam/tests/xcm_mock/parachain.rs +++ b/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -800,6 +800,7 @@ impl pallet_xcm_transactor::Config for Runtime { type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; type MaxHrmpFee = xcm_builder::Case; } From 64d1e093f2b1ae91bbf7a93186c0569f2ce84824 Mon Sep 17 00:00:00 2001 From: noandrea Date: Fri, 5 Apr 2024 13:20:20 -0700 Subject: [PATCH 5/7] allow HRMPOpenOrigin to accept HRMP channels --- pallets/xcm-transactor/src/lib.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index f140e89b26..8d24809ba1 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -869,16 +869,12 @@ pub mod pallet { // SetAppendix(RefundSurplus, DepositAsset(sov account)) // Transact - if let HrmpOperation::InitOpen(_) = &action { - >::ensure_origin( - origin, - )?; - } else { - T::HrmpManipulatorOrigin::ensure_origin(origin)?; - } - let call_bytes = match action.clone() { HrmpOperation::InitOpen(params) => { + // allowed from The HRMP Open origin + >::ensure_origin( + origin, + )?; Self::hrmp_encode_call(HrmpAvailableCalls::InitOpenChannel( params.para_id, params.proposed_max_capacity, @@ -886,18 +882,26 @@ pub mod pallet { )) } HrmpOperation::Accept { para_id } => { + // allowed from The HRMP Open origin + >::ensure_origin( + origin, + )?; Self::hrmp_encode_call(HrmpAvailableCalls::AcceptOpenChannel(para_id)) } HrmpOperation::Close(close_params) => { + T::HrmpManipulatorOrigin::ensure_origin(origin)?; Self::hrmp_encode_call(HrmpAvailableCalls::CloseChannel(close_params)) } HrmpOperation::Cancel { channel_id, open_requests, - } => Self::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest( - channel_id, - open_requests, - )), + } => { + T::HrmpManipulatorOrigin::ensure_origin(origin)?; + Self::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest( + channel_id, + open_requests, + )) + } } .map_err(|_| Error::::HrmpHandlerNotImplemented)?; From 61eb12ef49cdd69240047458561d4308b51eb467 Mon Sep 17 00:00:00 2001 From: noandrea Date: Mon, 8 Apr 2024 00:59:36 -0700 Subject: [PATCH 6/7] separate permission checks from action processing --- pallets/xcm-transactor/src/lib.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index 8d24809ba1..f94cba1630 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -869,12 +869,21 @@ pub mod pallet { // SetAppendix(RefundSurplus, DepositAsset(sov account)) // Transact - let call_bytes = match action.clone() { - HrmpOperation::InitOpen(params) => { - // allowed from The HRMP Open origin + // check permissions + match &action { + HrmpOperation::InitOpen(_) | HrmpOperation::Accept { .. } => { >::ensure_origin( origin, )?; + } + HrmpOperation::Close(_) | HrmpOperation::Cancel { .. } => { + T::HrmpManipulatorOrigin::ensure_origin(origin)?; + } + } + + // process action + let call_bytes = match action.clone() { + HrmpOperation::InitOpen(params) => { Self::hrmp_encode_call(HrmpAvailableCalls::InitOpenChannel( params.para_id, params.proposed_max_capacity, @@ -882,26 +891,18 @@ pub mod pallet { )) } HrmpOperation::Accept { para_id } => { - // allowed from The HRMP Open origin - >::ensure_origin( - origin, - )?; Self::hrmp_encode_call(HrmpAvailableCalls::AcceptOpenChannel(para_id)) } HrmpOperation::Close(close_params) => { - T::HrmpManipulatorOrigin::ensure_origin(origin)?; Self::hrmp_encode_call(HrmpAvailableCalls::CloseChannel(close_params)) } HrmpOperation::Cancel { channel_id, open_requests, - } => { - T::HrmpManipulatorOrigin::ensure_origin(origin)?; - Self::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest( - channel_id, - open_requests, - )) - } + } => Self::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest( + channel_id, + open_requests, + )), } .map_err(|_| Error::::HrmpHandlerNotImplemented)?; From 928a9058d3289371168e4a991b2891208b8df71e Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> Date: Tue, 9 Apr 2024 09:43:23 +0100 Subject: [PATCH 7/7] Update pallets/xcm-transactor/src/lib.rs Co-authored-by: Andrea Giacobino --- pallets/xcm-transactor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index f94cba1630..a6ba5b2024 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -149,7 +149,7 @@ pub mod pallet { // The origin that is allowed to manipulate (open, close, accept, cancel) an Hrmp channel type HrmpManipulatorOrigin: EnsureOrigin; - // The origin that is allowed to open an Hrmp channel + // The origin that is allowed to open and accept an Hrmp channel type HrmpOpenOrigin: EnsureOrigin; /// Convert `T::AccountId` to `Location`.