pallet_staking_async_rc_runtime/weights/xcm/
mod.rs1mod pallet_xcm_benchmarks_fungible;
18mod pallet_xcm_benchmarks_generic;
19
20use crate::Runtime;
21use alloc::vec::Vec;
22use frame_support::weights::Weight;
23use xcm::{
24 latest::{prelude::*, QueryResponseInfo},
25 DoubleEncoded,
26};
27
28use pallet_xcm_benchmarks_fungible::WeightInfo as XcmBalancesWeight;
29use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
30use sp_runtime::BoundedVec;
31use xcm::latest::AssetTransferFilter;
32
33pub enum AssetTypes {
35 Balances,
37 Unknown,
39}
40
41impl From<&Asset> for AssetTypes {
42 fn from(asset: &Asset) -> Self {
43 match asset {
44 Asset { id: AssetId(Location { parents: 0, interior: Here }), .. } =>
45 AssetTypes::Balances,
46 _ => AssetTypes::Unknown,
47 }
48 }
49}
50
51trait WeighAssets {
52 fn weigh_assets(&self, balances_weight: Weight) -> Weight;
53}
54
55const MAX_ASSETS: u64 = 1;
57
58impl WeighAssets for AssetFilter {
59 fn weigh_assets(&self, balances_weight: Weight) -> Weight {
60 match self {
61 Self::Definite(assets) => assets
62 .inner()
63 .into_iter()
64 .map(From::from)
65 .map(|t| match t {
66 AssetTypes::Balances => balances_weight,
67 AssetTypes::Unknown => Weight::MAX,
68 })
69 .fold(Weight::zero(), |acc, x| acc.saturating_add(x)),
70 Self::Wild(AllOf { .. } | AllOfCounted { .. }) => balances_weight,
73 Self::Wild(AllCounted(count)) =>
74 balances_weight.saturating_mul(MAX_ASSETS.min(*count as u64)),
75 Self::Wild(All) => balances_weight.saturating_mul(MAX_ASSETS),
76 }
77 }
78}
79
80impl WeighAssets for Assets {
81 fn weigh_assets(&self, balances_weight: Weight) -> Weight {
82 self.inner()
83 .into_iter()
84 .map(|m| <AssetTypes as From<&Asset>>::from(m))
85 .map(|t| match t {
86 AssetTypes::Balances => balances_weight,
87 AssetTypes::Unknown => Weight::MAX,
88 })
89 .fold(Weight::zero(), |acc, x| acc.saturating_add(x))
90 }
91}
92
93pub struct WestendXcmWeight<RuntimeCall>(core::marker::PhantomData<RuntimeCall>);
94impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
95 fn withdraw_asset(assets: &Assets) -> Weight {
96 assets.weigh_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
97 }
98 fn reserve_asset_deposited(assets: &Assets) -> Weight {
99 assets.weigh_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
100 }
101 fn receive_teleported_asset(assets: &Assets) -> Weight {
102 assets.weigh_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
103 }
104 fn query_response(
105 _query_id: &u64,
106 _response: &Response,
107 _max_weight: &Weight,
108 _querier: &Option<Location>,
109 ) -> Weight {
110 XcmGeneric::<Runtime>::query_response()
111 }
112 fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
113 assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
114 }
115 fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
116 assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
117 }
118 fn transact(
119 _origin_kind: &OriginKind,
120 _fallback_max_weight: &Option<Weight>,
121 _call: &DoubleEncoded<RuntimeCall>,
122 ) -> Weight {
123 XcmGeneric::<Runtime>::transact()
124 }
125 fn hrmp_new_channel_open_request(
126 _sender: &u32,
127 _max_message_size: &u32,
128 _max_capacity: &u32,
129 ) -> Weight {
130 Weight::MAX
132 }
133 fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
134 Weight::MAX
136 }
137 fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
138 Weight::MAX
140 }
141 fn clear_origin() -> Weight {
142 XcmGeneric::<Runtime>::clear_origin()
143 }
144 fn descend_origin(_who: &InteriorLocation) -> Weight {
145 XcmGeneric::<Runtime>::descend_origin()
146 }
147 fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
148 XcmGeneric::<Runtime>::report_error()
149 }
150
151 fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
152 assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
153 }
154 fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
155 assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
156 }
157 fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
158 Weight::MAX
160 }
161 fn initiate_reserve_withdraw(
162 assets: &AssetFilter,
163 _reserve: &Location,
164 _xcm: &Xcm<()>,
165 ) -> Weight {
166 assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
167 }
168 fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
169 assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
170 }
171 fn initiate_transfer(
172 _dest: &Location,
173 remote_fees: &Option<AssetTransferFilter>,
174 _preserve_origin: &bool,
175 assets: &BoundedVec<AssetTransferFilter, MaxAssetTransferFilters>,
176 _xcm: &Xcm<()>,
177 ) -> Weight {
178 let base_weight = XcmBalancesWeight::<Runtime>::initiate_transfer();
179 let mut weight = if let Some(remote_fees) = remote_fees {
180 let fees = remote_fees.inner();
181 fees.weigh_assets(base_weight)
182 } else {
183 base_weight
184 };
185 for asset_filter in assets {
186 let assets = asset_filter.inner();
187 let extra = assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_transfer());
188 weight = weight.saturating_add(extra);
189 }
190 weight
191 }
192 fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
193 XcmGeneric::<Runtime>::report_holding()
194 }
195 fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
196 XcmGeneric::<Runtime>::buy_execution()
197 }
198 fn pay_fees(_asset: &Asset) -> Weight {
199 XcmGeneric::<Runtime>::pay_fees()
200 }
201 fn refund_surplus() -> Weight {
202 XcmGeneric::<Runtime>::refund_surplus()
203 }
204 fn set_error_handler(_xcm: &Xcm<RuntimeCall>) -> Weight {
205 XcmGeneric::<Runtime>::set_error_handler()
206 }
207 fn set_appendix(_xcm: &Xcm<RuntimeCall>) -> Weight {
208 XcmGeneric::<Runtime>::set_appendix()
209 }
210 fn clear_error() -> Weight {
211 XcmGeneric::<Runtime>::clear_error()
212 }
213 fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
214 let mut weight = Weight::zero();
215 for hint in hints {
216 match hint {
217 AssetClaimer { .. } => {
218 weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
219 },
220 }
221 }
222 weight
223 }
224 fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
225 XcmGeneric::<Runtime>::claim_asset()
226 }
227 fn trap(_code: &u64) -> Weight {
228 XcmGeneric::<Runtime>::trap()
229 }
230 fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> Weight {
231 XcmGeneric::<Runtime>::subscribe_version()
232 }
233 fn unsubscribe_version() -> Weight {
234 XcmGeneric::<Runtime>::unsubscribe_version()
235 }
236 fn burn_asset(assets: &Assets) -> Weight {
237 assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
238 }
239 fn expect_asset(assets: &Assets) -> Weight {
240 assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
241 }
242 fn expect_origin(_origin: &Option<Location>) -> Weight {
243 XcmGeneric::<Runtime>::expect_origin()
244 }
245 fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
246 XcmGeneric::<Runtime>::expect_error()
247 }
248 fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight {
249 XcmGeneric::<Runtime>::expect_transact_status()
250 }
251 fn query_pallet(_module_name: &Vec<u8>, _response_info: &QueryResponseInfo) -> Weight {
252 XcmGeneric::<Runtime>::query_pallet()
253 }
254 fn expect_pallet(
255 _index: &u32,
256 _name: &Vec<u8>,
257 _module_name: &Vec<u8>,
258 _crate_major: &u32,
259 _min_crate_minor: &u32,
260 ) -> Weight {
261 XcmGeneric::<Runtime>::expect_pallet()
262 }
263 fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight {
264 XcmGeneric::<Runtime>::report_transact_status()
265 }
266 fn clear_transact_status() -> Weight {
267 XcmGeneric::<Runtime>::clear_transact_status()
268 }
269 fn universal_origin(_: &Junction) -> Weight {
270 Weight::MAX
272 }
273 fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
274 Weight::MAX
276 }
277 fn lock_asset(_: &Asset, _: &Location) -> Weight {
278 Weight::MAX
280 }
281 fn unlock_asset(_: &Asset, _: &Location) -> Weight {
282 Weight::MAX
284 }
285 fn note_unlockable(_: &Asset, _: &Location) -> Weight {
286 Weight::MAX
288 }
289 fn request_unlock(_: &Asset, _: &Location) -> Weight {
290 Weight::MAX
292 }
293 fn set_fees_mode(_: &bool) -> Weight {
294 XcmGeneric::<Runtime>::set_fees_mode()
295 }
296 fn set_topic(_topic: &[u8; 32]) -> Weight {
297 XcmGeneric::<Runtime>::set_topic()
298 }
299 fn clear_topic() -> Weight {
300 XcmGeneric::<Runtime>::clear_topic()
301 }
302 fn alias_origin(_: &Location) -> Weight {
303 XcmGeneric::<Runtime>::alias_origin()
304 }
305 fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
306 XcmGeneric::<Runtime>::unpaid_execution()
307 }
308 fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<RuntimeCall>) -> Weight {
309 XcmGeneric::<Runtime>::execute_with_origin()
310 }
311}
312
313#[test]
314fn all_counted_has_a_sane_weight_upper_limit() {
315 let assets = AssetFilter::Wild(AllCounted(4294967295));
316 let weight = Weight::from_parts(1000, 1000);
317
318 assert_eq!(assets.weigh_assets(weight), weight * MAX_ASSETS);
319}