git.delta.rocks / unique-network / refs/commits / 5a619a936664

difftreelog

fix(xcm) improve denythentry, deny transact xcm

Daniel Shiposha2022-08-30parent: #247c0b0.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
4571 "value-bag",4571 "value-bag",
4572]4572]
4573
4574[[package]]
4575name = "logtest"
4576version = "2.0.0"
4577source = "registry+https://github.com/rust-lang/crates.io-index"
4578checksum = "eb3e43a8657c1d64516dcc9db8ca03826a4aceaf89d5ce1b37b59f6ff0e43026"
4579dependencies = [
4580 "lazy_static",
4581 "log",
4582]
45734583
4574[[package]]4584[[package]]
4575name = "lru"4585name = "lru"
5148 "frame-system-rpc-runtime-api",5158 "frame-system-rpc-runtime-api",
5149 "frame-try-runtime",5159 "frame-try-runtime",
5150 "hex-literal",5160 "hex-literal",
5161 "impl-trait-for-tuples",
5151 "log",5162 "log",
5163 "logtest",
5152 "orml-tokens",5164 "orml-tokens",
5153 "orml-traits",5165 "orml-traits",
5154 "orml-vesting",5166 "orml-vesting",
8466 "frame-system-rpc-runtime-api",8478 "frame-system-rpc-runtime-api",
8467 "frame-try-runtime",8479 "frame-try-runtime",
8468 "hex-literal",8480 "hex-literal",
8481 "impl-trait-for-tuples",
8469 "log",8482 "log",
8483 "logtest",
8470 "orml-tokens",8484 "orml-tokens",
8471 "orml-traits",8485 "orml-traits",
8472 "orml-vesting",8486 "orml-vesting",
12206source = "registry+https://github.com/rust-lang/crates.io-index"12220source = "registry+https://github.com/rust-lang/crates.io-index"
12207checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"12221checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
12208dependencies = [12222dependencies = [
12209 "cfg-if 0.1.10",12223 "cfg-if 1.0.0",
12210 "digest 0.10.3",12224 "digest 0.10.3",
12211 "rand 0.8.5",12225 "rand 0.8.5",
12212 "static_assertions",12226 "static_assertions",
12459 "frame-system-rpc-runtime-api",12473 "frame-system-rpc-runtime-api",
12460 "frame-try-runtime",12474 "frame-try-runtime",
12461 "hex-literal",12475 "hex-literal",
12476 "impl-trait-for-tuples",
12462 "log",12477 "log",
12478 "logtest",
12463 "orml-tokens",12479 "orml-tokens",
12464 "orml-traits",12480 "orml-traits",
12465 "orml-vesting",12481 "orml-vesting",
modifiedruntime/common/config/xcm.rsdiffbeforeafterboth
172 };172 };
173}173}
174
175pub trait TryPass {
176 fn try_pass<Call>(
177 origin: &MultiLocation,
178 message: &mut Xcm<Call>,
179 ) -> Result<(), ()>;
180}
181
182#[impl_trait_for_tuples::impl_for_tuples(30)]
183impl TryPass for Tuple {
184 fn try_pass<Call>(
185 origin: &MultiLocation,
186 message: &mut Xcm<Call>,
187 ) -> Result<(), ()> {
188 for_tuples!( #(
189 Tuple::try_pass(origin, message)?;
190 )* );
191
192 Ok(())
193 }
194}
174195
175pub struct DenyTransact;196pub struct DenyTransact;
176impl ShouldExecute for DenyTransact {197impl TryPass for DenyTransact {
177 fn should_execute<Call>(198 fn try_pass<Call>(
178 _origin: &MultiLocation,199 _origin: &MultiLocation,
179 message: &mut Xcm<Call>,200 message: &mut Xcm<Call>,
180 _max_weight: Weight,
181 _weight_credit: &mut Weight,
182 ) -> Result<(), ()> {201 ) -> Result<(), ()> {
183 let transact_inst = message202 let transact_inst = message
184 .0203 .0
203/// If it passes the Deny, and matches one of the Allow cases then it is let through.222/// If it passes the Deny, and matches one of the Allow cases then it is let through.
204pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)223pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
205where224where
206 Deny: ShouldExecute,225 Deny: TryPass,
207 Allow: ShouldExecute;226 Allow: ShouldExecute;
208227
209impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>228impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
210where229where
211 Deny: ShouldExecute,230 Deny: TryPass,
212 Allow: ShouldExecute,231 Allow: ShouldExecute,
213{232{
214 fn should_execute<Call>(233 fn should_execute<Call>(
217 max_weight: Weight,236 max_weight: Weight,
218 weight_credit: &mut Weight,237 weight_credit: &mut Weight,
219 ) -> Result<(), ()> {238 ) -> Result<(), ()> {
220 Deny::should_execute(origin, message, max_weight, weight_credit)?;239 Deny::try_pass(origin, message)?;
221 Allow::should_execute(origin, message, max_weight, weight_credit)240 Allow::should_execute(origin, message, max_weight, weight_credit)
222 }241 }
223}242}
modifiedruntime/common/tests/xcm.rsdiffbeforeafterboth
34}34}
3535
36#[test]36#[test]
37fn xcm_barrier_does_not_allow_transact() {37fn xcm_barrier_denies_transact() {
38 // We have a `AllowTopLevelPaidExecutionFrom` barrier,38 // We have a `AllowTopLevelPaidExecutionFrom` barrier,
39 // so an XCM program should start from one of the following commands: 39 // so an XCM program should start from one of the following commands:
40 // * `WithdrawAsset`40 // * `WithdrawAsset`
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
462up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }462up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }
463pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }463pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
464
465################################################################################
466# Other Dependencies
467
468impl-trait-for-tuples = "0.2.2"
464469
465################################################################################470################################################################################
466# Dev Dependencies471# Dev Dependencies
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
470up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }470up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }
471pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }471pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
472
473################################################################################
474# Other Dependencies
475
476impl-trait-for-tuples = "0.2.2"
472477
473################################################################################478################################################################################
474# Dev Dependencies479# Dev Dependencies
modifiedruntime/quartz/src/xcm_config.rsdiffbeforeafterboth
41};41};
42use xcm_executor::{42use xcm_executor::{
43 {Config, XcmExecutor},43 {Config, XcmExecutor},
44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
45};45};
4646
47use up_common::{47use up_common::{
9393
94// Allow xcm exchange only with locations in list94// Allow xcm exchange only with locations in list
95pub struct DenyExchangeWithUnknownLocation;95pub struct DenyExchangeWithUnknownLocation;
96impl ShouldExecute for DenyExchangeWithUnknownLocation {96impl TryPass for DenyExchangeWithUnknownLocation {
97 fn should_execute<Call>(97 fn try_pass<Call>(
98 origin: &MultiLocation,98 origin: &MultiLocation,
99 message: &mut Xcm<Call>,99 message: &mut Xcm<Call>,
100 _max_weight: Weight,
101 _weight_credit: &mut Weight,
102 ) -> Result<(), ()> {100 ) -> Result<(), ()> {
103101
104 // Check if deposit or transfer belongs to allowed parachains102 // Check if deposit or transfer belongs to allowed parachains
126}124}
127125
128pub type Barrier = DenyThenTry<126pub type Barrier = DenyThenTry<
127 (
128 DenyTransact,
129 DenyExchangeWithUnknownLocation,129 DenyExchangeWithUnknownLocation,
130 ),
130 (131 (
131 DenyTransact,
132 TakeWeightCredit,132 TakeWeightCredit,
133 AllowTopLevelPaidExecutionFrom<Everything>,133 AllowTopLevelPaidExecutionFrom<Everything>,
134 // Parent and its exec plurality get free execution134 // Parent and its exec plurality get free execution
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
462up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }462up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }
463pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }463pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
464
465################################################################################
466# Other Dependencies
467
468impl-trait-for-tuples = "0.2.2"
464469
465################################################################################470################################################################################
466# Dev Dependencies471# Dev Dependencies
modifiedruntime/unique/src/xcm_config.rsdiffbeforeafterboth
41};41};
42use xcm_executor::{42use xcm_executor::{
43 {Config, XcmExecutor},43 {Config, XcmExecutor},
44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
45};45};
4646
47use up_common::{47use up_common::{
6767
6868
69pub type Barrier = DenyThenTry<69pub type Barrier = DenyThenTry<
70 (
71 DenyTransact,
70 DenyExchangeWithUnknownLocation,72 DenyExchangeWithUnknownLocation,
73 ),
71 (74 (
72 DenyTransact,
73 TakeWeightCredit,75 TakeWeightCredit,
74 AllowTopLevelPaidExecutionFrom<Everything>,76 AllowTopLevelPaidExecutionFrom<Everything>,
75 // Parent and its exec plurality get free execution77 // Parent and its exec plurality get free execution
98100
99// Allow xcm exchange only with locations in list101// Allow xcm exchange only with locations in list
100pub struct DenyExchangeWithUnknownLocation;102pub struct DenyExchangeWithUnknownLocation;
101impl ShouldExecute for DenyExchangeWithUnknownLocation {103impl TryPass for DenyExchangeWithUnknownLocation {
102 fn should_execute<Call>(104 fn try_pass<Call>(
103 origin: &MultiLocation,105 origin: &MultiLocation,
104 message: &mut Xcm<Call>,106 message: &mut Xcm<Call>,
105 _max_weight: Weight,
106 _weight_credit: &mut Weight,
107 ) -> Result<(), ()> {107 ) -> Result<(), ()> {
108108
109 // Check if deposit or transfer belongs to allowed parachains109 // Check if deposit or transfer belongs to allowed parachains