From e98ed6e2b41e9310222520a18d12cb7f33d99158 Mon Sep 17 00:00:00 2001 From: Egor_P Date: Wed, 29 Mar 2023 17:34:22 +0200 Subject: [PATCH] [Revert] Use XCM V3 for initiate_teleport weight calc #2102 (#2394) * Revert "[Enhancement] Use XCM V3 for initiate_teleport weight calc (#2102)" This reverts commit 8230ec4773751f2ff9d10b9144deee331d02ffcd. * updating weight format * We expect to pay 1bn+ for a teleport at the current weights. * The test isn't needed and hardcoded scale is hand to maintain. * remove unused imports --------- Co-authored-by: Giles Cope --- .../assets/statemine/src/weights/xcm/mod.rs | 20 +++------ .../runtimes/assets/statemine/tests/tests.rs | 2 +- .../assets/statemint/src/weights/xcm/mod.rs | 20 +++------ .../runtimes/assets/statemint/tests/tests.rs | 2 +- .../assets/westmint/src/weights/xcm/mod.rs | 20 +++------ .../runtimes/assets/westmint/tests/tests.rs | 41 +++---------------- .../bridge-hub-kusama/src/weights/xcm/mod.rs | 20 +++------ .../src/weights/xcm/mod.rs | 15 +------ .../bridge-hub-rococo/src/weights/xcm/mod.rs | 20 +++------ 9 files changed, 40 insertions(+), 120 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 877a54ba848..9c457671ed0 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } @@ -149,7 +138,10 @@ impl XcmWeightInfo for StatemineXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + // Hardcoded till the XCM pallet is fixed + let hardcoded_weight = Weight::from_parts(200_000_000 as u64, 0); + let weight = assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()); + hardcoded_weight.min(weight) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index b696e4ef1e3..8c9c0c152c1 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -448,7 +448,7 @@ fn receive_teleported_asset_works() { id: Concrete(MultiLocation { parents: 1, interior: Here }), fun: Fungible(10000000000000), }, - weight_limit: Limited(Weight::from_parts(303531000, 65536)), + weight_limit: Limited(Weight::from_parts(1303531000, 65536)), }, DepositAsset { assets: Wild(AllCounted(1)), diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 1b4a2bcfdd7..5e06dc7e746 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } @@ -149,7 +138,10 @@ impl XcmWeightInfo for StatemintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + // Hardcoded till the XCM pallet is fixed + let hardcoded_weight = Weight::from_parts(200_000_000 as u64, 0); + let weight = assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()); + hardcoded_weight.min(weight) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 81aa458b476..288aa1b4987 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -460,7 +460,7 @@ fn receive_teleported_asset_works() { id: Concrete(MultiLocation { parents: 1, interior: Here }), fun: Fungible(10000000000000), }, - weight_limit: Limited(Weight::from_parts(303531000, 65536)), + weight_limit: Limited(Weight::from_parts(1303531000, 65536)), }, DepositAsset { assets: Wild(AllCounted(1)), diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 5daa3acbcce..b30ee424073 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } @@ -149,7 +138,10 @@ impl XcmWeightInfo for WestmintXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + // Hardcoded till the XCM pallet is fixed + let hardcoded_weight = Weight::from_parts(200_000_000 as u64, 0); + let weight = assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()); + hardcoded_weight.min(weight) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 5d7a6187869..246ddbadb69 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -1,21 +1,20 @@ use asset_test_utils::{ExtBuilder, RuntimeHelper}; -use codec::{DecodeLimit, Encode}; +use codec::Encode; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ assert_noop, assert_ok, sp_io, weights::{Weight, WeightToFee as WeightToFeeT}, }; use parachains_common::{AccountId, AuraId, Balance}; +use westmint_runtime::xcm_config::{ + AssetFeeAsExistentialDepositMultiplierFeeCharger, WestendLocation, +}; pub use westmint_runtime::{ constants::fee::WeightToFee, xcm_config::{TrustBackedAssetsPalletLocation, XcmConfig}, Assets, Balances, ExistentialDeposit, ReservedDmpWeight, Runtime, SessionKeys, System, }; -use westmint_runtime::{ - xcm_config::{AssetFeeAsExistentialDepositMultiplierFeeCharger, WestendLocation}, - RuntimeCall, -}; -use xcm::{latest::prelude::*, VersionedXcm, MAX_XCM_DECODE_DEPTH}; +use xcm::latest::prelude::*; use xcm_executor::{ traits::{Convert, WeightTrader}, XcmExecutor, @@ -448,7 +447,7 @@ fn receive_teleported_asset_works() { id: Concrete(MultiLocation { parents: 1, interior: Here }), fun: Fungible(10000000000000), }, - weight_limit: Limited(Weight::from_parts(303531000, 65536)), + weight_limit: Limited(Weight::from_parts(1303531000, 65536)), }, DepositAsset { assets: Wild(AllCounted(1)), @@ -473,31 +472,3 @@ fn receive_teleported_asset_works() { assert_eq!(outcome.ensure_complete(), Ok(())); }) } - -#[test] -fn plain_receive_teleported_asset_works() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - let data = hex_literal::hex!("02100204000100000b00a0724e18090a13000100000b00a0724e180901e20f5e480d010004000101001299557001f55815d3fcb53c74463acb0cf6d14d4639b340982c60877f384609").to_vec(); - let message_id = sp_io::hashing::blake2_256(&data); - - let maybe_msg = VersionedXcm::::decode_all_with_depth_limit( - MAX_XCM_DECODE_DEPTH, - &mut data.as_ref(), - ) - .map(xcm::v3::Xcm::::try_from).expect("failed").expect("failed"); - - let weight_limit = ReservedDmpWeight::get(); - - let outcome = - XcmExecutor::::execute_xcm(Parent, maybe_msg, message_id, weight_limit); - assert_eq!(outcome.ensure_complete(), Ok(())); - }) -} diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/weights/xcm/mod.rs b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/weights/xcm/mod.rs index 7cf23e0610b..f3489cf3e48 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/weights/xcm/mod.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } @@ -149,7 +138,10 @@ impl XcmWeightInfo for BridgeHubKusamaXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + // Hardcoded till the XCM pallet is fixed + let hardcoded_weight = Weight::from_parts(200_000_000 as u64, 0); + let weight = assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()); + hardcoded_weight.min(weight) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/weights/xcm/mod.rs b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/weights/xcm/mod.rs index e9b1c70bf6a..f74eaf1195a 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/weights/xcm/mod.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/xcm/mod.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/xcm/mod.rs index b05c554580d..2bbcb765bfb 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/xcm/mod.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/xcm/mod.rs @@ -17,7 +17,7 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; -use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; +use crate::Runtime; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -35,18 +35,7 @@ impl WeighMultiAssets for MultiAssetFilter { match self { Self::Definite(assets) => weight.saturating_mul(assets.inner().into_iter().count() as u64), - Self::Wild(asset) => match asset { - All => weight.saturating_mul(MAX_ASSETS), - AllOf { fun, .. } => match fun { - WildFungibility::Fungible => weight, - // Magic number 2 has to do with the fact that we could have up to 2 times - // MaxAssetsIntoHolding in the worst-case scenario. - WildFungibility::NonFungible => - weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64), - }, - AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)), - }, + Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), } } } @@ -149,7 +138,10 @@ impl XcmWeightInfo for BridgeHubRococoXcmWeight { _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { - assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + // Hardcoded till the XCM pallet is fixed + let hardcoded_weight = Weight::from_parts(200_000_000 as u64, 0); + let weight = assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()); + hardcoded_weight.min(weight) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding()