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

Deny using relay chain for reserve transfers #1169

Merged
merged 16 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions polkadot-parachains/canvas-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use parachains_common::{DenyThenTry, IsReserveTransferToRelayChain};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -117,16 +118,19 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
);
pub type Barrier = DenyThenTry<
IsReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down
65 changes: 65 additions & 0 deletions polkadot-parachains/parachains-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@

pub mod impls;
pub use constants::*;
use core::marker::PhantomData;
use frame_support::weights::Weight;
pub use opaque::*;
pub use types::*;
use xcm::{
opaque::v2::prelude::{DepositReserveAsset, TransferReserveAsset},
gilescope marked this conversation as resolved.
Show resolved Hide resolved
v2::{Junctions, MultiLocation, Xcm},
};
use xcm_executor::traits::ShouldExecute;
/// Common types of parachains.
mod types {
use sp_runtime::traits::{IdentifyAccount, Verify};
Expand Down Expand Up @@ -109,3 +116,61 @@ pub mod opaque {
/// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>;
}

//TODO: move DenyThenTry to polkadot's xcm module.
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
pub struct DenyThenTry<Deny, Allow>
where
Deny: ShouldExecute,
Allow: ShouldExecute,
{
_deny: PhantomData<Deny>,
_allow: PhantomData<Allow>,
gilescope marked this conversation as resolved.
Show resolved Hide resolved
}

impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
where
Deny: ShouldExecute,
Allow: ShouldExecute,
{
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
if Deny::should_execute(origin, message, max_weight, weight_credit).is_ok() {
gilescope marked this conversation as resolved.
Show resolved Hide resolved
return Err(())
}
Allow::should_execute(origin, message, max_weight, weight_credit)
}
}

// See issue #5233
pub struct IsReserveTransferToRelayChain;
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
impl ShouldExecute for IsReserveTransferToRelayChain {
fn should_execute<Call>(
_origin: &MultiLocation,
message: &mut Xcm<Call>,
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
matches!(
inst,
DepositReserveAsset {
dest: MultiLocation { parents: 1, interior: Junctions::Here },
..
} | TransferReserveAsset {
dest: MultiLocation { parents: 1, interior: Junctions::Here },
..
}
)
}) {
Ok(())
} else {
Err(())
}
}
}
25 changes: 14 additions & 11 deletions polkadot-parachains/statemine/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
weights::Weight,
};
use pallet_xcm::XcmPassthrough;
use parachains_common::impls::ToStakingPot;
use parachains_common::{impls::ToStakingPot, DenyThenTry, IsReserveTransferToRelayChain};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -139,16 +139,19 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
);
pub type Barrier = DenyThenTry<
IsReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down
25 changes: 14 additions & 11 deletions polkadot-parachains/statemint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
weights::Weight,
};
use pallet_xcm::XcmPassthrough;
use parachains_common::impls::ToStakingPot;
use parachains_common::{impls::ToStakingPot, DenyThenTry, IsReserveTransferToRelayChain};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -139,16 +139,19 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
);
pub type Barrier = DenyThenTry<
IsReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down
25 changes: 14 additions & 11 deletions polkadot-parachains/westmint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
weights::Weight,
};
use pallet_xcm::XcmPassthrough;
use parachains_common::impls::ToStakingPot;
use parachains_common::{impls::ToStakingPot, DenyThenTry, IsReserveTransferToRelayChain};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -135,16 +135,19 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
);
pub type Barrier = DenyThenTry<
IsReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down