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

Commit 8230ec4

Browse files
authored
[Enhancement] Use XCM V3 for initiate_teleport weight calc (#2102)
* [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 <>
1 parent afcfd24 commit 8230ec4

File tree

6 files changed

+83
-32
lines changed
  • parachains/runtimes
    • assets
      • statemine/src/weights/xcm
      • statemint/src/weights/xcm
      • westmint/src/weights/xcm
    • bridge-hubs
      • bridge-hub-kusama/src/weights/xcm
      • bridge-hub-polkadot/src/weights/xcm
      • bridge-hub-rococo/src/weights/xcm

6 files changed

+83
-32
lines changed

parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}
@@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
138149
_dest: &MultiLocation,
139150
_xcm: &Xcm<()>,
140151
) -> Weight {
141-
// Hardcoded till the XCM pallet is fixed
142-
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
143-
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
144-
hardcoded_weight.min(weight)
152+
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
145153
}
146154
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
147155
XcmGeneric::<Runtime>::report_holding()

parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}
@@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
138149
_dest: &MultiLocation,
139150
_xcm: &Xcm<()>,
140151
) -> Weight {
141-
// Hardcoded till the XCM pallet is fixed
142-
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
143-
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
144-
hardcoded_weight.min(weight)
152+
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
145153
}
146154
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
147155
XcmGeneric::<Runtime>::report_holding()

parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}
@@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
138149
_dest: &MultiLocation,
139150
_xcm: &Xcm<()>,
140151
) -> Weight {
141-
// Hardcoded till the XCM pallet is fixed
142-
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
143-
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
144-
hardcoded_weight.min(weight)
152+
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
145153
}
146154
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
147155
XcmGeneric::<Runtime>::report_holding()

parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/weights/xcm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}
@@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubKusamaXcmWeight<Call> {
138149
_dest: &MultiLocation,
139150
_xcm: &Xcm<()>,
140151
) -> Weight {
141-
// Hardcoded till the XCM pallet is fixed
142-
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
143-
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
144-
hardcoded_weight.min(weight)
152+
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
145153
}
146154
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
147155
XcmGeneric::<Runtime>::report_holding()

parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/weights/xcm/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}

parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/xcm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mod pallet_xcm_benchmarks_fungible;
1818
mod pallet_xcm_benchmarks_generic;
1919

20-
use crate::Runtime;
20+
use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
2121
use frame_support::weights::Weight;
2222
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
2323
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
@@ -35,7 +35,18 @@ impl WeighMultiAssets for MultiAssetFilter {
3535
match self {
3636
Self::Definite(assets) =>
3737
weight.saturating_mul(assets.inner().into_iter().count() as u64),
38-
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
38+
Self::Wild(asset) => match asset {
39+
All => weight.saturating_mul(MAX_ASSETS as u64),
40+
AllOf { fun, .. } => match fun {
41+
WildFungibility::Fungible => weight,
42+
// Magic number 2 has to do with the fact that we could have up to 2 times
43+
// MaxAssetsIntoHolding in the worst-case scenario.
44+
WildFungibility::NonFungible =>
45+
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
46+
},
47+
AllCounted(count) => weight.saturating_mul(*count as u64),
48+
AllOfCounted { count, .. } => weight.saturating_mul(*count as u64),
49+
},
3950
}
4051
}
4152
}
@@ -138,10 +149,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
138149
_dest: &MultiLocation,
139150
_xcm: &Xcm<()>,
140151
) -> Weight {
141-
// Hardcoded till the XCM pallet is fixed
142-
let hardcoded_weight = Weight::from_ref_time(200_000_000 as u64);
143-
let weight = assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport());
144-
hardcoded_weight.min(weight)
152+
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
145153
}
146154
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
147155
XcmGeneric::<Runtime>::report_holding()

0 commit comments

Comments
 (0)