From 5ebdb902087d56b957aee59ea0360388c1b0c77c Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 14:45:30 +0200 Subject: [PATCH 1/8] [Fix] Weight calculations for Wild -> affects teleports --- .../runtimes/assets/statemine/src/weights/xcm/mod.rs | 7 +++---- .../runtimes/assets/statemint/src/weights/xcm/mod.rs | 7 +++---- parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 79fbd0812bb..c54aa2ffdca 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -31,13 +31,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { let weight = match self { - Self::Definite(assets) => - weight.saturating_mul(assets.inner().into_iter().count() as u64), + Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), }; weight.ref_time() @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time() + weight.saturating_mul(self.len() as u64).ref_time() } } diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index b51f8b207a5..e4aeef218f2 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -31,13 +31,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { let weight = match self { - Self::Definite(assets) => - weight.saturating_mul(assets.inner().into_iter().count() as u64), + Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), }; weight.ref_time() @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time() + weight.saturating_mul(self.len() as u64).ref_time() } } diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 018f8f7d9f7..331c799c048 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -31,13 +31,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { let weight = match self { - Self::Definite(assets) => - weight.saturating_mul(assets.inner().into_iter().count() as u64), + Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), }; weight.ref_time() @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time() + weight.saturating_mul(self.len() as u64).ref_time() } } From 77d33b1407dc4f7dd5a653d8d9fd63da115c6bac Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 15:21:54 +0200 Subject: [PATCH 2/8] introduce a separate asset limit for teleports --- .../assets/statemine/src/weights/xcm/mod.rs | 33 +++++++++++++++---- .../assets/statemint/src/weights/xcm/mod.rs | 33 +++++++++++++++---- .../assets/westmint/src/weights/xcm/mod.rs | 33 +++++++++++++++---- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index c54aa2ffdca..628cd457e1d 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -27,19 +27,38 @@ use xcm::{ DoubleEncoded, }; +fn weigh_multi_assets_generic( + filter: &MultiAssetFilter, + weight: Weight, + max_assets: u32, +) -> XCMWeight { + let weight = match filter { + MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), + MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), + }; + weight.ref_time() +} + trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 1; +trait WeighMultiAssetsTeleport { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +} + +const MAX_ASSETS: u32 = 100; +const TELEPORT_MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - let weight = match self { - Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), - Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), - }; - weight.ref_time() + weigh_multi_assets_generic(self, weight, MAX_ASSETS) + } +} + +impl WeighMultiAssetsTeleport for MultiAssetFilter { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) } } @@ -141,7 +160,7 @@ impl XcmWeightInfo for StatemineXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index e4aeef218f2..0a5d4865d5b 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -27,19 +27,38 @@ use xcm::{ DoubleEncoded, }; +fn weigh_multi_assets_generic( + filter: &MultiAssetFilter, + weight: Weight, + max_assets: u32, +) -> XCMWeight { + let weight = match filter { + MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), + MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), + }; + weight.ref_time() +} + trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 1; +trait WeighMultiAssetsTeleport { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +} + +const MAX_ASSETS: u32 = 100; +const TELEPORT_MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - let weight = match self { - Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), - Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), - }; - weight.ref_time() + weigh_multi_assets_generic(self, weight, MAX_ASSETS) + } +} + +impl WeighMultiAssetsTeleport for MultiAssetFilter { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) } } @@ -141,7 +160,7 @@ impl XcmWeightInfo for StatemintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 331c799c048..089462d6b03 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -27,19 +27,38 @@ use xcm::{ DoubleEncoded, }; +fn weigh_multi_assets_generic( + filter: &MultiAssetFilter, + weight: Weight, + max_assets: u32, +) -> XCMWeight { + let weight = match filter { + MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), + MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), + }; + weight.ref_time() +} + trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 1; +trait WeighMultiAssetsTeleport { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +} + +const MAX_ASSETS: u32 = 100; +const TELEPORT_MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - let weight = match self { - Self::Definite(assets) => weight.saturating_mul(assets.len() as u64), - Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), - }; - weight.ref_time() + weigh_multi_assets_generic(self, weight, MAX_ASSETS) + } +} + +impl WeighMultiAssetsTeleport for MultiAssetFilter { + fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) } } @@ -141,7 +160,7 @@ impl XcmWeightInfo for WestmintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, From 4901fe3438f5eae2027b69e5671e4f05dd8c4e68 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 15:28:50 +0200 Subject: [PATCH 3/8] fix deposit --- parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs | 2 +- parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs | 2 +- parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 628cd457e1d..cf6d6d09448 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -135,7 +135,7 @@ impl XcmWeightInfo for StatemineXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 0a5d4865d5b..903a104ef6f 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -135,7 +135,7 @@ impl XcmWeightInfo for StatemintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 089462d6b03..9f9494dde0f 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -135,7 +135,7 @@ impl XcmWeightInfo for WestmintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, From 81ea3bec38a246e75bbbba2777526a7622576935 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 15:45:26 +0200 Subject: [PATCH 4/8] reshuffle abstractions --- .../assets/statemine/src/weights/xcm/mod.rs | 22 +++++++++---------- .../assets/statemint/src/weights/xcm/mod.rs | 22 +++++++++---------- .../assets/westmint/src/weights/xcm/mod.rs | 22 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index cf6d6d09448..892326a6f7a 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -43,12 +43,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -trait WeighMultiAssetsTeleport { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +trait WeighMultiAssetsReserve { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; -const TELEPORT_MAX_ASSETS: u32 = 1; +const RESERVE_MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { @@ -56,9 +56,9 @@ impl WeighMultiAssets for MultiAssetFilter { } } -impl WeighMultiAssetsTeleport for MultiAssetFilter { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { - weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) +impl WeighMultiAssetsReserve for MultiAssetFilter { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS) } } @@ -135,7 +135,7 @@ impl XcmWeightInfo for StatemineXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, @@ -143,7 +143,7 @@ impl XcmWeightInfo for StatemineXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + assets.weigh_multi_assets_reserve(XcmFungibleWeight::::deposit_reserve_asset()) } fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { Weight::MAX.ref_time() @@ -153,14 +153,14 @@ impl XcmWeightInfo for StatemineXcmWeight { _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + assets.weigh_multi_assets_reserve(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 903a104ef6f..4b8fd9bb1ec 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -43,12 +43,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -trait WeighMultiAssetsTeleport { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +trait WeighMultiAssetsReserve { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; -const TELEPORT_MAX_ASSETS: u32 = 1; +const RESERVE_MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { @@ -56,9 +56,9 @@ impl WeighMultiAssets for MultiAssetFilter { } } -impl WeighMultiAssetsTeleport for MultiAssetFilter { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { - weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) +impl WeighMultiAssetsReserve for MultiAssetFilter { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS) } } @@ -135,7 +135,7 @@ impl XcmWeightInfo for StatemintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, @@ -143,7 +143,7 @@ impl XcmWeightInfo for StatemintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + assets.weigh_multi_assets_reserve(XcmFungibleWeight::::deposit_reserve_asset()) } fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { Weight::MAX.ref_time() @@ -153,14 +153,14 @@ impl XcmWeightInfo for StatemintXcmWeight { _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + assets.weigh_multi_assets_reserve(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 9f9494dde0f..2ce04ecc7d1 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -43,12 +43,12 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } -trait WeighMultiAssetsTeleport { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight; +trait WeighMultiAssetsReserve { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight; } -const MAX_ASSETS: u32 = 100; -const TELEPORT_MAX_ASSETS: u32 = 1; +const RESERVE_MAX_ASSETS: u32 = 100; +const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { @@ -56,9 +56,9 @@ impl WeighMultiAssets for MultiAssetFilter { } } -impl WeighMultiAssetsTeleport for MultiAssetFilter { - fn weigh_multi_assets_teleport(&self, weight: Weight) -> XCMWeight { - weigh_multi_assets_generic(self, weight, TELEPORT_MAX_ASSETS) +impl WeighMultiAssetsReserve for MultiAssetFilter { + fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { + weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS) } } @@ -135,7 +135,7 @@ impl XcmWeightInfo for WestmintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, @@ -143,7 +143,7 @@ impl XcmWeightInfo for WestmintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + assets.weigh_multi_assets_reserve(XcmFungibleWeight::::deposit_reserve_asset()) } fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { Weight::MAX.ref_time() @@ -153,14 +153,14 @@ impl XcmWeightInfo for WestmintXcmWeight { _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + assets.weigh_multi_assets_reserve(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets_teleport(XcmFungibleWeight::::initiate_teleport()) + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( _query_id: &u64, From 9efa8224e48145c8e34da67d869c756312c7a3c7 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 15:46:58 +0200 Subject: [PATCH 5/8] fix imports --- parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs | 1 - parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs | 1 - parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 892326a6f7a..ce254fc2909 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -21,7 +21,6 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; -use sp_std::prelude::*; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 4b8fd9bb1ec..b6a1b5fc6fa 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -21,7 +21,6 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; -use sp_std::prelude::*; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 2ce04ecc7d1..667348c5551 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -21,7 +21,6 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; -use sp_std::prelude::*; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, From 9258f4e55b79619df4afb105fe972d6528893c72 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 16:21:30 +0200 Subject: [PATCH 6/8] little refactoring --- parachains/common/src/xcm_config.rs | 14 ++++++++++++++ .../assets/statemine/src/weights/xcm/mod.rs | 13 +------------ .../assets/statemint/src/weights/xcm/mod.rs | 13 +------------ .../assets/westmint/src/weights/xcm/mod.rs | 13 +------------ 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index b9ae5ef87ce..1e0936d25d4 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -119,3 +119,17 @@ impl> FilterAssetLocation for ConcreteNativeAssetFr matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get()) } } + +/// A generic function to use for MultiAssetFilter implementations, currently used to differentiate +/// between reserve operations and the rest of them. +pub fn weigh_multi_assets_generic( + filter: &MultiAssetFilter, + weight: Weight, + max_assets: u32, +) -> XCMWeight { + let weight = match filter { + MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), + MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), + }; + weight.ref_time() +} diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index ce254fc2909..636ed70446e 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -21,23 +21,12 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use parachains_common::xcm_config::weigh_multi_assets_generic; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, }; -fn weigh_multi_assets_generic( - filter: &MultiAssetFilter, - weight: Weight, - max_assets: u32, -) -> XCMWeight { - let weight = match filter { - MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), - MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), - }; - weight.ref_time() -} - trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index b6a1b5fc6fa..0be415d140b 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -21,23 +21,12 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use parachains_common::xcm_config::weigh_multi_assets_generic; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, }; -fn weigh_multi_assets_generic( - filter: &MultiAssetFilter, - weight: Weight, - max_assets: u32, -) -> XCMWeight { - let weight = match filter { - MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), - MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), - }; - weight.ref_time() -} - trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 667348c5551..a83342def95 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -21,23 +21,12 @@ use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use parachains_common::xcm_config::weigh_multi_assets_generic; use xcm::{ latest::{prelude::*, Weight as XCMWeight}, DoubleEncoded, }; -fn weigh_multi_assets_generic( - filter: &MultiAssetFilter, - weight: Weight, - max_assets: u32, -) -> XCMWeight { - let weight = match filter { - MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), - MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), - }; - weight.ref_time() -} - trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } From 2d60b9f038a5077ac600bee043fcf7220257d00f Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 20:08:27 +0200 Subject: [PATCH 7/8] Update parachains/common/src/xcm_config.rs Co-authored-by: Squirrel --- parachains/common/src/xcm_config.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index 1e0936d25d4..346e0f9cb61 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -127,9 +127,9 @@ pub fn weigh_multi_assets_generic( weight: Weight, max_assets: u32, ) -> XCMWeight { - let weight = match filter { - MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), - MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), + let multiplier = match filter { + MultiAssetFilter::Definite(assets) => assets.len() as u64, + MultiAssetFilter::Wild(_) => max_assets as u64, }; - weight.ref_time() + weight.saturating_mul(multiplier).ref_time() } From 4b1583a3a236fd61a89ea5ee3ed14a2fd73f4aa6 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 19 Sep 2022 20:10:03 +0200 Subject: [PATCH 8/8] add comments --- parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs | 1 + parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs | 1 + parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 636ed70446e..9dd4345ef73 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -36,6 +36,7 @@ trait WeighMultiAssetsReserve { } const RESERVE_MAX_ASSETS: u32 = 100; +/// For teleports and deposits const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 0be415d140b..2fbe469aab7 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -36,6 +36,7 @@ trait WeighMultiAssetsReserve { } const RESERVE_MAX_ASSETS: u32 = 100; +/// For teleports and deposits const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter { diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index a83342def95..0c1f96ae7d7 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -36,6 +36,7 @@ trait WeighMultiAssetsReserve { } const RESERVE_MAX_ASSETS: u32 = 100; +/// For teleports and deposits const MAX_ASSETS: u32 = 1; impl WeighMultiAssets for MultiAssetFilter {