difftreelog
fix(xcm) improve denythentry, deny transact xcm
in: master
8 files changed
Cargo.lockdiffbeforeafterboth4571 "value-bag",4571 "value-bag",4572]4572]45734574[[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]457345834574[[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",runtime/common/config/xcm.rsdiffbeforeafterboth172 };172 };173}173}174175pub trait TryPass {176 fn try_pass<Call>(177 origin: &MultiLocation,178 message: &mut Xcm<Call>,179 ) -> Result<(), ()>;180}181182#[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 )* );191192 Ok(())193 }194}174195175pub 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 = message184 .0203 .0203/// 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>)205where224where206 Deny: ShouldExecute,225 Deny: TryPass,207 Allow: ShouldExecute;226 Allow: ShouldExecute;208227209impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>228impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>210where229where211 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}runtime/common/tests/xcm.rsdiffbeforeafterboth34}34}353536#[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`runtime/opal/Cargo.tomldiffbeforeafterboth462up-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" }464465################################################################################466# Other Dependencies467468impl-trait-for-tuples = "0.2.2"464469465################################################################################470################################################################################466# Dev Dependencies471# Dev Dependenciesruntime/quartz/Cargo.tomldiffbeforeafterboth470up-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" }472473################################################################################474# Other Dependencies475476impl-trait-for-tuples = "0.2.2"472477473################################################################################478################################################################################474# Dev Dependencies479# Dev Dependenciesruntime/quartz/src/xcm_config.rsdiffbeforeafterboth41};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};464647use up_common::{47use up_common::{939394// Allow xcm exchange only with locations in list94// Allow xcm exchange only with locations in list95pub 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<(), ()> {103101104 // Check if deposit or transfer belongs to allowed parachains102 // Check if deposit or transfer belongs to allowed parachains126}124}127125128pub 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 executionruntime/unique/Cargo.tomldiffbeforeafterboth462up-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" }464465################################################################################466# Other Dependencies467468impl-trait-for-tuples = "0.2.2"464469465################################################################################470################################################################################466# Dev Dependencies471# Dev Dependenciesruntime/unique/src/xcm_config.rsdiffbeforeafterboth41};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};464647use up_common::{47use up_common::{6767686869pub 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 execution9810099// Allow xcm exchange only with locations in list101// Allow xcm exchange only with locations in list100pub 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<(), ()> {108108109 // Check if deposit or transfer belongs to allowed parachains109 // Check if deposit or transfer belongs to allowed parachains