diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index 0dd8ecd0cf..a6ba5b2024 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 and accept an Hrmp channel + type HrmpOpenOrigin: EnsureOrigin; + /// Convert `T::AccountId` to `Location`. type AccountIdToLocation: Convert; @@ -862,7 +868,20 @@ pub mod pallet { // BuyExecution // SetAppendix(RefundSurplus, DepositAsset(sov account)) // Transact - T::HrmpManipulatorOrigin::ensure_origin(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( 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 = (); } 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; } 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; } 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; }