referrerpolicy=no-referrer-when-downgrade

pallet_staking_async_parachain_runtime/weights/xcm/
mod.rs

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