referrerpolicy=no-referrer-when-downgrade

people_westend_runtime/weights/xcm/
mod.rs

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