Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rococo: configure MQ pallet
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Apr 11, 2023
1 parent 099e2f0 commit b9c15e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ impl pallet_message_queue::Config for Runtime {
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type DiscardOverweightOrigin = xcm_config::MqDiscardOverweightOrigin;
type QueueChangeHandler = ParaInclusion;
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}
Expand Down
47 changes: 44 additions & 3 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ use super::{
};
use frame_support::{
match_types, parameter_types,
traits::{Contains, Everything, Nothing},
traits::{
AsEnsureOriginWithContains, Contains, EitherOfWithArg, EnsureOriginWithArg, Everything,
Nothing,
},
weights::Weight,
};
use frame_system::EnsureRoot;
use frame_system::{ensure_signed, EnsureRoot};
use runtime_common::{crowdloan, paras_registrar, xcm_sender, ToAuthor};
use runtime_parachains::inclusion::AggregateMessageOrigin;
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand All @@ -37,7 +41,10 @@ use xcm_builder::{
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
use xcm_executor::{
traits::{Convert, WithOriginFilter},
XcmExecutor,
};

parameter_types! {
pub const TokenLocation: MultiLocation = Here.into_location();
Expand Down Expand Up @@ -142,6 +149,40 @@ pub type Barrier = (
>,
);

/// Either root for all queues or a parachain for its own queue.
pub type MqDiscardOverweightOrigin = EitherOfWithArg<
AsEnsureOriginWithContains<EnsureRoot<AccountId>, Everything>,
ParaAsUmpQueueManager<LocationConverter>,
>;

/// Each parachain can control its own UMP queue through its sovereign account.
pub struct ParaAsUmpQueueManager<ParaToSovereign>(core::marker::PhantomData<ParaToSovereign>);
impl<ParaToSovereign> EnsureOriginWithArg<RuntimeOrigin, AggregateMessageOrigin>
for ParaAsUmpQueueManager<ParaToSovereign>
where
ParaToSovereign: Convert<MultiLocation, AccountId>,
{
type Success = ();

fn try_origin(
o: RuntimeOrigin,
queue: &AggregateMessageOrigin,
) -> Result<Self::Success, RuntimeOrigin> {
let para: ParaId = match queue {
AggregateMessageOrigin::Ump(para) => *para,
};
let owner = Junction::Parachain(para.into());
let sovereign = ParaToSovereign::convert_ref(&owner.into()).map_err(|()| o.clone())?; // FAIL-CI remove clones

let signer = ensure_signed(o.clone()).map_err(|_| o.clone())?; // TODO why no `ensure_signed_by`?
if signer == sovereign {
Ok(())
} else {
Err(o)
}
}
}

/// A call filter for the XCM Transact instruction. This is a temporary measure until we
/// properly account for proof size weights.
///
Expand Down

0 comments on commit b9c15e8

Please sign in to comment.