Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
[Enhancement] Use XCM V3 for initiate_teleport weight calc (#2102)
Browse files Browse the repository at this point in the history
* [Enhancement] Use XCM V3 for initiate_teleport weight calc

* deref

* replicate in all the runtimes

* fmt

* better handling for AllOf

* fmt

* small type fix

* replicate the fix for all runtimes

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
ruseinov authored Feb 9, 2023
1 parent afcfd24 commit 8230ec4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 32 deletions.
20 changes: 14 additions & 6 deletions parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down Expand Up @@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
hardcoded_weight.min(weight)
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down
20 changes: 14 additions & 6 deletions parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down Expand Up @@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
hardcoded_weight.min(weight)
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down
20 changes: 14 additions & 6 deletions parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down Expand Up @@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
hardcoded_weight.min(weight)
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down Expand Up @@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubKusamaXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
hardcoded_weight.min(weight)
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
Expand All @@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(asset) => match asset {
All => weight.saturating_mul(MAX_ASSETS as u64),
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(*count as u64),
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
},
}
}
}
Expand Down Expand Up @@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
// Hardcoded till the XCM pallet is fixed
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
hardcoded_weight.min(weight)
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down

0 comments on commit 8230ec4

Please sign in to comment.