gear_core/
costs.rs

1// This file is part of Gear.
2
3// Copyright (C) 2022-2025 Gear Technologies Inc.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Costs module.
20
21use crate::pages::{GearPagesAmount, WasmPagesAmount};
22use core::{fmt::Debug, marker::PhantomData};
23use paste::paste;
24
25/// Gas cost per some type of action or data size.
26#[derive(Clone, Copy, PartialEq, Eq)]
27pub struct CostOf<T> {
28    cost: u64,
29    _phantom: PhantomData<T>,
30}
31
32impl<T> CostOf<T> {
33    /// Const constructor
34    pub const fn new(cost: u64) -> Self {
35        Self {
36            cost,
37            _phantom: PhantomData,
38        }
39    }
40
41    /// Cost for one.
42    pub const fn cost_for_one(&self) -> u64 {
43        self.cost
44    }
45}
46
47impl<T: Into<u32>> CostOf<T> {
48    /// Calculate (saturating mult) cost for `num` amount of `T`.
49    pub fn cost_for(&self, num: T) -> u64 {
50        self.cost.saturating_mul(Into::<u32>::into(num).into())
51    }
52}
53
54impl<T> Debug for CostOf<T> {
55    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56        f.write_fmt(format_args!("{}", &self.cost))
57    }
58}
59
60impl<T> From<u64> for CostOf<T> {
61    fn from(cost: u64) -> Self {
62        CostOf::new(cost)
63    }
64}
65
66impl<T> From<CostOf<T>> for u64 {
67    fn from(value: CostOf<T>) -> Self {
68        value.cost
69    }
70}
71
72impl<T> Default for CostOf<T> {
73    fn default() -> Self {
74        CostOf::new(0)
75    }
76}
77
78/// Some actions or calls amount.
79#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, derive_more::From, derive_more::Into)]
80pub struct CallsAmount(u32);
81
82impl CostOf<CallsAmount> {
83    /// Calculate (saturating add) cost for `per_byte` amount of `BytesAmount` (saturating mul).
84    pub fn with_bytes(&self, per_byte: CostOf<BytesAmount>, amount: BytesAmount) -> u64 {
85        self.cost_for_one()
86            .saturating_add(per_byte.cost_for(amount))
87    }
88}
89
90/// Bytes amount.
91#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, derive_more::From, derive_more::Into)]
92pub struct BytesAmount(u32);
93
94/// Chain blocks amount.
95#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, derive_more::From, derive_more::Into)]
96pub struct BlocksAmount(u32);
97
98/// Program imported function call (syscall) costs.
99#[derive(Debug, Clone, Default, PartialEq, Eq)]
100pub struct SyscallCosts {
101    /// Cost of calling `alloc`.
102    pub alloc: CostOf<CallsAmount>,
103
104    /// Cost of calling `free`.
105    pub free: CostOf<CallsAmount>,
106
107    /// Cost of calling `free_range`
108    pub free_range: CostOf<CallsAmount>,
109
110    /// Cost of calling `free_range` per page
111    pub free_range_per_page: CostOf<WasmPagesAmount>,
112
113    /// Cost of calling `gr_reserve_gas`.
114    pub gr_reserve_gas: CostOf<CallsAmount>,
115
116    /// Cost of calling `gr_unreserve_gas`
117    pub gr_unreserve_gas: CostOf<CallsAmount>,
118
119    /// Cost of calling `gr_system_reserve_gas`
120    pub gr_system_reserve_gas: CostOf<CallsAmount>,
121
122    /// Cost of calling `gr_gas_available`.
123    pub gr_gas_available: CostOf<CallsAmount>,
124
125    /// Cost of calling `gr_message_id`.
126    pub gr_message_id: CostOf<CallsAmount>,
127
128    /// Cost of calling `gr_program_id`.
129    pub gr_program_id: CostOf<CallsAmount>,
130
131    /// Cost of calling `gr_source`.
132    pub gr_source: CostOf<CallsAmount>,
133
134    /// Cost of calling `gr_value`.
135    pub gr_value: CostOf<CallsAmount>,
136
137    /// Cost of calling `gr_value_available`.
138    pub gr_value_available: CostOf<CallsAmount>,
139
140    /// Cost of calling `gr_size`.
141    pub gr_size: CostOf<CallsAmount>,
142
143    /// Cost of calling `gr_read`.
144    pub gr_read: CostOf<CallsAmount>,
145
146    /// Cost per payload byte for `gr_read`.
147    pub gr_read_per_byte: CostOf<BytesAmount>,
148
149    /// Cost of calling `gr_env_vars`.
150    pub gr_env_vars: CostOf<CallsAmount>,
151
152    /// Cost of calling `gr_block_height`.
153    pub gr_block_height: CostOf<CallsAmount>,
154
155    /// Cost of calling `gr_block_timestamp`.
156    pub gr_block_timestamp: CostOf<CallsAmount>,
157
158    /// Cost of calling `gr_random`.
159    pub gr_random: CostOf<CallsAmount>,
160
161    /// Cost of calling `gr_reply_deposit`.
162    pub gr_reply_deposit: CostOf<CallsAmount>,
163
164    /// Cost of calling `gr_send`
165    pub gr_send: CostOf<CallsAmount>,
166
167    /// Cost per bytes for `gr_send`.
168    pub gr_send_per_byte: CostOf<BytesAmount>,
169
170    /// Cost of calling `gr_send_wgas`.
171    pub gr_send_wgas: CostOf<CallsAmount>,
172
173    /// Cost of calling `gr_send_wgas` per one payload byte.
174    pub gr_send_wgas_per_byte: CostOf<BytesAmount>,
175
176    /// Cost of calling `gr_send_init`.
177    pub gr_send_init: CostOf<CallsAmount>,
178
179    /// Cost of calling `gr_send_push`.
180    pub gr_send_push: CostOf<CallsAmount>,
181
182    /// Cost per payload byte by `gr_send_push`.
183    pub gr_send_push_per_byte: CostOf<BytesAmount>,
184
185    /// Cost of calling `gr_send_commit`.
186    pub gr_send_commit: CostOf<CallsAmount>,
187
188    /// Cost of calling `gr_send_commit_wgas`.
189    pub gr_send_commit_wgas: CostOf<CallsAmount>,
190
191    /// Cost of calling `gr_reservation_send`.
192    pub gr_reservation_send: CostOf<CallsAmount>,
193
194    /// Cost of calling `gr_reservation_send` per one payload byte.
195    pub gr_reservation_send_per_byte: CostOf<BytesAmount>,
196
197    /// Cost of calling `gr_reservation_send_commit`.
198    pub gr_reservation_send_commit: CostOf<CallsAmount>,
199
200    /// Cost of calling `gr_send_init`.
201    pub gr_send_input: CostOf<CallsAmount>,
202
203    /// Cost of calling `gr_send_init_wgas`.
204    pub gr_send_input_wgas: CostOf<CallsAmount>,
205
206    /// Cost of calling `gr_send_push_input`.
207    pub gr_send_push_input: CostOf<CallsAmount>,
208
209    /// Cost per payload byte by `gr_send_push_input`.
210    pub gr_send_push_input_per_byte: CostOf<BytesAmount>,
211
212    /// Cost of calling `gr_reply`.
213    pub gr_reply: CostOf<CallsAmount>,
214
215    /// Cost of calling `gr_reply` per one payload byte.
216    pub gr_reply_per_byte: CostOf<BytesAmount>,
217
218    /// Cost of calling `gr_reply_wgas`.
219    pub gr_reply_wgas: CostOf<CallsAmount>,
220
221    /// Cost of calling `gr_reply_wgas` per one payload byte.
222    pub gr_reply_wgas_per_byte: CostOf<BytesAmount>,
223
224    /// Cost of calling `gr_reply_commit`.
225    pub gr_reply_commit: CostOf<CallsAmount>,
226
227    /// Cost of calling `gr_reply_commit_wgas`.
228    pub gr_reply_commit_wgas: CostOf<CallsAmount>,
229
230    /// Cost of calling `gr_reservation_reply`.
231    pub gr_reservation_reply: CostOf<CallsAmount>,
232
233    /// Cost of calling `gr_reservation_reply` per one payload byte.
234    pub gr_reservation_reply_per_byte: CostOf<BytesAmount>,
235
236    /// Cost of calling `gr_reservation_reply_commit`.
237    pub gr_reservation_reply_commit: CostOf<CallsAmount>,
238
239    /// Cost of calling `gr_reply_push`.
240    pub gr_reply_push: CostOf<CallsAmount>,
241
242    /// Cost per payload byte by `gr_reply_push`.
243    pub gr_reply_push_per_byte: CostOf<BytesAmount>,
244
245    /// Cost of calling `gr_reply_input`.
246    pub gr_reply_input: CostOf<CallsAmount>,
247
248    /// Cost of calling `gr_reply_input_wgas`.
249    pub gr_reply_input_wgas: CostOf<CallsAmount>,
250
251    /// Cost of calling `gr_reply_push_input`.
252    pub gr_reply_push_input: CostOf<CallsAmount>,
253
254    /// Cost per payload byte by `gr_reply_push_input`.
255    pub gr_reply_push_input_per_byte: CostOf<BytesAmount>,
256
257    /// Cost of calling `gr_reply_to`.
258    pub gr_reply_to: CostOf<CallsAmount>,
259
260    /// Cost of calling `gr_signal_code`.
261    pub gr_signal_code: CostOf<CallsAmount>,
262
263    /// Cost of calling `gr_signal_from`.
264    pub gr_signal_from: CostOf<CallsAmount>,
265
266    /// Cost of calling `gr_debug`.
267    pub gr_debug: CostOf<CallsAmount>,
268
269    /// Cost per payload byte by `gr_debug`.
270    pub gr_debug_per_byte: CostOf<BytesAmount>,
271
272    /// Cost of calling `gr_reply_code`.
273    pub gr_reply_code: CostOf<CallsAmount>,
274
275    /// Cost of calling `gr_exit`.
276    pub gr_exit: CostOf<CallsAmount>,
277
278    /// Cost of calling `gr_leave`.
279    pub gr_leave: CostOf<CallsAmount>,
280
281    /// Cost of calling `gr_wait`.
282    pub gr_wait: CostOf<CallsAmount>,
283
284    /// Cost of calling `gr_wait_for`.
285    pub gr_wait_for: CostOf<CallsAmount>,
286
287    /// Cost of calling `gr_wait_up_to`.
288    pub gr_wait_up_to: CostOf<CallsAmount>,
289
290    /// Cost of calling `gr_wake`.
291    pub gr_wake: CostOf<CallsAmount>,
292
293    /// Cost of calling `gr_create_program_wgas`.
294    pub gr_create_program: CostOf<CallsAmount>,
295
296    /// Cost per payload byte by `gr_create_program_wgas`.
297    pub gr_create_program_payload_per_byte: CostOf<BytesAmount>,
298
299    /// Cost per salt byte by `gr_create_program_wgas`.
300    pub gr_create_program_salt_per_byte: CostOf<BytesAmount>,
301
302    /// Cost of calling `gr_create_program_wgas`.
303    pub gr_create_program_wgas: CostOf<CallsAmount>,
304
305    /// Cost per payload byte by `gr_create_program_wgas`.
306    pub gr_create_program_wgas_payload_per_byte: CostOf<BytesAmount>,
307
308    /// Cost per salt byte by `gr_create_program_wgas`.
309    pub gr_create_program_wgas_salt_per_byte: CostOf<BytesAmount>,
310}
311
312/// Enumerates syscalls that can be charged by gas meter.
313#[derive(Debug, Copy, Clone)]
314pub enum CostToken {
315    /// Zero cost.
316    Null,
317    /// Cost of calling `alloc`.
318    Alloc,
319    /// Cost of calling `free`.
320    Free,
321    /// Cost of calling `free_range`
322    FreeRange,
323    /// Cost of calling `gr_reserve_gas`.
324    ReserveGas,
325    /// Cost of calling `gr_unreserve_gas`.
326    UnreserveGas,
327    /// Cost of calling `gr_system_reserve_gas`.
328    SystemReserveGas,
329    /// Cost of calling `gr_gas_available`.
330    GasAvailable,
331    /// Cost of calling `gr_message_id`.
332    MsgId,
333    /// Cost of calling `gr_program_id`.
334    ActorId,
335    /// Cost of calling `gr_source`.
336    Source,
337    /// Cost of calling `gr_value`.
338    Value,
339    /// Cost of calling `gr_value_available`.
340    ValueAvailable,
341    /// Cost of calling `gr_size`.
342    Size,
343    /// Cost of calling `gr_read`.
344    Read,
345    /// Cost of calling `gr_env_vars`.
346    EnvVars,
347    /// Cost of calling `gr_block_height`.
348    BlockHeight,
349    /// Cost of calling `gr_block_timestamp`.
350    BlockTimestamp,
351    /// Cost of calling `gr_random`.
352    Random,
353    /// Cost of calling `gr_reply_deposit`.
354    ReplyDeposit,
355    /// Cost of calling `gr_send`, taking in account payload size.
356    Send(BytesAmount),
357    /// Cost of calling `gr_send_wgas`, taking in account payload size.
358    SendWGas(BytesAmount),
359    /// Cost of calling `gr_send_init`.
360    SendInit,
361    /// Cost of calling `gr_send_push`, taking in account payload size.
362    SendPush(BytesAmount),
363    /// Cost of calling `gr_send_commit`.
364    SendCommit,
365    /// Cost of calling `gr_send_commit_wgas`.
366    SendCommitWGas,
367    /// Cost of calling `gr_reservation_send`, taking in account payload size.
368    ReservationSend(BytesAmount),
369    /// Cost of calling `gr_reservation_send_commit`.
370    ReservationSendCommit,
371    /// Cost of calling `gr_send_input`.
372    SendInput,
373    /// Cost of calling `gr_send_input_wgas`.
374    SendInputWGas,
375    /// Cost of calling `gr_send_push_input`.
376    SendPushInput,
377    /// Cost of calling `gr_reply`, taking in account payload size.
378    Reply(BytesAmount),
379    /// Cost of calling `gr_reply_wgas`, taking in account payload size.
380    ReplyWGas(BytesAmount),
381    /// Cost of calling `gr_reply_push`, taking in account payload size.
382    ReplyPush(BytesAmount),
383    /// Cost of calling `gr_reply_commit`.
384    ReplyCommit,
385    /// Cost of calling `gr_reply_commit_wgas`.
386    ReplyCommitWGas,
387    /// Cost of calling `gr_reservation_reply`, taking in account payload size.
388    ReservationReply(BytesAmount),
389    /// Cost of calling `gr_reservation_reply_commit`.
390    ReservationReplyCommit,
391    /// Cost of calling `gr_reply_input`.
392    ReplyInput,
393    /// Cost of calling `gr_reply_input_wgas`.
394    ReplyInputWGas,
395    /// Cost of calling `gr_reply_push_input`.
396    ReplyPushInput,
397    /// Cost of calling `gr_reply_to`.
398    ReplyTo,
399    /// Cost of calling `gr_signal_code`.
400    SignalCode,
401    /// Cost of calling `gr_signal_from`.
402    SignalFrom,
403    /// Cost of calling `gr_debug`, taking in account payload size.
404    Debug(BytesAmount),
405    /// Cost of calling `gr_reply_code`.
406    ReplyCode,
407    /// Cost of calling `gr_exit`.
408    Exit,
409    /// Cost of calling `gr_leave`.
410    Leave,
411    /// Cost of calling `gr_wait`.
412    Wait,
413    /// Cost of calling `gr_wait_for`.
414    WaitFor,
415    /// Cost of calling `gr_wait_up_to`.
416    WaitUpTo,
417    /// Cost of calling `gr_wake`.
418    Wake,
419    /// Cost of calling `gr_create_program`, taking in account payload and salt size.
420    CreateProgram(BytesAmount, BytesAmount),
421    /// Cost of calling `gr_create_program_wgas`, taking in account payload and salt size.
422    CreateProgramWGas(BytesAmount, BytesAmount),
423}
424
425impl SyscallCosts {
426    /// Get cost for a token.
427    pub fn cost_for_token(&self, token: CostToken) -> u64 {
428        use CostToken::*;
429
430        macro_rules! cost_with_per_byte {
431            ($name:ident, $len:expr) => {
432                paste! {
433                    self.$name.with_bytes(self.[< $name _per_byte >], $len)
434                }
435            };
436        }
437
438        match token {
439            Null => 0,
440            Alloc => self.alloc.cost_for_one(),
441            Free => self.free.cost_for_one(),
442            FreeRange => self.free_range.cost_for_one(),
443            ReserveGas => self.gr_reserve_gas.cost_for_one(),
444            UnreserveGas => self.gr_unreserve_gas.cost_for_one(),
445            SystemReserveGas => self.gr_system_reserve_gas.cost_for_one(),
446            GasAvailable => self.gr_gas_available.cost_for_one(),
447            MsgId => self.gr_message_id.cost_for_one(),
448            ActorId => self.gr_program_id.cost_for_one(),
449            Source => self.gr_source.cost_for_one(),
450            Value => self.gr_value.cost_for_one(),
451            ValueAvailable => self.gr_value_available.cost_for_one(),
452            Size => self.gr_size.cost_for_one(),
453            Read => self.gr_read.cost_for_one(),
454            EnvVars => self.gr_env_vars.cost_for_one(),
455            BlockHeight => self.gr_block_height.cost_for_one(),
456            BlockTimestamp => self.gr_block_timestamp.cost_for_one(),
457            Random => self.gr_random.cost_for_one(),
458            ReplyDeposit => self.gr_reply_deposit.cost_for_one(),
459            Send(len) => cost_with_per_byte!(gr_send, len),
460            SendWGas(len) => cost_with_per_byte!(gr_send_wgas, len),
461            SendInit => self.gr_send_init.cost_for_one(),
462            SendPush(len) => cost_with_per_byte!(gr_send_push, len),
463            SendCommit => self.gr_send_commit.cost_for_one(),
464            SendCommitWGas => self.gr_send_commit_wgas.cost_for_one(),
465            ReservationSend(len) => cost_with_per_byte!(gr_reservation_send, len),
466            ReservationSendCommit => self.gr_reservation_send_commit.cost_for_one(),
467            SendInput => self.gr_send_input.cost_for_one(),
468            SendInputWGas => self.gr_send_input_wgas.cost_for_one(),
469            SendPushInput => self.gr_send_push_input.cost_for_one(),
470            Reply(len) => cost_with_per_byte!(gr_reply, len),
471            ReplyWGas(len) => cost_with_per_byte!(gr_reply_wgas, len),
472            ReplyPush(len) => cost_with_per_byte!(gr_reply_push, len),
473            ReplyCommit => self.gr_reply_commit.cost_for_one(),
474            ReplyCommitWGas => self.gr_reply_commit_wgas.cost_for_one(),
475            ReservationReply(len) => cost_with_per_byte!(gr_reservation_reply, len),
476            ReservationReplyCommit => self.gr_reservation_reply_commit.cost_for_one(),
477            ReplyInput => self.gr_reply_input.cost_for_one(),
478            ReplyInputWGas => self.gr_reply_input_wgas.cost_for_one(),
479            ReplyPushInput => self.gr_reply_push_input.cost_for_one(),
480            ReplyTo => self.gr_reply_to.cost_for_one(),
481            SignalCode => self.gr_signal_code.cost_for_one(),
482            SignalFrom => self.gr_signal_from.cost_for_one(),
483            Debug(len) => cost_with_per_byte!(gr_debug, len),
484            ReplyCode => self.gr_reply_code.cost_for_one(),
485            Exit => self.gr_exit.cost_for_one(),
486            Leave => self.gr_leave.cost_for_one(),
487            Wait => self.gr_wait.cost_for_one(),
488            WaitFor => self.gr_wait_for.cost_for_one(),
489            WaitUpTo => self.gr_wait_up_to.cost_for_one(),
490            Wake => self.gr_wake.cost_for_one(),
491            CreateProgram(payload, salt) => CostOf::from(
492                self.gr_create_program
493                    .with_bytes(self.gr_create_program_payload_per_byte, payload),
494            )
495            .with_bytes(self.gr_create_program_salt_per_byte, salt),
496            CreateProgramWGas(payload, salt) => CostOf::from(
497                self.gr_create_program_wgas
498                    .with_bytes(self.gr_create_program_wgas_payload_per_byte, payload),
499            )
500            .with_bytes(self.gr_create_program_wgas_salt_per_byte, salt),
501        }
502    }
503}
504
505/// Memory pages costs.
506#[derive(Debug, Default, Clone, PartialEq, Eq)]
507pub struct PagesCosts {
508    /// Loading from storage and moving it in program memory cost.
509    pub load_page_data: CostOf<GearPagesAmount>,
510    /// Uploading page data to storage cost.
511    pub upload_page_data: CostOf<GearPagesAmount>,
512    /// Memory grow cost.
513    pub mem_grow: CostOf<GearPagesAmount>,
514    /// Memory grow per page cost.
515    pub mem_grow_per_page: CostOf<GearPagesAmount>,
516    /// Parachain read heuristic cost.
517    pub parachain_read_heuristic: CostOf<GearPagesAmount>,
518}
519
520/// Memory pages lazy access costs.
521#[derive(Debug, Default, Clone, PartialEq, Eq)]
522pub struct LazyPagesCosts {
523    /// First read page access cost.
524    pub signal_read: CostOf<GearPagesAmount>,
525    /// First write page access cost.
526    pub signal_write: CostOf<GearPagesAmount>,
527    /// First write access cost for page, which has been already read accessed.
528    pub signal_write_after_read: CostOf<GearPagesAmount>,
529    /// First read page access cost from host function call.
530    pub host_func_read: CostOf<GearPagesAmount>,
531    /// First write page access cost from host function call.
532    pub host_func_write: CostOf<GearPagesAmount>,
533    /// First write page access cost from host function call.
534    pub host_func_write_after_read: CostOf<GearPagesAmount>,
535    /// Loading page data from storage cost.
536    pub load_page_storage_data: CostOf<GearPagesAmount>,
537}
538
539/// IO costs.
540#[derive(Debug, Default, Clone, PartialEq, Eq)]
541pub struct IoCosts {
542    /// Consts for common pages.
543    pub common: PagesCosts,
544    /// Consts for lazy pages.
545    pub lazy_pages: LazyPagesCosts,
546}
547
548/// Holding in storages rent costs.
549#[derive(Debug, Default, Clone, PartialEq, Eq)]
550pub struct RentCosts {
551    /// Holding message in waitlist cost per block.
552    pub waitlist: CostOf<BlocksAmount>,
553    /// Holding message in dispatch stash cost per block.
554    pub dispatch_stash: CostOf<BlocksAmount>,
555    /// Holding reservation cost per block.
556    pub reservation: CostOf<BlocksAmount>,
557}
558
559/// Execution externalities costs.
560#[derive(Debug, Default, Clone, PartialEq, Eq)]
561pub struct ExtCosts {
562    /// Syscalls costs.
563    pub syscalls: SyscallCosts,
564    /// Rent costs.
565    pub rent: RentCosts,
566    /// Memory grow cost.
567    pub mem_grow: CostOf<CallsAmount>,
568    /// Memory grow per page cost.
569    pub mem_grow_per_page: CostOf<WasmPagesAmount>,
570}
571
572/// Module instantiation costs.
573#[derive(Debug, Default, Clone, PartialEq, Eq)]
574pub struct InstantiationCosts {
575    /// WASM module code section instantiation per byte cost.
576    pub code_section_per_byte: CostOf<BytesAmount>,
577    /// WASM module data section instantiation per byte cost.
578    pub data_section_per_byte: CostOf<BytesAmount>,
579    /// WASM module global section instantiation per byte cost.
580    pub global_section_per_byte: CostOf<BytesAmount>,
581    /// WASM module table section instantiation per byte cost.
582    pub table_section_per_byte: CostOf<BytesAmount>,
583    /// WASM module element section instantiation per byte cost.
584    pub element_section_per_byte: CostOf<BytesAmount>,
585    /// WASM module type section instantiation per byte cost.
586    pub type_section_per_byte: CostOf<BytesAmount>,
587}
588
589/// Database costs.
590#[derive(Clone, Debug, Default, PartialEq, Eq)]
591pub struct DbCosts {
592    /// Storage read cost.
593    pub read: CostOf<CallsAmount>,
594    /// Storage read per byte cost.
595    pub read_per_byte: CostOf<BytesAmount>,
596    /// Storage write cost.
597    pub write: CostOf<CallsAmount>,
598    /// Storage write per byte cost.
599    pub write_per_byte: CostOf<BytesAmount>,
600}
601
602/// Code instrumentation costs.
603#[derive(Clone, Debug, Default, PartialEq, Eq)]
604pub struct InstrumentationCosts {
605    /// Code instrumentation cost.
606    pub base: CostOf<CallsAmount>,
607    /// Code instrumentation per byte cost.
608    pub per_byte: CostOf<BytesAmount>,
609}
610
611/// Costs for message processing
612#[derive(Clone, Debug, Default, PartialEq, Eq)]
613pub struct ProcessCosts {
614    /// Execution externalities costs.
615    pub ext: ExtCosts,
616    /// Lazy pages costs.
617    pub lazy_pages: LazyPagesCosts,
618    /// Module instantiation costs.
619    pub instantiation: InstantiationCosts,
620    /// DB costs.
621    pub db: DbCosts,
622    /// Instrumentation costs.
623    pub instrumentation: InstrumentationCosts,
624    /// Load program allocations cost per interval.
625    pub load_allocations_per_interval: CostOf<u32>,
626}