referrerpolicy=no-referrer-when-downgrade

bridge_hub_westend_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 codec::Encode;
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 BridgeHubWestendXcmWeight<Call>(core::marker::PhantomData<Call>);
65impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<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 mut weight = if let Some(remote_fees) = remote_fees {
149			let fees = remote_fees.inner();
150			fees.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_transfer())
151		} else {
152			Weight::zero()
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		Weight::MAX
240	}
241	fn export_message(_: &NetworkId, _: &Junctions, inner: &Xcm<()>) -> Weight {
242		let inner_encoded_len = inner.encode().len() as u32;
243		XcmGeneric::<Runtime>::export_message(inner_encoded_len)
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}