referrerpolicy=no-referrer-when-downgrade

coretime_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)),
51				AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)),
52			},
53		}
54	}
55}
56
57impl WeighAssets for Assets {
58	fn weigh_assets(&self, weight: Weight) -> Weight {
59		weight.saturating_mul(self.inner().iter().count() as u64)
60	}
61}
62
63pub struct CoretimeRococoXcmWeight<Call>(core::marker::PhantomData<Call>);
64impl<Call> XcmWeightInfo<Call> for CoretimeRococoXcmWeight<Call> {
65	fn withdraw_asset(assets: &Assets) -> Weight {
66		assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
67	}
68	fn reserve_asset_deposited(assets: &Assets) -> Weight {
69		assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
70	}
71	fn receive_teleported_asset(assets: &Assets) -> Weight {
72		assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
73	}
74	fn query_response(
75		_query_id: &u64,
76		_response: &Response,
77		_max_weight: &Weight,
78		_querier: &Option<Location>,
79	) -> Weight {
80		XcmGeneric::<Runtime>::query_response()
81	}
82	fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
83		assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
84	}
85	fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
86		assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
87	}
88	fn transact(
89		_origin_type: &OriginKind,
90		_fallback_max_weight: &Option<Weight>,
91		_call: &DoubleEncoded<Call>,
92	) -> Weight {
93		XcmGeneric::<Runtime>::transact()
94	}
95	fn hrmp_new_channel_open_request(
96		_sender: &u32,
97		_max_message_size: &u32,
98		_max_capacity: &u32,
99	) -> Weight {
100		// XCM Executor does not currently support HRMP channel operations
101		Weight::MAX
102	}
103	fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
104		// XCM Executor does not currently support HRMP channel operations
105		Weight::MAX
106	}
107	fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
108		// XCM Executor does not currently support HRMP channel operations
109		Weight::MAX
110	}
111	fn clear_origin() -> Weight {
112		XcmGeneric::<Runtime>::clear_origin()
113	}
114	fn descend_origin(_who: &InteriorLocation) -> Weight {
115		XcmGeneric::<Runtime>::descend_origin()
116	}
117	fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
118		XcmGeneric::<Runtime>::report_error()
119	}
120	fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
121		assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
122	}
123	fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
124		assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
125	}
126	fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
127		Weight::MAX
128	}
129	fn initiate_reserve_withdraw(
130		assets: &AssetFilter,
131		_reserve: &Location,
132		_xcm: &Xcm<()>,
133	) -> Weight {
134		assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
135	}
136	fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
137		assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
138	}
139	fn initiate_transfer(
140		_dest: &Location,
141		remote_fees: &Option<AssetTransferFilter>,
142		_preserve_origin: &bool,
143		assets: &BoundedVec<AssetTransferFilter, MaxAssetTransferFilters>,
144		_xcm: &Xcm<()>,
145	) -> Weight {
146		let mut weight = if let Some(remote_fees) = remote_fees {
147			let fees = remote_fees.inner();
148			fees.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_transfer())
149		} else {
150			Weight::zero()
151		};
152		for asset_filter in assets {
153			let assets = asset_filter.inner();
154			let extra = assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_transfer());
155			weight = weight.saturating_add(extra);
156		}
157		weight
158	}
159	fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
160		XcmGeneric::<Runtime>::report_holding()
161	}
162	fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
163		XcmGeneric::<Runtime>::buy_execution()
164	}
165	fn pay_fees(_asset: &Asset) -> Weight {
166		XcmGeneric::<Runtime>::pay_fees()
167	}
168	fn refund_surplus() -> Weight {
169		XcmGeneric::<Runtime>::refund_surplus()
170	}
171	fn set_error_handler(_xcm: &Xcm<Call>) -> Weight {
172		XcmGeneric::<Runtime>::set_error_handler()
173	}
174	fn set_appendix(_xcm: &Xcm<Call>) -> Weight {
175		XcmGeneric::<Runtime>::set_appendix()
176	}
177	fn clear_error() -> Weight {
178		XcmGeneric::<Runtime>::clear_error()
179	}
180	fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
181		XcmGeneric::<Runtime>::claim_asset()
182	}
183	fn trap(_code: &u64) -> Weight {
184		XcmGeneric::<Runtime>::trap()
185	}
186	fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> Weight {
187		XcmGeneric::<Runtime>::subscribe_version()
188	}
189	fn unsubscribe_version() -> Weight {
190		XcmGeneric::<Runtime>::unsubscribe_version()
191	}
192	fn burn_asset(assets: &Assets) -> Weight {
193		assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
194	}
195	fn expect_asset(assets: &Assets) -> Weight {
196		assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
197	}
198	fn expect_origin(_origin: &Option<Location>) -> Weight {
199		XcmGeneric::<Runtime>::expect_origin()
200	}
201	fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
202		XcmGeneric::<Runtime>::expect_error()
203	}
204	fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight {
205		XcmGeneric::<Runtime>::expect_transact_status()
206	}
207	fn query_pallet(_module_name: &Vec<u8>, _response_info: &QueryResponseInfo) -> Weight {
208		XcmGeneric::<Runtime>::query_pallet()
209	}
210	fn expect_pallet(
211		_index: &u32,
212		_name: &Vec<u8>,
213		_module_name: &Vec<u8>,
214		_crate_major: &u32,
215		_min_crate_minor: &u32,
216	) -> Weight {
217		XcmGeneric::<Runtime>::expect_pallet()
218	}
219	fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight {
220		XcmGeneric::<Runtime>::report_transact_status()
221	}
222	fn clear_transact_status() -> Weight {
223		XcmGeneric::<Runtime>::clear_transact_status()
224	}
225	fn universal_origin(_: &Junction) -> Weight {
226		Weight::MAX
227	}
228	fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
229		Weight::MAX
230	}
231	fn lock_asset(_: &Asset, _: &Location) -> Weight {
232		Weight::MAX
233	}
234	fn unlock_asset(_: &Asset, _: &Location) -> Weight {
235		Weight::MAX
236	}
237	fn note_unlockable(_: &Asset, _: &Location) -> Weight {
238		Weight::MAX
239	}
240	fn request_unlock(_: &Asset, _: &Location) -> Weight {
241		Weight::MAX
242	}
243	fn set_fees_mode(_: &bool) -> Weight {
244		XcmGeneric::<Runtime>::set_fees_mode()
245	}
246	fn set_topic(_topic: &[u8; 32]) -> Weight {
247		XcmGeneric::<Runtime>::set_topic()
248	}
249	fn clear_topic() -> Weight {
250		XcmGeneric::<Runtime>::clear_topic()
251	}
252	fn alias_origin(_: &Location) -> Weight {
253		// XCM Executor does not currently support alias origin operations
254		Weight::MAX
255	}
256	fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
257		XcmGeneric::<Runtime>::unpaid_execution()
258	}
259	fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
260		let mut weight = Weight::zero();
261		for hint in hints {
262			match hint {
263				AssetClaimer { .. } => {
264					weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
265				},
266			}
267		}
268		weight
269	}
270	fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
271		XcmGeneric::<Runtime>::execute_with_origin()
272	}
273}