referrerpolicy=no-referrer-when-downgrade

asset_hub_rococo_runtime/weights/xcm/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17mod pallet_xcm_benchmarks_fungible;
18mod pallet_xcm_benchmarks_generic;
19
20use crate::{xcm_config::MaxAssetsIntoHolding, Runtime};
21use alloc::vec::Vec;
22use frame_support::weights::Weight;
23use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
24use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
25use sp_runtime::BoundedVec;
26use xcm::{
27	latest::{prelude::*, AssetTransferFilter},
28	DoubleEncoded,
29};
30
31trait WeighAssets {
32	fn weigh_assets(&self, weight: Weight) -> Weight;
33}
34
35const MAX_ASSETS: u64 = 100;
36
37impl WeighAssets for AssetFilter {
38	fn weigh_assets(&self, weight: Weight) -> Weight {
39		match self {
40			Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
41			Self::Wild(asset) => match asset {
42				All => weight.saturating_mul(MAX_ASSETS),
43				AllOf { fun, .. } => match fun {
44					WildFungibility::Fungible => weight,
45					// Magic number 2 has to do with the fact that we could have up to 2 times
46					// MaxAssetsIntoHolding in the worst-case scenario.
47					WildFungibility::NonFungible =>
48						weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
49				},
50				AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min((*count as u64).max(1))),
51				AllOfCounted { count, .. } =>
52					weight.saturating_mul(MAX_ASSETS.min((*count as u64).max(1))),
53			},
54		}
55	}
56}
57
58impl WeighAssets for Assets {
59	fn weigh_assets(&self, weight: Weight) -> Weight {
60		weight.saturating_mul(self.inner().iter().count() as u64)
61	}
62}
63
64pub struct AssetHubRococoXcmWeight<Call>(core::marker::PhantomData<Call>);
65impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
66	fn withdraw_asset(assets: &Assets) -> Weight {
67		assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
68	}
69	fn reserve_asset_deposited(assets: &Assets) -> Weight {
70		assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
71	}
72	fn receive_teleported_asset(assets: &Assets) -> Weight {
73		assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
74	}
75	fn query_response(
76		_query_id: &u64,
77		_response: &Response,
78		_max_weight: &Weight,
79		_querier: &Option<Location>,
80	) -> Weight {
81		XcmGeneric::<Runtime>::query_response()
82	}
83	fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
84		assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
85	}
86	fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
87		assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
88	}
89	fn transact(
90		_origin_type: &OriginKind,
91		_fallback_max_weight: &Option<Weight>,
92		_call: &DoubleEncoded<Call>,
93	) -> Weight {
94		XcmGeneric::<Runtime>::transact()
95	}
96	fn hrmp_new_channel_open_request(
97		_sender: &u32,
98		_max_message_size: &u32,
99		_max_capacity: &u32,
100	) -> Weight {
101		// XCM Executor does not currently support HRMP channel operations
102		Weight::MAX
103	}
104	fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
105		// XCM Executor does not currently support HRMP channel operations
106		Weight::MAX
107	}
108	fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
109		// XCM Executor does not currently support HRMP channel operations
110		Weight::MAX
111	}
112	fn clear_origin() -> Weight {
113		XcmGeneric::<Runtime>::clear_origin()
114	}
115	fn descend_origin(_who: &InteriorLocation) -> Weight {
116		XcmGeneric::<Runtime>::descend_origin()
117	}
118	fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
119		XcmGeneric::<Runtime>::report_error()
120	}
121	fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
122		assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
123	}
124	fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
125		assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
126	}
127	fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
128		Weight::MAX
129	}
130	fn initiate_reserve_withdraw(
131		assets: &AssetFilter,
132		_reserve: &Location,
133		_xcm: &Xcm<()>,
134	) -> Weight {
135		assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
136	}
137	fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
138		assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
139	}
140	fn initiate_transfer(
141		_dest: &Location,
142		remote_fees: &Option<AssetTransferFilter>,
143		_preserve_origin: &bool,
144		assets: &BoundedVec<AssetTransferFilter, MaxAssetTransferFilters>,
145		_xcm: &Xcm<()>,
146	) -> Weight {
147		let base_weight = XcmFungibleWeight::<Runtime>::initiate_transfer();
148		let mut weight = if let Some(remote_fees) = remote_fees {
149			let fees = remote_fees.inner();
150			fees.weigh_assets(base_weight)
151		} else {
152			base_weight
153		};
154		for asset_filter in assets {
155			let assets = asset_filter.inner();
156			let extra = assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_transfer());
157			weight = weight.saturating_add(extra);
158		}
159		weight
160	}
161	fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
162		XcmGeneric::<Runtime>::report_holding()
163	}
164	fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
165		XcmGeneric::<Runtime>::buy_execution()
166	}
167	fn pay_fees(_asset: &Asset) -> Weight {
168		XcmGeneric::<Runtime>::pay_fees()
169	}
170	fn refund_surplus() -> Weight {
171		XcmGeneric::<Runtime>::refund_surplus()
172	}
173	fn set_error_handler(_xcm: &Xcm<Call>) -> Weight {
174		XcmGeneric::<Runtime>::set_error_handler()
175	}
176	fn set_appendix(_xcm: &Xcm<Call>) -> Weight {
177		XcmGeneric::<Runtime>::set_appendix()
178	}
179	fn clear_error() -> Weight {
180		XcmGeneric::<Runtime>::clear_error()
181	}
182	fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
183		let mut weight = Weight::zero();
184		for hint in hints {
185			match hint {
186				AssetClaimer { .. } => {
187					weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
188				},
189			}
190		}
191		weight
192	}
193	fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
194		XcmGeneric::<Runtime>::claim_asset()
195	}
196	fn trap(_code: &u64) -> Weight {
197		XcmGeneric::<Runtime>::trap()
198	}
199	fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> Weight {
200		XcmGeneric::<Runtime>::subscribe_version()
201	}
202	fn unsubscribe_version() -> Weight {
203		XcmGeneric::<Runtime>::unsubscribe_version()
204	}
205	fn burn_asset(assets: &Assets) -> Weight {
206		assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
207	}
208	fn expect_asset(assets: &Assets) -> Weight {
209		assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
210	}
211	fn expect_origin(_origin: &Option<Location>) -> Weight {
212		XcmGeneric::<Runtime>::expect_origin()
213	}
214	fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
215		XcmGeneric::<Runtime>::expect_error()
216	}
217	fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight {
218		XcmGeneric::<Runtime>::expect_transact_status()
219	}
220	fn query_pallet(_module_name: &Vec<u8>, _response_info: &QueryResponseInfo) -> Weight {
221		XcmGeneric::<Runtime>::query_pallet()
222	}
223	fn expect_pallet(
224		_index: &u32,
225		_name: &Vec<u8>,
226		_module_name: &Vec<u8>,
227		_crate_major: &u32,
228		_min_crate_minor: &u32,
229	) -> Weight {
230		XcmGeneric::<Runtime>::expect_pallet()
231	}
232	fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight {
233		XcmGeneric::<Runtime>::report_transact_status()
234	}
235	fn clear_transact_status() -> Weight {
236		XcmGeneric::<Runtime>::clear_transact_status()
237	}
238	fn universal_origin(_: &Junction) -> Weight {
239		XcmGeneric::<Runtime>::universal_origin()
240	}
241	fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
242		Weight::MAX
243	}
244	fn lock_asset(_: &Asset, _: &Location) -> Weight {
245		Weight::MAX
246	}
247	fn unlock_asset(_: &Asset, _: &Location) -> Weight {
248		Weight::MAX
249	}
250	fn note_unlockable(_: &Asset, _: &Location) -> Weight {
251		Weight::MAX
252	}
253	fn request_unlock(_: &Asset, _: &Location) -> Weight {
254		Weight::MAX
255	}
256	fn set_fees_mode(_: &bool) -> Weight {
257		XcmGeneric::<Runtime>::set_fees_mode()
258	}
259	fn set_topic(_topic: &[u8; 32]) -> Weight {
260		XcmGeneric::<Runtime>::set_topic()
261	}
262	fn clear_topic() -> Weight {
263		XcmGeneric::<Runtime>::clear_topic()
264	}
265	fn alias_origin(_: &Location) -> Weight {
266		XcmGeneric::<Runtime>::alias_origin()
267	}
268	fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
269		XcmGeneric::<Runtime>::unpaid_execution()
270	}
271	fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
272		XcmGeneric::<Runtime>::execute_with_origin()
273	}
274}