git.delta.rocks / unique-network / refs/commits / 8c9b07c4c9bd

difftreelog

feat(xcm) move DenyThenTry to common, add DenyTransact

Daniel Shiposha2022-08-29parent: #6396c5b.patch.diff
in: master

4 files changed

modifiedruntime/common/config/xcm.rsdiffbeforeafterboth
34 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}
173175
174/*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 { .. }]);
186
187 match transact_inst {
188 Some(_) => {
189 log::warn!(
190 target: "xcm::barrier",
191 "transact XCM rejected"
192 );
193
194 Err(())
195 },
196 None => Ok(())
197 }
198 }
199}
200
201/// 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 where
205 Deny: ShouldExecute,
206 Allow: ShouldExecute;
207
208impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
209 where
210 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}
181223
182pub struct UsingOnlySelfCurrencyComponents<224pub struct UsingOnlySelfCurrencyComponents<
183 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,225 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
modifiedruntime/opal/src/xcm_config.rsdiffbeforeafterboth
301 }301 }
302}302}
303303
304pub type Barrier = (304pub type Barrier = DenyThenTry<
305 DenyTransact,
306 (
305 TakeWeightCredit,307 TakeWeightCredit,
306 AllowTopLevelPaidExecutionFrom<Everything>,308 AllowTopLevelPaidExecutionFrom<Everything>,
307 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,309 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
308 // ^^^ Parent & its unit plurality gets free execution310 // ^^^ Parent & its unit plurality gets free execution
309 AllowAllDebug,311 AllowAllDebug,
310);312 )
313>;
311314
312pub struct AllAsset;315pub struct AllAsset;
313impl FilterAssetLocation for AllAsset {316impl FilterAssetLocation for AllAsset {
modifiedruntime/quartz/src/xcm_config.rsdiffbeforeafterboth
76 };76 };
77}77}
78
79/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.
80/// If it passes the Deny, and matches one of the Allow cases then it is let through.
81pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
82 where
83 Deny: ShouldExecute,
84 Allow: ShouldExecute;
85
86impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
87 where
88 Deny: ShouldExecute,
89 Allow: ShouldExecute,
90{
91 fn should_execute<Call>(
92 origin: &MultiLocation,
93 message: &mut Xcm<Call>,
94 max_weight: Weight,
95 weight_credit: &mut Weight,
96 ) -> Result<(), ()> {
97 Deny::should_execute(origin, message, max_weight, weight_credit)?;
98 Allow::should_execute(origin, message, max_weight, weight_credit)
99 }
100}
10178
102pub fn get_allowed_locations() -> Vec<MultiLocation> {79pub fn get_allowed_locations() -> Vec<MultiLocation> {
103 vec![80 vec![
151pub type Barrier = DenyThenTry<128pub type Barrier = DenyThenTry<
152 DenyExchangeWithUnknownLocation,129 DenyExchangeWithUnknownLocation,
153 (130 (
131 DenyTransact,
154 TakeWeightCredit,132 TakeWeightCredit,
155 AllowTopLevelPaidExecutionFrom<Everything>,133 AllowTopLevelPaidExecutionFrom<Everything>,
156 // Parent and its exec plurality get free execution134 // Parent and its exec plurality get free execution
modifiedruntime/unique/src/xcm_config.rsdiffbeforeafterboth
69pub type Barrier = DenyThenTry<69pub type Barrier = DenyThenTry<
70 DenyExchangeWithUnknownLocation,70 DenyExchangeWithUnknownLocation,
71 (71 (
72 DenyTransact,
72 TakeWeightCredit,73 TakeWeightCredit,
73 AllowTopLevelPaidExecutionFrom<Everything>,74 AllowTopLevelPaidExecutionFrom<Everything>,
74 // Parent and its exec plurality get free execution75 // Parent and its exec plurality get free execution
95 ]96 ]
96}97}
97
98pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
99 where
100 Deny: ShouldExecute,
101 Allow: ShouldExecute;
102
103impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
104 where
105 Deny: ShouldExecute,
106 Allow: ShouldExecute,
107{
108 fn should_execute<Call>(
109 origin: &MultiLocation,
110 message: &mut Xcm<Call>,
111 max_weight: Weight,
112 weight_credit: &mut Weight,
113 ) -> Result<(), ()> {
114 Deny::should_execute(origin, message, max_weight, weight_credit)?;
115 Allow::should_execute(origin, message, max_weight, weight_credit)
116 }
117}
11898
119// Allow xcm exchange only with locations in list99// Allow xcm exchange only with locations in list
120pub struct DenyExchangeWithUnknownLocation;100pub struct DenyExchangeWithUnknownLocation;