1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
pub mod pallet_xcm_benchmarks_generic;
18

            
19
use {
20
    crate::Runtime,
21
    frame_support::weights::Weight,
22
    pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric,
23
    sp_std::prelude::*,
24
    staging_xcm::{
25
        latest::{prelude::*, Weight as XCMWeight},
26
        DoubleEncoded,
27
    },
28
};
29

            
30
trait WeighAssets {
31
    fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
32
}
33

            
34
impl WeighAssets for Assets {
35
147
    fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
36
147
        weight.saturating_mul(self.inner().iter().count() as u64)
37
147
    }
38
}
39

            
40
// Values copied from statemint benchmarks
41
const ASSET_BURN_MAX_PROOF_SIZE: u64 = 7242;
42
const ASSET_MINT_MAX_PROOF_SIZE: u64 = 7242;
43
const ASSET_TRANSFER_MAX_PROOF_SIZE: u64 = 13412;
44

            
45
// For now we are returning benchmarked weights only for generic XCM instructions.
46
// Fungible XCM instructions will return a fixed weight value of
47
// 200_000_000 ref_time and its proper PoV weight taken from statemint benchmarks.
48
//
49
// TODO: add the fungible benchmarked values once these are calculated.
50
pub struct XcmWeight<RuntimeCall>(core::marker::PhantomData<RuntimeCall>);
51
impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for XcmWeight<RuntimeCall>
52
where
53
    Runtime: frame_system::Config,
