unc_parameters/
view.rs

1use crate::{ActionCosts, ExtCosts, Fee, ParameterCost};
2use num_rational::Rational32;
3use unc_account_id::AccountId;
4use unc_primitives_core::serialize::dec_format;
5use unc_primitives_core::types::{Balance, Gas};
6
7/// View that preserves JSON format of the runtime config.
8#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
9pub struct RuntimeConfigView {
10    /// Amount of yN per byte required to have on the account.  See
11    /// <https://nomicon.io/Economics/Economic#state-pledge> for details.
12    #[serde(with = "dec_format")]
13    pub storage_amount_per_byte: Balance,
14    /// Costs of different actions that need to be performed when sending and
15    /// processing transaction and receipts.
16    pub transaction_costs: RuntimeFeesConfigView,
17    /// Config of wasm operations.
18    pub wasm_config: VMConfigView,
19    /// Config that defines rules for account creation.
20    pub account_creation_config: AccountCreationConfigView,
21}
22
23#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
24pub struct RuntimeFeesConfigView {
25    /// Describes the cost of creating an action receipt, `ActionReceipt`, excluding the actual cost
26    /// of actions.
27    /// - `send` cost is burned when a receipt is created using `promise_create` or
28    ///     `promise_batch_create`
29    /// - `exec` cost is burned when the receipt is being executed.
30    pub action_receipt_creation_config: Fee,
31    /// Describes the cost of creating a data receipt, `DataReceipt`.
32    pub data_receipt_creation_config: DataReceiptCreationConfigView,
33    /// Describes the cost of creating a certain action, `Action`. Includes all variants.
34    pub action_creation_config: ActionCreationConfigView,
35    /// Describes fees for storage.
36    pub storage_usage_config: StorageUsageConfigView,
37
38    /// Fraction of the burnt gas to reward to the contract account for execution.
39    pub burnt_gas_reward: Rational32,
40
41    /// Pessimistic gas price inflation ratio.
42    pub pessimistic_gas_price_inflation_ratio: Rational32,
43}
44
45/// The structure describes configuration for creation of new accounts.
46#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
47pub struct AccountCreationConfigView {
48    /// The minimum length of the top-level account ID that is allowed to be created by any account.
49    pub min_allowed_top_level_account_length: u8,
50    /// The account ID of the account registrar. This account ID allowed to create top-level
51    /// accounts of any valid length.
52    pub registrar_account_id: AccountId,
53}
54
55#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
56pub struct DataReceiptCreationConfigView {
57    /// Base cost of creating a data receipt.
58    /// Both `send` and `exec` costs are burned when a new receipt has input dependencies. The gas
59    /// is charged for each input dependency. The dependencies are specified when a receipt is
60    /// created using `promise_then` and `promise_batch_then`.
61    /// NOTE: Any receipt with output dependencies will produce data receipts. Even if it fails.
62    /// Even if the last action is not a function call (in case of success it will return empty
63    /// value).
64    pub base_cost: Fee,
65    /// Additional cost per byte sent.
66    /// Both `send` and `exec` costs are burned when a function call finishes execution and returns
67    /// `N` bytes of data to every output dependency. For each output dependency the cost is
68    /// `(send(sir) + exec()) * N`.
69    pub cost_per_byte: Fee,
70}
71
72/// Describes the cost of creating a specific action, `Action`. Includes all variants.
73#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
74pub struct ActionCreationConfigView {
75    /// Base cost of creating an account.
76    pub create_account_cost: Fee,
77
78    /// Base cost of deploying a contract.
79    pub deploy_contract_cost: Fee,
80    /// Cost per byte of deploying a contract.
81    pub deploy_contract_cost_per_byte: Fee,
82
83    /// Base cost of calling a function.
84    pub function_call_cost: Fee,
85    /// Cost per byte of method name and arguments of calling a function.
86    pub function_call_cost_per_byte: Fee,
87
88    /// Base cost of making a transfer.
89    pub transfer_cost: Fee,
90
91    /// Base cost of staking.
92    pub pledge_cost: Fee,
93
94    /// Base cost of adding a key.
95    pub add_key_cost: AccessKeyCreationConfigView,
96
97    /// Base cost of deleting a key.
98    pub delete_key_cost: Fee,
99
100    /// Base cost of deleting an account.
101    pub delete_account_cost: Fee,
102
103    /// Base cost for processing a delegate action.
104    ///
105    /// This is on top of the costs for the actions inside the delegate action.
106    pub delegate_cost: Fee,
107}
108
109/// Describes the cost of creating an access key.
110#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
111pub struct AccessKeyCreationConfigView {
112    /// Base cost of creating a full access access-key.
113    pub full_access_cost: Fee,
114    /// Base cost of creating an access-key restricted to specific functions.
115    pub function_call_cost: Fee,
116    /// Cost per byte of method_names of creating a restricted access-key.
117    pub function_call_cost_per_byte: Fee,
118}
119
120/// Describes cost of storage per block
121#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
122pub struct StorageUsageConfigView {
123    /// Number of bytes for an account record, including rounding up for account id.
124    pub num_bytes_account: u64,
125    /// Additional number of bytes for a k/v record
126    pub num_extra_bytes_record: u64,
127}
128
129impl From<crate::RuntimeConfig> for RuntimeConfigView {
130    fn from(config: crate::RuntimeConfig) -> Self {
131        Self {
132            storage_amount_per_byte: config.storage_amount_per_byte(),
133            transaction_costs: RuntimeFeesConfigView {
134                action_receipt_creation_config: config
135                    .fees
136                    .fee(ActionCosts::new_action_receipt)
137                    .clone(),
138                data_receipt_creation_config: DataReceiptCreationConfigView {
139                    base_cost: config.fees.fee(ActionCosts::new_data_receipt_base).clone(),
140                    cost_per_byte: config.fees.fee(ActionCosts::new_data_receipt_byte).clone(),
141                },
142                action_creation_config: ActionCreationConfigView {
143                    create_account_cost: config.fees.fee(ActionCosts::create_account).clone(),
144                    deploy_contract_cost: config
145                        .fees
146                        .fee(ActionCosts::deploy_contract_base)
147                        .clone(),
148                    deploy_contract_cost_per_byte: config
149                        .fees
150                        .fee(ActionCosts::deploy_contract_byte)
151                        .clone(),
152                    function_call_cost: config.fees.fee(ActionCosts::function_call_base).clone(),
153                    function_call_cost_per_byte: config
154                        .fees
155                        .fee(ActionCosts::function_call_byte)
156                        .clone(),
157                    transfer_cost: config.fees.fee(ActionCosts::transfer).clone(),
158                    pledge_cost: config.fees.fee(ActionCosts::pledge).clone(),
159                    add_key_cost: AccessKeyCreationConfigView {
160                        full_access_cost: config.fees.fee(ActionCosts::add_full_access_key).clone(),
161                        function_call_cost: config
162                            .fees
163                            .fee(ActionCosts::add_function_call_key_base)
164                            .clone(),
165                        function_call_cost_per_byte: config
166                            .fees
167                            .fee(ActionCosts::add_function_call_key_byte)
168                            .clone(),
169                    },
170                    delete_key_cost: config.fees.fee(ActionCosts::delete_key).clone(),
171                    delete_account_cost: config.fees.fee(ActionCosts::delete_account).clone(),
172                    delegate_cost: config.fees.fee(ActionCosts::delegate).clone(),
173                },
174                storage_usage_config: StorageUsageConfigView {
175                    num_bytes_account: config.fees.storage_usage_config.num_bytes_account,
176                    num_extra_bytes_record: config.fees.storage_usage_config.num_extra_bytes_record,
177                },
178                burnt_gas_reward: config.fees.burnt_gas_reward,
179                pessimistic_gas_price_inflation_ratio: config
180                    .fees
181                    .pessimistic_gas_price_inflation_ratio,
182            },
183            wasm_config: VMConfigView::from(config.wasm_config),
184            account_creation_config: AccountCreationConfigView {
185                min_allowed_top_level_account_length: config
186                    .account_creation_config
187                    .min_allowed_top_level_account_length,
188                registrar_account_id: config.account_creation_config.registrar_account_id,
189            },
190        }
191    }
192}
193
194#[derive(Clone, Debug, Hash, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
195pub struct VMConfigView {
196    /// Costs for runtime externals
197    pub ext_costs: ExtCostsConfigView,
198
199    /// Gas cost of a growing memory by single page.
200    pub grow_mem_cost: u32,
201    /// Gas cost of a regular operation.
202    pub regular_op_cost: u32,
203
204    /// See [`VMConfig::vm_kind`].
205    pub vm_kind: crate::vm::VMKind,
206    /// See [`VMConfig::disable_9393_fix`].
207    pub disable_9393_fix: bool,
208    /// See [`VMConfig::flat_storage_reads`].
209    pub storage_get_mode: crate::vm::StorageGetMode,
210    /// See [`VMConfig::fix_contract_loading_cost`].
211    pub fix_contract_loading_cost: bool,
212    /// See [`VMConfig::implicit_account_creation`].
213    pub implicit_account_creation: bool,
214    /// See [`VMConfig::math_extension`].
215    pub math_extension: bool,
216    /// See [`VMConfig::ed25519_verify`].
217    pub ed25519_verify: bool,
218    /// See [`VMConfig::alt_bn128`].
219    pub alt_bn128: bool,
220    /// See [`VMConfig::function_call_weight`].
221    pub function_call_weight: bool,
222    /// See [`VMConfig::eth_accounts`].
223    pub eth_accounts: bool,
224
225    /// Describes limits for VM and Runtime.
226    ///
227    /// TODO: Consider changing this to `VMLimitConfigView` to avoid dependency
228    /// on runtime.
229    pub limit_config: crate::vm::LimitConfig,
230}
231
232impl From<crate::vm::Config> for VMConfigView {
233    fn from(config: crate::vm::Config) -> Self {
234        Self {
235            ext_costs: ExtCostsConfigView::from(config.ext_costs),
236            grow_mem_cost: config.grow_mem_cost,
237            regular_op_cost: config.regular_op_cost,
238            disable_9393_fix: config.disable_9393_fix,
239            limit_config: config.limit_config,
240            storage_get_mode: config.storage_get_mode,
241            fix_contract_loading_cost: config.fix_contract_loading_cost,
242            implicit_account_creation: config.implicit_account_creation,
243            math_extension: config.math_extension,
244            ed25519_verify: config.ed25519_verify,
245            alt_bn128: config.alt_bn128,
246            function_call_weight: config.function_call_weight,
247            vm_kind: config.vm_kind,
248            eth_accounts: config.eth_accounts,
249        }
250    }
251}
252
253impl From<VMConfigView> for crate::vm::Config {
254    fn from(view: VMConfigView) -> Self {
255        Self {
256            ext_costs: crate::ExtCostsConfig::from(view.ext_costs),
257            grow_mem_cost: view.grow_mem_cost,
258            regular_op_cost: view.regular_op_cost,
259            disable_9393_fix: view.disable_9393_fix,
260            limit_config: view.limit_config,
261            storage_get_mode: view.storage_get_mode,
262            fix_contract_loading_cost: view.fix_contract_loading_cost,
263            implicit_account_creation: view.implicit_account_creation,
264            math_extension: view.math_extension,
265            ed25519_verify: view.ed25519_verify,
266            alt_bn128: view.alt_bn128,
267            function_call_weight: view.function_call_weight,
268            vm_kind: view.vm_kind,
269            eth_accounts: view.eth_accounts,
270        }
271    }
272}
273
274/// Typed view of ExtCostsConfig to preserve JSON output field names in protocol
275/// config RPC output.
276#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
277pub struct ExtCostsConfigView {
278    /// Base cost for calling a host function.
279    pub base: Gas,
280
281    /// Base cost of loading a pre-compiled contract
282    pub contract_loading_base: Gas,
283    /// Cost per byte of loading a pre-compiled contract
284    pub contract_loading_bytes: Gas,
285
286    /// Base cost for guest memory read
287    pub read_memory_base: Gas,
288    /// Cost for guest memory read
289    pub read_memory_byte: Gas,
290
291    /// Base cost for guest memory write
292    pub write_memory_base: Gas,
293    /// Cost for guest memory write per byte
294    pub write_memory_byte: Gas,
295
296    /// Base cost for reading from register
297    pub read_register_base: Gas,
298    /// Cost for reading byte from register
299    pub read_register_byte: Gas,
300
301    /// Base cost for writing into register
302    pub write_register_base: Gas,
303    /// Cost for writing byte into register
304    pub write_register_byte: Gas,
305
306    /// Base cost of decoding utf8. It's used for `log_utf8` and `panic_utf8`.
307    pub utf8_decoding_base: Gas,
308    /// Cost per byte of decoding utf8. It's used for `log_utf8` and `panic_utf8`.
309    pub utf8_decoding_byte: Gas,
310
311    /// Base cost of decoding utf16. It's used for `log_utf16`.
312    pub utf16_decoding_base: Gas,
313    /// Cost per byte of decoding utf16. It's used for `log_utf16`.
314    pub utf16_decoding_byte: Gas,
315
316    /// Cost of getting sha256 base
317    pub sha256_base: Gas,
318    /// Cost of getting sha256 per byte
319    pub sha256_byte: Gas,
320
321    /// Cost of getting sha256 base
322    pub keccak256_base: Gas,
323    /// Cost of getting sha256 per byte
324    pub keccak256_byte: Gas,
325
326    /// Cost of getting sha256 base
327    pub keccak512_base: Gas,
328    /// Cost of getting sha256 per byte
329    pub keccak512_byte: Gas,
330
331    /// Cost of getting ripemd160 base
332    pub ripemd160_base: Gas,
333    /// Cost of getting ripemd160 per message block
334    pub ripemd160_block: Gas,
335
336    /// Cost of getting ed25519 base
337    pub ed25519_verify_base: Gas,
338    /// Cost of getting ed25519 per byte
339    pub ed25519_verify_byte: Gas,
340
341    /// Cost of calling ecrecover
342    pub ecrecover_base: Gas,
343
344    /// Cost for calling logging.
345    pub log_base: Gas,
346    /// Cost for logging per byte
347    pub log_byte: Gas,
348
349    // ###############
350    // # Storage API #
351    // ###############
352    /// Storage trie write key base cost
353    pub storage_write_base: Gas,
354    /// Storage trie write key per byte cost
355    pub storage_write_key_byte: Gas,
356    /// Storage trie write value per byte cost
357    pub storage_write_value_byte: Gas,
358    /// Storage trie write cost per byte of evicted value.
359    pub storage_write_evicted_byte: Gas,
360
361    /// Storage trie read key base cost
362    pub storage_read_base: Gas,
363    /// Storage trie read key per byte cost
364    pub storage_read_key_byte: Gas,
365    /// Storage trie read value cost per byte cost
366    pub storage_read_value_byte: Gas,
367
368    /// Remove key from trie base cost
369    pub storage_remove_base: Gas,
370    /// Remove key from trie per byte cost
371    pub storage_remove_key_byte: Gas,
372    /// Remove key from trie ret value byte cost
373    pub storage_remove_ret_value_byte: Gas,
374
375    /// Storage trie check for key existence cost base
376    pub storage_has_key_base: Gas,
377    /// Storage trie check for key existence per key byte
378    pub storage_has_key_byte: Gas,
379
380    /// Create trie prefix iterator cost base
381    pub storage_iter_create_prefix_base: Gas,
382    /// Create trie prefix iterator cost per byte.
383    pub storage_iter_create_prefix_byte: Gas,
384
385    /// Create trie range iterator cost base
386    pub storage_iter_create_range_base: Gas,
387    /// Create trie range iterator cost per byte of from key.
388    pub storage_iter_create_from_byte: Gas,
389    /// Create trie range iterator cost per byte of to key.
390    pub storage_iter_create_to_byte: Gas,
391
392    /// Trie iterator per key base cost
393    pub storage_iter_next_base: Gas,
394    /// Trie iterator next key byte cost
395    pub storage_iter_next_key_byte: Gas,
396    /// Trie iterator next key byte cost
397    pub storage_iter_next_value_byte: Gas,
398
399    /// Cost per reading trie node from DB
400    pub touching_trie_node: Gas,
401    /// Cost for reading trie node from memory
402    pub read_cached_trie_node: Gas,
403
404    // ###############
405    // # Promise API #
406    // ###############
407    /// Cost for calling `promise_and`
408    pub promise_and_base: Gas,
409    /// Cost for calling `promise_and` for each promise
410    pub promise_and_per_promise: Gas,
411    /// Cost for calling `promise_return`
412    pub promise_return: Gas,
413
414    // ###############
415    // # Validator API #
416    // ###############
417    /// Cost of calling `validator_stake`.
418    pub validator_pledge_base: Gas,
419    pub validator_power_base: Gas,
420    /// Cost of calling `validator_total_stake`.
421    pub validator_total_pledge_base: Gas,
422    pub validator_total_power_base: Gas,
423
424    // Removed parameters, only here for keeping the output backward-compatible.
425    pub contract_compile_base: Gas,
426    pub contract_compile_bytes: Gas,
427
428    // #############
429    // # Alt BN128 #
430    // #############
431    /// Base cost for multiexp
432    pub alt_bn128_g1_multiexp_base: Gas,
433    /// Per element cost for multiexp
434    pub alt_bn128_g1_multiexp_element: Gas,
435    /// Base cost for sum
436    pub alt_bn128_g1_sum_base: Gas,
437    /// Per element cost for sum
438    pub alt_bn128_g1_sum_element: Gas,
439    /// Base cost for pairing check
440    pub alt_bn128_pairing_check_base: Gas,
441    /// Per element cost for pairing check
442    pub alt_bn128_pairing_check_element: Gas,
443}
444
445impl From<crate::ExtCostsConfig> for ExtCostsConfigView {
446    fn from(config: crate::ExtCostsConfig) -> Self {
447        Self {
448            base: config.gas_cost(ExtCosts::base),
449            contract_loading_base: config.gas_cost(ExtCosts::contract_loading_base),
450            contract_loading_bytes: config.gas_cost(ExtCosts::contract_loading_bytes),
451            read_memory_base: config.gas_cost(ExtCosts::read_memory_base),
452            read_memory_byte: config.gas_cost(ExtCosts::read_memory_byte),
453            write_memory_base: config.gas_cost(ExtCosts::write_memory_base),
454            write_memory_byte: config.gas_cost(ExtCosts::write_memory_byte),
455            read_register_base: config.gas_cost(ExtCosts::read_register_base),
456            read_register_byte: config.gas_cost(ExtCosts::read_register_byte),
457            write_register_base: config.gas_cost(ExtCosts::write_register_base),
458            write_register_byte: config.gas_cost(ExtCosts::write_register_byte),
459            utf8_decoding_base: config.gas_cost(ExtCosts::utf8_decoding_base),
460            utf8_decoding_byte: config.gas_cost(ExtCosts::utf8_decoding_byte),
461            utf16_decoding_base: config.gas_cost(ExtCosts::utf16_decoding_base),
462            utf16_decoding_byte: config.gas_cost(ExtCosts::utf16_decoding_byte),
463            sha256_base: config.gas_cost(ExtCosts::sha256_base),
464            sha256_byte: config.gas_cost(ExtCosts::sha256_byte),
465            keccak256_base: config.gas_cost(ExtCosts::keccak256_base),
466            keccak256_byte: config.gas_cost(ExtCosts::keccak256_byte),
467            keccak512_base: config.gas_cost(ExtCosts::keccak512_base),
468            keccak512_byte: config.gas_cost(ExtCosts::keccak512_byte),
469            ripemd160_base: config.gas_cost(ExtCosts::ripemd160_base),
470            ripemd160_block: config.gas_cost(ExtCosts::ripemd160_block),
471            ed25519_verify_base: config.gas_cost(ExtCosts::ed25519_verify_base),
472            ed25519_verify_byte: config.gas_cost(ExtCosts::ed25519_verify_byte),
473            ecrecover_base: config.gas_cost(ExtCosts::ecrecover_base),
474            log_base: config.gas_cost(ExtCosts::log_base),
475            log_byte: config.gas_cost(ExtCosts::log_byte),
476            storage_write_base: config.gas_cost(ExtCosts::storage_write_base),
477            storage_write_key_byte: config.gas_cost(ExtCosts::storage_write_key_byte),
478            storage_write_value_byte: config.gas_cost(ExtCosts::storage_write_value_byte),
479            storage_write_evicted_byte: config.gas_cost(ExtCosts::storage_write_evicted_byte),
480            storage_read_base: config.gas_cost(ExtCosts::storage_read_base),
481            storage_read_key_byte: config.gas_cost(ExtCosts::storage_read_key_byte),
482            storage_read_value_byte: config.gas_cost(ExtCosts::storage_read_value_byte),
483            storage_remove_base: config.gas_cost(ExtCosts::storage_remove_base),
484            storage_remove_key_byte: config.gas_cost(ExtCosts::storage_remove_key_byte),
485            storage_remove_ret_value_byte: config.gas_cost(ExtCosts::storage_remove_ret_value_byte),
486            storage_has_key_base: config.gas_cost(ExtCosts::storage_has_key_base),
487            storage_has_key_byte: config.gas_cost(ExtCosts::storage_has_key_byte),
488            storage_iter_create_prefix_base: config
489                .gas_cost(ExtCosts::storage_iter_create_prefix_base),
490            storage_iter_create_prefix_byte: config
491                .gas_cost(ExtCosts::storage_iter_create_prefix_byte),
492            storage_iter_create_range_base: config
493                .gas_cost(ExtCosts::storage_iter_create_range_base),
494            storage_iter_create_from_byte: config.gas_cost(ExtCosts::storage_iter_create_from_byte),
495            storage_iter_create_to_byte: config.gas_cost(ExtCosts::storage_iter_create_to_byte),
496            storage_iter_next_base: config.gas_cost(ExtCosts::storage_iter_next_base),
497            storage_iter_next_key_byte: config.gas_cost(ExtCosts::storage_iter_next_key_byte),
498            storage_iter_next_value_byte: config.gas_cost(ExtCosts::storage_iter_next_value_byte),
499            touching_trie_node: config.gas_cost(ExtCosts::touching_trie_node),
500            read_cached_trie_node: config.gas_cost(ExtCosts::read_cached_trie_node),
501            promise_and_base: config.gas_cost(ExtCosts::promise_and_base),
502            promise_and_per_promise: config.gas_cost(ExtCosts::promise_and_per_promise),
503            promise_return: config.gas_cost(ExtCosts::promise_return),
504            validator_pledge_base: config.gas_cost(ExtCosts::validator_pledge_base),
505            validator_total_pledge_base: config.gas_cost(ExtCosts::validator_total_pledge_base),
506            validator_power_base: config.gas_cost(ExtCosts::validator_power_base),
507            validator_total_power_base: config.gas_cost(ExtCosts::validator_total_power_base),
508            alt_bn128_g1_multiexp_base: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_base),
509            alt_bn128_g1_multiexp_element: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_element),
510            alt_bn128_g1_sum_base: config.gas_cost(ExtCosts::alt_bn128_g1_sum_base),
511            alt_bn128_g1_sum_element: config.gas_cost(ExtCosts::alt_bn128_g1_sum_element),
512            alt_bn128_pairing_check_base: config.gas_cost(ExtCosts::alt_bn128_pairing_check_base),
513            alt_bn128_pairing_check_element: config
514                .gas_cost(ExtCosts::alt_bn128_pairing_check_element),
515            // removed parameters
516            contract_compile_base: 0,
517            contract_compile_bytes: 0,
518        }
519    }
520}
521
522impl From<ExtCostsConfigView> for crate::ExtCostsConfig {
523    fn from(view: ExtCostsConfigView) -> Self {
524        let costs = enum_map::enum_map! {
525                ExtCosts::base => view.base,
526                ExtCosts::contract_loading_base => view.contract_loading_base,
527                ExtCosts::contract_loading_bytes => view.contract_loading_bytes,
528                ExtCosts::read_memory_base => view.read_memory_base,
529                ExtCosts::read_memory_byte => view.read_memory_byte,
530                ExtCosts::write_memory_base => view.write_memory_base,
531                ExtCosts::write_memory_byte => view.write_memory_byte,
532                ExtCosts::read_register_base => view.read_register_base,
533                ExtCosts::read_register_byte => view.read_register_byte,
534                ExtCosts::write_register_base => view.write_register_base,
535                ExtCosts::write_register_byte => view.write_register_byte,
536                ExtCosts::utf8_decoding_base => view.utf8_decoding_base,
537                ExtCosts::utf8_decoding_byte => view.utf8_decoding_byte,
538                ExtCosts::utf16_decoding_base => view.utf16_decoding_base,
539                ExtCosts::utf16_decoding_byte => view.utf16_decoding_byte,
540                ExtCosts::sha256_base => view.sha256_base,
541                ExtCosts::sha256_byte => view.sha256_byte,
542                ExtCosts::keccak256_base => view.keccak256_base,
543                ExtCosts::keccak256_byte => view.keccak256_byte,
544                ExtCosts::keccak512_base => view.keccak512_base,
545                ExtCosts::keccak512_byte => view.keccak512_byte,
546                ExtCosts::ripemd160_base => view.ripemd160_base,
547                ExtCosts::ripemd160_block => view.ripemd160_block,
548                ExtCosts::ed25519_verify_base => view.ed25519_verify_base,
549                ExtCosts::ed25519_verify_byte => view.ed25519_verify_byte,
550                ExtCosts::ecrecover_base => view.ecrecover_base,
551                ExtCosts::log_base => view.log_base,
552                ExtCosts::log_byte => view.log_byte,
553                ExtCosts::storage_write_base => view.storage_write_base,
554                ExtCosts::storage_write_key_byte => view.storage_write_key_byte,
555                ExtCosts::storage_write_value_byte => view.storage_write_value_byte,
556                ExtCosts::storage_write_evicted_byte => view.storage_write_evicted_byte,
557                ExtCosts::storage_read_base => view.storage_read_base,
558                ExtCosts::storage_read_key_byte => view.storage_read_key_byte,
559                ExtCosts::storage_read_value_byte => view.storage_read_value_byte,
560                ExtCosts::storage_remove_base => view.storage_remove_base,
561                ExtCosts::storage_remove_key_byte => view.storage_remove_key_byte,
562                ExtCosts::storage_remove_ret_value_byte => view.storage_remove_ret_value_byte,
563                ExtCosts::storage_has_key_base => view.storage_has_key_base,
564                ExtCosts::storage_has_key_byte => view.storage_has_key_byte,
565                ExtCosts::storage_iter_create_prefix_base => view.storage_iter_create_prefix_base,
566                ExtCosts::storage_iter_create_prefix_byte => view.storage_iter_create_prefix_byte,
567                ExtCosts::storage_iter_create_range_base => view.storage_iter_create_range_base,
568                ExtCosts::storage_iter_create_from_byte => view.storage_iter_create_from_byte,
569                ExtCosts::storage_iter_create_to_byte => view.storage_iter_create_to_byte,
570                ExtCosts::storage_iter_next_base => view.storage_iter_next_base,
571                ExtCosts::storage_iter_next_key_byte => view.storage_iter_next_key_byte,
572                ExtCosts::storage_iter_next_value_byte => view.storage_iter_next_value_byte,
573                ExtCosts::touching_trie_node => view.touching_trie_node,
574                ExtCosts::read_cached_trie_node => view.read_cached_trie_node,
575                ExtCosts::promise_and_base => view.promise_and_base,
576                ExtCosts::promise_and_per_promise => view.promise_and_per_promise,
577                ExtCosts::promise_return => view.promise_return,
578                ExtCosts::validator_pledge_base => view.validator_pledge_base,
579                ExtCosts::validator_total_pledge_base => view.validator_total_pledge_base,
580                ExtCosts::validator_power_base => view.validator_power_base,
581                ExtCosts::validator_total_power_base => view.validator_total_power_base,
582                ExtCosts::alt_bn128_g1_multiexp_base => view.alt_bn128_g1_multiexp_base,
583                ExtCosts::alt_bn128_g1_multiexp_element => view.alt_bn128_g1_multiexp_element,
584                ExtCosts::alt_bn128_g1_sum_base => view.alt_bn128_g1_sum_base,
585                ExtCosts::alt_bn128_g1_sum_element => view.alt_bn128_g1_sum_element,
586                ExtCosts::alt_bn128_pairing_check_base => view.alt_bn128_pairing_check_base,
587                ExtCosts::alt_bn128_pairing_check_element => view.alt_bn128_pairing_check_element,
588        }
589        .map(|_, value| ParameterCost { gas: value, compute: value });
590        Self { costs }
591    }
592}
593
594#[cfg(test)]
595mod tests {
596    /// The JSON representation used in RPC responses must not remove or rename
597    /// fields, only adding fields is allowed or we risk breaking clients.
598    #[test]
599    #[cfg_attr(feature = "nightly", ignore)]
600    fn test_runtime_config_view() {
601        use crate::view::RuntimeConfigView;
602        use crate::RuntimeConfig;
603        use crate::RuntimeConfigStore;
604        use unc_primitives_core::version::PROTOCOL_VERSION;
605
606        let config_store = RuntimeConfigStore::new(None);
607        let config = config_store.get_config(PROTOCOL_VERSION);
608        let view = RuntimeConfigView::from(RuntimeConfig::clone(config));
609        insta::assert_json_snapshot!(&view, { ".wasm_config.vm_kind" => "<REDACTED>"});
610    }
611}