difftreelog
feat(xcm) move DenyThenTry to common, add DenyTransact
in: master
4 files changed
runtime/common/config/xcm.rsdiffbeforeafterboth34 AssetId::{Concrete},34 AssetId::{Concrete},35 Fungibility::Fungible as XcmFungible,35 Fungibility::Fungible as XcmFungible,36 MultiAsset, Error as XcmError,36 MultiAsset, Error as XcmError,37 Instruction, Xcm,37};38};38use xcm_builder::{39use xcm_builder::{39 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,40 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,45use xcm_executor::{Config, XcmExecutor, Assets};46use xcm_executor::{Config, XcmExecutor, Assets};46use xcm_executor::traits::{47use xcm_executor::traits::{47 Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation,48 Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation,49 ShouldExecute,48};50};49use pallet_foreing_assets::{51use pallet_foreing_assets::{50 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,171 };173 };172}174}173175174/*176pub struct DenyTransact;175pub type Barrier = (177impl ShouldExecute for DenyTransact {176 TakeWeightCredit,178 fn should_execute<Call>(177 AllowTopLevelPaidExecutionFrom<Everything>,179 _origin: &MultiLocation,178 // ^^^ Parent & its unit plurality gets free execution180 message: &mut Xcm<Call>,179);181 _max_weight: Weight,180 */182 _weight_credit: &mut Weight,183 ) -> Result<(), ()> {184 let transact_inst = message.0.iter()185 .find(|inst| matches![inst, Instruction::Transact { .. }]);186187 match transact_inst {188 Some(_) => {189 log::warn!(190 target: "xcm::barrier",191 "transact XCM rejected"192 );193194 Err(())195 },196 None => Ok(())197 }198 }199}200201/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.202/// If it passes the Deny, and matches one of the Allow cases then it is let through.203pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)204 where205 Deny: ShouldExecute,206 Allow: ShouldExecute;207208impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>209 where210 Deny: ShouldExecute,211 Allow: ShouldExecute,212{213 fn should_execute<Call>(214 origin: &MultiLocation,215 message: &mut Xcm<Call>,216 max_weight: Weight,217 weight_credit: &mut Weight,218 ) -> Result<(), ()> {219 Deny::should_execute(origin, message, max_weight, weight_credit)?;220 Allow::should_execute(origin, message, max_weight, weight_credit)221 }222}181223182pub struct UsingOnlySelfCurrencyComponents<224pub struct UsingOnlySelfCurrencyComponents<183 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,225 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,runtime/opal/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/opal/src/xcm_config.rs
+++ b/runtime/opal/src/xcm_config.rs
@@ -301,13 +301,16 @@
}
}
-pub type Barrier = (
- TakeWeightCredit,
- AllowTopLevelPaidExecutionFrom<Everything>,
- AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
- // ^^^ Parent & its unit plurality gets free execution
- AllowAllDebug,
-);
+pub type Barrier = DenyThenTry<
+ DenyTransact,
+ (
+ TakeWeightCredit,
+ AllowTopLevelPaidExecutionFrom<Everything>,
+ AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
+ // ^^^ Parent & its unit plurality gets free execution
+ AllowAllDebug,
+ )
+>;
pub struct AllAsset;
impl FilterAssetLocation for AllAsset {
runtime/quartz/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/quartz/src/xcm_config.rs
+++ b/runtime/quartz/src/xcm_config.rs
@@ -76,29 +76,6 @@
};
}
-/// Deny executing the XCM 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>(PhantomData<Deny>, PhantomData<Allow>)
- where
- Deny: ShouldExecute,
- Allow: ShouldExecute;
-
-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<(), ()> {
- Deny::should_execute(origin, message, max_weight, weight_credit)?;
- Allow::should_execute(origin, message, max_weight, weight_credit)
- }
-}
-
pub fn get_allowed_locations() -> Vec<MultiLocation> {
vec![
// Self location
@@ -151,6 +128,7 @@
pub type Barrier = DenyThenTry<
DenyExchangeWithUnknownLocation,
(
+ DenyTransact,
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
runtime/unique/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/unique/src/xcm_config.rs
+++ b/runtime/unique/src/xcm_config.rs
@@ -69,6 +69,7 @@
pub type Barrier = DenyThenTry<
DenyExchangeWithUnknownLocation,
(
+ DenyTransact,
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
@@ -93,27 +94,6 @@
// Self parachain address
MultiLocation { parents: 1, interior: X1(Parachain(ParachainInfo::get().into())) },
]
-}
-
-pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
- where
- Deny: ShouldExecute,
- Allow: ShouldExecute;
-
-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<(), ()> {
- Deny::should_execute(origin, message, max_weight, weight_credit)?;
- Allow::should_execute(origin, message, max_weight, weight_credit)
- }
}
// Allow xcm exchange only with locations in list