54
{
55
40
    fn withdraw_asset(assets: &Assets) -> XCMWeight {
56
40
        assets.weigh_multi_assets(XCMWeight::from_parts(
57
40
            200_000_000u64,
58
40
            ASSET_BURN_MAX_PROOF_SIZE,
59
40
        ))
60
40
    }
61
61
    fn reserve_asset_deposited(assets: &Assets) -> XCMWeight {
62
61
        assets.weigh_multi_assets(XCMWeight::from_parts(200_000_000u64, 0))
63
61
    }
64
6
    fn receive_teleported_asset(_assets: &Assets) -> XCMWeight {
65
6
        XCMWeight::MAX
66
6
    }
67
10
    fn query_response(
68
10
        _query_id: &u64,
69
10
        _response: &Response,
70
10
        _max_weight: &Weight,
71
10
        _querier: &Option<Location>,
72
10
    ) -> XCMWeight {
73
10
        XcmGeneric::<Runtime>::query_response()
74
10
    }
75
44
    fn transfer_asset(assets: &Assets, _dest: &Location) -> XCMWeight {
76
44
        assets.weigh_multi_assets(XCMWeight::from_parts(
77
44
            200_000_000u64,
78
44
            ASSET_TRANSFER_MAX_PROOF_SIZE,
79
44
        ))
80
44
    }
81
    fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> XCMWeight {
82
        assets.weigh_multi_assets(XCMWeight::from_parts(
83
            200_000_000u64,
84
            ASSET_TRANSFER_MAX_PROOF_SIZE,
85
        ))
86
    }
87
41
    fn transact(
88
41
        _origin_type: &OriginKind,
89
41
        _require_weight_at_most: &Weight,
90
41
        _call: &DoubleEncoded<RuntimeCall>,
91
41
    ) -> XCMWeight {
92
41
        XcmGeneric::<Runtime>::transact()
93
41
    }
94
    fn hrmp_new_channel_open_request(
95
        _sender: &u32,
96
        _max_message_size: &u32,
97
        _max_capacity: &u32,
98
    ) -> XCMWeight {
99
        // XCM Executor does not currently support HRMP channel operations
100
        Weight::MAX
101
    }
102
    fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight {
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) -> XCMWeight {
107
        // XCM Executor does not currently support HRMP channel operations
108
        Weight::MAX
109
    }
110
61
    fn clear_origin() -> XCMWeight {
111
61
        XcmGeneric::<Runtime>::clear_origin()
112
61
    }
113
27
    fn descend_origin(_who: &InteriorLocation) -> XCMWeight {
114
27
        XcmGeneric::<Runtime>::descend_origin()
115
27
    }
116
    fn report_error(_query_response_info: &QueryResponseInfo) -> XCMWeight {
117
        XcmGeneric::<Runtime>::report_error()
118
    }
119
94
    fn deposit_asset(_assets: &AssetFilter, _dest: &Location) -> XCMWeight {
120
94
        Weight::from_parts(200_000_000u64, ASSET_MINT_MAX_PROOF_SIZE)
121
94
    }
122
    fn deposit_reserve_asset(_assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> XCMWeight {
123
        Weight::from_parts(200_000_000u64, ASSET_MINT_MAX_PROOF_SIZE)
124
    }
125
    fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> XCMWeight {
126
        Weight::MAX
127
    }
128
2
    fn initiate_reserve_withdraw(
129
2
        _assets: &AssetFilter,
130
2
        _reserve: &Location,
131
2
        _xcm: &Xcm<()>,
132
2
    ) -> XCMWeight {
133
2
        XCMWeight::from_parts(200_000_000u64, ASSET_TRANSFER_MAX_PROOF_SIZE)
134
2
    }
135
    fn initiate_teleport(_assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> XCMWeight {
136
        XCMWeight::MAX
137
    }
138
    fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
139
        XcmGeneric::<Runtime>::report_holding()
140
    }
141
103
    fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> XCMWeight {
142
103
        XcmGeneric::<Runtime>::buy_execution()
143
103
    }
144
2
    fn refund_surplus() -> XCMWeight {
145
2
        XcmGeneric::<Runtime>::refund_surplus()
146
2
    }
147
18
    fn set_error_handler(_xcm: &Xcm<RuntimeCall>) -> XCMWeight {
148
18
        XcmGeneric::<Runtime>::set_error_handler()
149
18
    }
150
12
    fn set_appendix(_xcm: &Xcm<RuntimeCall>) -> XCMWeight {
151
12
        XcmGeneric::<Runtime>::set_appendix()
152
12
    }
153
    fn clear_error() -> XCMWeight {
154
        XcmGeneric::<Runtime>::clear_error()
155
    }
156
    fn claim_asset(assets: &Assets, _ticket: &Location) -> XCMWeight {
157
        assets.weigh_multi_assets(XcmGeneric::<Runtime>::claim_asset())
158
    }
159
13
    fn trap(_code: &u64) -> XCMWeight {
160
13
        XcmGeneric::<Runtime>::trap()
161
13
    }
162
    fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> XCMWeight {
163
        XcmGeneric::<Runtime>::subscribe_version()
164
    }
165
    fn unsubscribe_version() -> XCMWeight {
166
        XcmGeneric::<Runtime>::unsubscribe_version()
167
    }
168
2
    fn burn_asset(assets: &Assets) -> Weight {
169
2
        assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
170
2
    }
171
    fn expect_asset(assets: &Assets) -> Weight {
172
        assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
173
    }
174
    fn expect_origin(_origin: &Option<Location>) -> Weight {
175
        XcmGeneric::<Runtime>::expect_origin()
176
    }
177
    fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
178
        XcmGeneric::<Runtime>::expect_error()
179
    }
180
    fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight {
181
        XcmGeneric::<Runtime>::expect_transact_status()
182
    }
183
    fn query_pallet(_module_name: &Vec<u8>, _response_info: &QueryResponseInfo) -> Weight {
184
        XcmGeneric::<Runtime>::query_pallet()
185
    }
186
    fn expect_pallet(
187
        _index: &u32,
188
        _name: &Vec<u8>,
189
        _module_name: &Vec<u8>,
190
        _crate_major: &u32,
191
        _min_crate_minor: &u32,
192
    ) -> Weight {
193
        XcmGeneric::<Runtime>::expect_pallet()
194
    }
195
    fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight {
196
        XcmGeneric::<Runtime>::report_transact_status()
197
    }
198
    fn clear_transact_status() -> Weight {
199
        XcmGeneric::<Runtime>::clear_transact_status()
200
    }
201
    fn universal_origin(_: &Junction) -> Weight {
202
        Weight::MAX
203
    }
204
    fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
205
        Weight::MAX
206
    }
207
    fn lock_asset(_: &Asset, _: &Location) -> Weight {
208
        Weight::MAX
209
    }
210
    fn unlock_asset(_: &Asset, _: &Location) -> Weight {
211
        Weight::MAX
212
    }
213
    fn note_unlockable(_: &Asset, _: &Location) -> Weight {
214
        Weight::MAX
215
    }
216
    fn request_unlock(_: &Asset, _: &Location) -> Weight {
217
        Weight::MAX
218
    }
219
2
    fn set_fees_mode(_: &bool) -> Weight {
220
2
        XcmGeneric::<Runtime>::set_fees_mode()
221
2
    }
222
24
    fn set_topic(_topic: &[u8; 32]) -> Weight {
223
24
        XcmGeneric::<Runtime>::set_topic()
224
24
    }
225
    fn clear_topic() -> Weight {
226
        XcmGeneric::<Runtime>::clear_topic()
227
    }
228
    fn alias_origin(_: &Location) -> Weight {
229
        // XCM Executor does not currently support alias origin operations
230
        Weight::MAX
231
    }
232
1
    fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
233
1
        XcmGeneric::<Runtime>::unpaid_execution()
234
1
    }
235
}