Skip to content

Commit

Permalink
Fast General Admin Track for opening HRMP channels (#2736)
Browse files Browse the repository at this point in the history
* Add new origin for opening a Hrmp channel

* update Moonbase to support the HrmpOpen origin

* add new track fast_general_admin to open hrmp channels on Moonriver

* add new track fast_general_admin to open new hrmp channels on Moonbeam

* allow HRMPOpenOrigin to accept HRMP channels

* separate permission checks from action processing

* Update pallets/xcm-transactor/src/lib.rs

Co-authored-by: Andrea Giacobino <no.andrea@gmail.com>

---------

Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
  • Loading branch information
noandrea and RomarQ committed Apr 10, 2024
1 parent 56cccd0 commit 0430625
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 13 deletions.
25 changes: 22 additions & 3 deletions pallets/xcm-transactor/src/lib.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -143,9 +146,12 @@ pub mod pallet {
// The origin that is allowed to register derivative address indices
type DerivativeAddressRegistrationOrigin: EnsureOrigin<Self::RuntimeOrigin>;

// 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<Self::RuntimeOrigin>;

// The origin that is allowed to open and accept an Hrmp channel
type HrmpOpenOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Convert `T::AccountId` to `Location`.
type AccountIdToLocation: Convert<Self::AccountId, Location>;

Expand Down Expand Up @@ -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 { .. } => {
<EitherOfDiverse<T::HrmpManipulatorOrigin, T::HrmpOpenOrigin>>::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(
Expand Down
1 change: 1 addition & 0 deletions pallets/xcm-transactor/src/mock.rs
Expand Up @@ -396,6 +396,7 @@ impl Config for Test {
type ReserveProvider = orml_traits::location::RelativeReserveProvider;
type WeightInfo = ();
type HrmpManipulatorOrigin = EnsureRoot<u64>;
type HrmpOpenOrigin = EnsureRoot<u64>;
type MaxHrmpFee = MaxHrmpRelayFee;
}

Expand Down
1 change: 1 addition & 0 deletions precompiles/relay-encoder/src/mock.rs
Expand Up @@ -309,6 +309,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = orml_traits::location::RelativeReserveProvider;
type WeightInfo = ();
type HrmpManipulatorOrigin = frame_system::EnsureRoot<AccountId>;
type HrmpOpenOrigin = frame_system::EnsureRoot<AccountId>;
type MaxHrmpFee = ();
}

Expand Down
1 change: 1 addition & 0 deletions precompiles/xcm-transactor/src/mock.rs
Expand Up @@ -334,6 +334,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = orml_traits::location::RelativeReserveProvider;
type WeightInfo = ();
type HrmpManipulatorOrigin = frame_system::EnsureRoot<AccountId>;
type HrmpOpenOrigin = frame_system::EnsureRoot<AccountId>;
type MaxHrmpFee = ();
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbase/src/governance/referenda.rs
Expand Up @@ -51,8 +51,8 @@ parameter_types! {

pub type GeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::GeneralAdmin>;

/// The policy allows for Root, GeneralAdmin, or FastGeneralAdmin.
pub type FastGeneralAdminOrRoot = EitherOf<GeneralAdminOrRoot, origins::FastGeneralAdmin>;
/// The policy allows for Root or FastGeneralAdmin.
pub type FastGeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::FastGeneralAdmin>;

impl custom_origins::Config for Runtime {}

Expand Down
5 changes: 3 additions & 2 deletions runtime/moonbase/src/xcm_config.rs
Expand Up @@ -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
Expand Down Expand Up @@ -658,7 +658,8 @@ impl pallet_xcm_transactor::Config for Runtime {
type AssetTransactor = AssetTransactors;
type ReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo<Runtime>;
type HrmpManipulatorOrigin = FastGeneralAdminOrRoot;
type HrmpManipulatorOrigin = GeneralAdminOrRoot;
type HrmpOpenOrigin = FastGeneralAdminOrRoot;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/tests/xcm_mock/parachain.rs
Expand Up @@ -840,6 +840,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = ();
type HrmpManipulatorOrigin = EnsureRoot<AccountId>;
type HrmpOpenOrigin = EnsureRoot<AccountId>;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down
5 changes: 4 additions & 1 deletion runtime/moonbeam/src/governance/origins.rs
Expand Up @@ -41,6 +41,8 @@ pub mod custom_origins {
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Fast General Admin
FastGeneralAdmin,
}

macro_rules! decl_unit_ensures {
Expand Down Expand Up @@ -77,6 +79,7 @@ pub mod custom_origins {
ReferendumCanceller,
ReferendumKiller,
WhitelistedCaller,
GeneralAdmin
GeneralAdmin,
FastGeneralAdmin,
);
}
2 changes: 2 additions & 0 deletions runtime/moonbeam/src/governance/referenda.rs
Expand Up @@ -50,6 +50,8 @@ parameter_types! {

// Origin for general admin or root
pub type GeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::GeneralAdmin>;
// The policy allows for Root or FastGeneralAdmin.
pub type FastGeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::FastGeneralAdmin>;

impl custom_origins::Config for Runtime {}

Expand Down
16 changes: 15 additions & 1 deletion runtime/moonbeam/src/governance/tracks.rs
Expand Up @@ -28,7 +28,7 @@ const fn permill(x: i32) -> sp_runtime::FixedI64 {
}

use pallet_referenda::Curve;
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 5] = [
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 6] = [
(
0,
pallet_referenda::TrackInfo {
Expand Down Expand Up @@ -111,6 +111,20 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 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;
Expand Down
3 changes: 2 additions & 1 deletion runtime/moonbeam/src/xcm_config.rs
Expand Up @@ -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
Expand Down Expand Up @@ -651,6 +651,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo<Runtime>;
type HrmpManipulatorOrigin = GeneralAdminOrRoot;
type HrmpOpenOrigin = FastGeneralAdminOrRoot;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/tests/xcm_mock/parachain.rs
Expand Up @@ -800,6 +800,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = ();
type HrmpManipulatorOrigin = EnsureRoot<AccountId>;
type HrmpOpenOrigin = EnsureRoot<AccountId>;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down
5 changes: 4 additions & 1 deletion runtime/moonriver/src/governance/origins.rs
Expand Up @@ -40,6 +40,8 @@ pub mod custom_origins {
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Fast General Admin
FastGeneralAdmin,
}

macro_rules! decl_unit_ensures {
Expand Down Expand Up @@ -76,6 +78,7 @@ pub mod custom_origins {
ReferendumCanceller,
ReferendumKiller,
WhitelistedCaller,
GeneralAdmin
GeneralAdmin,
FastGeneralAdmin,
);
}
2 changes: 2 additions & 0 deletions runtime/moonriver/src/governance/referenda.rs
Expand Up @@ -50,6 +50,8 @@ parameter_types! {

// Origin for general admin or root
pub type GeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::GeneralAdmin>;
// The policy allows for Root or FastGeneralAdmin.
pub type FastGeneralAdminOrRoot = EitherOf<EnsureRoot<AccountId>, origins::FastGeneralAdmin>;

impl custom_origins::Config for Runtime {}

Expand Down
16 changes: 15 additions & 1 deletion runtime/moonriver/src/governance/tracks.rs
Expand Up @@ -28,7 +28,7 @@ const fn permill(x: i32) -> sp_runtime::FixedI64 {
}

use pallet_referenda::Curve;
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 5] = [
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 6] = [
(
0,
pallet_referenda::TrackInfo {
Expand Down Expand Up @@ -111,6 +111,20 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 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;
Expand Down
3 changes: 2 additions & 1 deletion runtime/moonriver/src/xcm_config.rs
Expand Up @@ -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
Expand Down Expand Up @@ -664,6 +664,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo<Runtime>;
type HrmpManipulatorOrigin = GeneralAdminOrRoot;
type HrmpOpenOrigin = FastGeneralAdminOrRoot;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/tests/xcm_mock/parachain.rs
Expand Up @@ -805,6 +805,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type WeightInfo = ();
type HrmpManipulatorOrigin = EnsureRoot<AccountId>;
type HrmpOpenOrigin = EnsureRoot<AccountId>;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
}

Expand Down

0 comments on commit 0430625

Please sign in to comment.