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
--- a/runtime/common/config/xcm.rs
+++ b/runtime/common/config/xcm.rs
@@ -172,13 +172,32 @@
 	};
 }
 
+pub trait TryPass {
+	fn try_pass<Call>(
+		origin: &MultiLocation,
+		message: &mut Xcm<Call>,
+	) -> Result<(), ()>;
+}
+
+#[impl_trait_for_tuples::impl_for_tuples(30)]
+impl TryPass for Tuple {
+	fn try_pass<Call>(
+		origin: &MultiLocation,
+		message: &mut Xcm<Call>,
+	)  -> Result<(), ()> {
+		for_tuples!( #(
+			Tuple::try_pass(origin, message)?;
+		)* );
+
+		Ok(())
+	}
+}
+
 pub struct DenyTransact;
-impl ShouldExecute for DenyTransact {
-	fn should_execute<Call>(
+impl TryPass for DenyTransact {
+	fn try_pass<Call>(
 		_origin: &MultiLocation,
 		message: &mut Xcm<Call>,
-		_max_weight: Weight,
-		_weight_credit: &mut Weight,
 	) -> Result<(), ()> {
 		let transact_inst = message
 			.0
@@ -203,12 +222,12 @@
 /// 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,
+	Deny: TryPass,
 	Allow: ShouldExecute;
 
 impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
 where
-	Deny: ShouldExecute,
+	Deny: TryPass,
 	Allow: ShouldExecute,
 {
 	fn should_execute<Call>(
@@ -217,7 +236,7 @@
 		max_weight: Weight,
 		weight_credit: &mut Weight,
 	) -> Result<(), ()> {
-		Deny::should_execute(origin, message, max_weight, weight_credit)?;
+		Deny::try_pass(origin, message)?;
 		Allow::should_execute(origin, message, max_weight, weight_credit)
 	}
 }
modifiedruntime/common/tests/xcm.rsdiffbeforeafterboth
--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -34,7 +34,7 @@
 }
 
 #[test]
-fn xcm_barrier_does_not_allow_transact() {
+fn xcm_barrier_denies_transact() {
     // We have a `AllowTopLevelPaidExecutionFrom` barrier,
     // so an XCM program should start from one of the following commands: 
     // * `WithdrawAsset`
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -463,6 +463,11 @@
 pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
 
 ################################################################################
+# Other Dependencies
+
+impl-trait-for-tuples = "0.2.2"
+
+################################################################################
 # Dev Dependencies
 
 [dev-dependencies.logtest]
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -471,6 +471,11 @@
 pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
 
 ################################################################################
+# Other Dependencies
+
+impl-trait-for-tuples = "0.2.2"
+
+################################################################################
 # Dev Dependencies
 
 [dev-dependencies.logtest]
modifiedruntime/quartz/src/xcm_config.rsdiffbeforeafterboth
--- a/runtime/quartz/src/xcm_config.rs
+++ b/runtime/quartz/src/xcm_config.rs
@@ -41,7 +41,7 @@
 };
 use xcm_executor::{
     {Config, XcmExecutor},
-    traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},
+    traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
 };
 
 use up_common::{
@@ -93,12 +93,10 @@
 
 // Allow xcm exchange only with locations in list
 pub struct DenyExchangeWithUnknownLocation;
-impl ShouldExecute for DenyExchangeWithUnknownLocation {
-    fn should_execute<Call>(
+impl TryPass for DenyExchangeWithUnknownLocation {
+    fn try_pass<Call>(
         origin: &MultiLocation,
         message: &mut Xcm<Call>,
-        _max_weight: Weight,
-        _weight_credit: &mut Weight,
     ) -> Result<(), ()> {
 
         // Check if deposit or transfer belongs to allowed parachains
@@ -126,9 +124,11 @@
 }
 
 pub type Barrier = DenyThenTry<
-    DenyExchangeWithUnknownLocation,
     (
         DenyTransact,
+        DenyExchangeWithUnknownLocation,
+    ),
+    (
         TakeWeightCredit,
         AllowTopLevelPaidExecutionFrom<Everything>,
         // Parent and its exec plurality get free execution
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -463,6 +463,11 @@
 pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
 
 ################################################################################
+# Other Dependencies
+
+impl-trait-for-tuples = "0.2.2"
+
+################################################################################
 # Dev Dependencies
 
 [dev-dependencies.logtest]
modifiedruntime/unique/src/xcm_config.rsdiffbeforeafterboth
--- a/runtime/unique/src/xcm_config.rs
+++ b/runtime/unique/src/xcm_config.rs
@@ -41,7 +41,7 @@
 };
 use xcm_executor::{
     {Config, XcmExecutor},
-    traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},
+    traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
 };
 
 use up_common::{
@@ -67,9 +67,11 @@
 
 
 pub type Barrier = DenyThenTry<
-    DenyExchangeWithUnknownLocation,
     (
         DenyTransact,
+        DenyExchangeWithUnknownLocation,
+    ),
+    (
         TakeWeightCredit,
         AllowTopLevelPaidExecutionFrom<Everything>,
         // Parent and its exec plurality get free execution
@@ -98,12 +100,10 @@
 
 // Allow xcm exchange only with locations in list
 pub struct DenyExchangeWithUnknownLocation;
-impl ShouldExecute for DenyExchangeWithUnknownLocation {
-    fn should_execute<Call>(
+impl TryPass for DenyExchangeWithUnknownLocation {
+    fn try_pass<Call>(
         origin: &MultiLocation,
         message: &mut Xcm<Call>,
-        _max_weight: Weight,
-        _weight_credit: &mut Weight,
     ) -> Result<(), ()> {
 
         // Check if deposit or transfer belongs to allowed parachains