1use crate::config::{CongestionControlConfig, WitnessConfig};
2use crate::{ActionCosts, ExtCosts, Fee, ParameterCost};
3use near_account_id::AccountId;
4use near_primitives_core::serialize::dec_format;
5use near_primitives_core::types::{Balance, Gas};
6use num_rational::Rational32;
7
8#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
10#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
11pub struct RuntimeConfigView {
12 #[serde(with = "dec_format")]
15 #[cfg_attr(feature = "schemars", schemars(with = "String"))]
16 pub storage_amount_per_byte: Balance,
17 pub transaction_costs: RuntimeFeesConfigView,
20 pub wasm_config: VMConfigView,
22 pub account_creation_config: AccountCreationConfigView,
24 pub congestion_control_config: CongestionControlConfigView,
26 pub witness_config: WitnessConfigView,
28}
29
30#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
31#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
32pub struct RuntimeFeesConfigView {
33 pub action_receipt_creation_config: Fee,
39 pub data_receipt_creation_config: DataReceiptCreationConfigView,
41 pub action_creation_config: ActionCreationConfigView,
43 pub storage_usage_config: StorageUsageConfigView,
45
46 #[cfg_attr(feature = "schemars", schemars(with = "Rational32SchemarsProvider"))]
48 pub burnt_gas_reward: Rational32,
49
50 #[cfg_attr(feature = "schemars", schemars(with = "Rational32SchemarsProvider"))]
52 pub pessimistic_gas_price_inflation_ratio: Rational32,
53}
54
55#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
57#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
58pub struct AccountCreationConfigView {
59 pub min_allowed_top_level_account_length: u8,
61 pub registrar_account_id: AccountId,
64}
65
66#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
67#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
68pub struct DataReceiptCreationConfigView {
69 pub base_cost: Fee,
77 pub cost_per_byte: Fee,
82}
83
84#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
86#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
87pub struct ActionCreationConfigView {
88 pub create_account_cost: Fee,
90
91 pub deploy_contract_cost: Fee,
93 pub deploy_contract_cost_per_byte: Fee,
95
96 pub function_call_cost: Fee,
98 pub function_call_cost_per_byte: Fee,
100
101 pub transfer_cost: Fee,
103
104 pub stake_cost: Fee,
106
107 pub add_key_cost: AccessKeyCreationConfigView,
109
110 pub delete_key_cost: Fee,
112
113 pub delete_account_cost: Fee,
115
116 pub delegate_cost: Fee,
120}
121
122#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
124#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
125pub struct AccessKeyCreationConfigView {
126 pub full_access_cost: Fee,
128 pub function_call_cost: Fee,
130 pub function_call_cost_per_byte: Fee,
132}
133
134#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
136#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
137pub struct StorageUsageConfigView {
138 pub num_bytes_account: u64,
140 pub num_extra_bytes_record: u64,
142}
143
144impl From<crate::RuntimeConfig> for RuntimeConfigView {
145 fn from(config: crate::RuntimeConfig) -> Self {
146 Self {
147 storage_amount_per_byte: config.storage_amount_per_byte(),
148 transaction_costs: RuntimeFeesConfigView {
149 action_receipt_creation_config: config
150 .fees
151 .fee(ActionCosts::new_action_receipt)
152 .clone(),
153 data_receipt_creation_config: DataReceiptCreationConfigView {
154 base_cost: config.fees.fee(ActionCosts::new_data_receipt_base).clone(),
155 cost_per_byte: config.fees.fee(ActionCosts::new_data_receipt_byte).clone(),
156 },
157 action_creation_config: ActionCreationConfigView {
158 create_account_cost: config.fees.fee(ActionCosts::create_account).clone(),
159 deploy_contract_cost: config
160 .fees
161 .fee(ActionCosts::deploy_contract_base)
162 .clone(),
163 deploy_contract_cost_per_byte: config
164 .fees
165 .fee(ActionCosts::deploy_contract_byte)
166 .clone(),
167 function_call_cost: config.fees.fee(ActionCosts::function_call_base).clone(),
168 function_call_cost_per_byte: config
169 .fees
170 .fee(ActionCosts::function_call_byte)
171 .clone(),
172 transfer_cost: config.fees.fee(ActionCosts::transfer).clone(),
173 stake_cost: config.fees.fee(ActionCosts::stake).clone(),
174 add_key_cost: AccessKeyCreationConfigView {
175 full_access_cost: config.fees.fee(ActionCosts::add_full_access_key).clone(),
176 function_call_cost: config
177 .fees
178 .fee(ActionCosts::add_function_call_key_base)
179 .clone(),
180 function_call_cost_per_byte: config
181 .fees
182 .fee(ActionCosts::add_function_call_key_byte)
183 .clone(),
184 },
185 delete_key_cost: config.fees.fee(ActionCosts::delete_key).clone(),
186 delete_account_cost: config.fees.fee(ActionCosts::delete_account).clone(),
187 delegate_cost: config.fees.fee(ActionCosts::delegate).clone(),
188 },
189 storage_usage_config: StorageUsageConfigView {
190 num_bytes_account: config.fees.storage_usage_config.num_bytes_account,
191 num_extra_bytes_record: config.fees.storage_usage_config.num_extra_bytes_record,
192 },
193 burnt_gas_reward: config.fees.burnt_gas_reward,
194 pessimistic_gas_price_inflation_ratio: config
195 .fees
196 .pessimistic_gas_price_inflation_ratio,
197 },
198 wasm_config: VMConfigView::from(crate::vm::Config::clone(&config.wasm_config)),
199 account_creation_config: AccountCreationConfigView {
200 min_allowed_top_level_account_length: config
201 .account_creation_config
202 .min_allowed_top_level_account_length,
203 registrar_account_id: config.account_creation_config.registrar_account_id,
204 },
205 congestion_control_config: CongestionControlConfigView::from(
206 config.congestion_control_config,
207 ),
208 witness_config: WitnessConfigView::from(config.witness_config),
209 }
210 }
211}
212
213#[derive(Clone, Debug, Hash, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
214#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
215pub struct VMConfigView {
216 pub ext_costs: ExtCostsConfigView,
218
219 pub grow_mem_cost: u32,
221 pub regular_op_cost: u32,
223
224 pub vm_kind: crate::vm::VMKind,
226 pub discard_custom_sections: bool,
228 pub saturating_float_to_int: bool,
230 pub global_contract_host_fns: bool,
232
233 pub storage_get_mode: crate::vm::StorageGetMode,
235 pub fix_contract_loading_cost: bool,
237 pub implicit_account_creation: bool,
239 pub eth_implicit_accounts: bool,
241
242 pub limit_config: crate::vm::LimitConfig,
247}
248
249impl From<crate::vm::Config> for VMConfigView {
250 fn from(config: crate::vm::Config) -> Self {
251 Self {
252 ext_costs: ExtCostsConfigView::from(config.ext_costs),
253 grow_mem_cost: config.grow_mem_cost,
254 regular_op_cost: config.regular_op_cost,
255 discard_custom_sections: config.discard_custom_sections,
256 limit_config: config.limit_config,
257 storage_get_mode: config.storage_get_mode,
258 fix_contract_loading_cost: config.fix_contract_loading_cost,
259 implicit_account_creation: config.implicit_account_creation,
260 vm_kind: config.vm_kind,
261 eth_implicit_accounts: config.eth_implicit_accounts,
262 saturating_float_to_int: config.saturating_float_to_int,
263 global_contract_host_fns: config.global_contract_host_fns,
264 }
265 }
266}
267
268impl From<VMConfigView> for crate::vm::Config {
269 fn from(view: VMConfigView) -> Self {
270 Self {
271 ext_costs: crate::ExtCostsConfig::from(view.ext_costs),
272 grow_mem_cost: view.grow_mem_cost,
273 regular_op_cost: view.regular_op_cost,
274 discard_custom_sections: view.discard_custom_sections,
275 limit_config: view.limit_config,
276 storage_get_mode: view.storage_get_mode,
277 fix_contract_loading_cost: view.fix_contract_loading_cost,
278 implicit_account_creation: view.implicit_account_creation,
279 vm_kind: view.vm_kind,
280 eth_implicit_accounts: view.eth_implicit_accounts,
281 saturating_float_to_int: view.saturating_float_to_int,
282 global_contract_host_fns: view.global_contract_host_fns,
283 }
284 }
285}
286
287#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
290#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
291pub struct ExtCostsConfigView {
292 pub base: Gas,
294
295 pub contract_loading_base: Gas,
297 pub contract_loading_bytes: Gas,
299
300 pub read_memory_base: Gas,
302 pub read_memory_byte: Gas,
304
305 pub write_memory_base: Gas,
307 pub write_memory_byte: Gas,
309
310 pub read_register_base: Gas,
312 pub read_register_byte: Gas,
314
315 pub write_register_base: Gas,
317 pub write_register_byte: Gas,
319
320 pub utf8_decoding_base: Gas,
322 pub utf8_decoding_byte: Gas,
324
325 pub utf16_decoding_base: Gas,
327 pub utf16_decoding_byte: Gas,
329
330 pub sha256_base: Gas,
332 pub sha256_byte: Gas,
334
335 pub keccak256_base: Gas,
337 pub keccak256_byte: Gas,
339
340 pub keccak512_base: Gas,
342 pub keccak512_byte: Gas,
344
345 pub ripemd160_base: Gas,
347 pub ripemd160_block: Gas,
349
350 pub ed25519_verify_base: Gas,
352 pub ed25519_verify_byte: Gas,
354
355 pub ecrecover_base: Gas,
357
358 pub log_base: Gas,
360 pub log_byte: Gas,
362
363 pub storage_write_base: Gas,
368 pub storage_write_key_byte: Gas,
370 pub storage_write_value_byte: Gas,
372 pub storage_write_evicted_byte: Gas,
374
375 pub storage_read_base: Gas,
377 pub storage_read_key_byte: Gas,
379 pub storage_read_value_byte: Gas,
381
382 pub storage_large_read_overhead_base: Gas,
384 pub storage_large_read_overhead_byte: Gas,
386
387 pub storage_remove_base: Gas,
389 pub storage_remove_key_byte: Gas,
391 pub storage_remove_ret_value_byte: Gas,
393
394 pub storage_has_key_base: Gas,
396 pub storage_has_key_byte: Gas,
398
399 pub storage_iter_create_prefix_base: Gas,
401 pub storage_iter_create_prefix_byte: Gas,
403
404 pub storage_iter_create_range_base: Gas,
406 pub storage_iter_create_from_byte: Gas,
408 pub storage_iter_create_to_byte: Gas,
410
411 pub storage_iter_next_base: Gas,
413 pub storage_iter_next_key_byte: Gas,
415 pub storage_iter_next_value_byte: Gas,
417
418 pub touching_trie_node: Gas,
420 pub read_cached_trie_node: Gas,
422
423 pub promise_and_base: Gas,
428 pub promise_and_per_promise: Gas,
430 pub promise_return: Gas,
432
433 pub validator_stake_base: Gas,
438 pub validator_total_stake_base: Gas,
440
441 pub contract_compile_base: Gas,
443 pub contract_compile_bytes: Gas,
444
445 pub alt_bn128_g1_multiexp_base: Gas,
450 pub alt_bn128_g1_multiexp_element: Gas,
452 pub alt_bn128_g1_sum_base: Gas,
454 pub alt_bn128_g1_sum_element: Gas,
456 pub alt_bn128_pairing_check_base: Gas,
458 pub alt_bn128_pairing_check_element: Gas,
460 pub yield_create_base: Gas,
462 pub yield_create_byte: Gas,
464 pub yield_resume_base: Gas,
466 pub yield_resume_byte: Gas,
468 pub bls12381_p1_sum_base: Gas,
469 pub bls12381_p1_sum_element: Gas,
470 pub bls12381_p2_sum_base: Gas,
471 pub bls12381_p2_sum_element: Gas,
472 pub bls12381_g1_multiexp_base: Gas,
473 pub bls12381_g1_multiexp_element: Gas,
474 pub bls12381_g2_multiexp_base: Gas,
475 pub bls12381_g2_multiexp_element: Gas,
476 pub bls12381_map_fp_to_g1_base: Gas,
477 pub bls12381_map_fp_to_g1_element: Gas,
478 pub bls12381_map_fp2_to_g2_base: Gas,
479 pub bls12381_map_fp2_to_g2_element: Gas,
480 pub bls12381_pairing_base: Gas,
481 pub bls12381_pairing_element: Gas,
482 pub bls12381_p1_decompress_base: Gas,
483 pub bls12381_p1_decompress_element: Gas,
484 pub bls12381_p2_decompress_base: Gas,
485 pub bls12381_p2_decompress_element: Gas,
486}
487
488impl From<crate::ExtCostsConfig> for ExtCostsConfigView {
489 fn from(config: crate::ExtCostsConfig) -> Self {
490 Self {
491 base: config.gas_cost(ExtCosts::base),
492 contract_loading_base: config.gas_cost(ExtCosts::contract_loading_base),
493 contract_loading_bytes: config.gas_cost(ExtCosts::contract_loading_bytes),
494 read_memory_base: config.gas_cost(ExtCosts::read_memory_base),
495 read_memory_byte: config.gas_cost(ExtCosts::read_memory_byte),
496 write_memory_base: config.gas_cost(ExtCosts::write_memory_base),
497 write_memory_byte: config.gas_cost(ExtCosts::write_memory_byte),
498 read_register_base: config.gas_cost(ExtCosts::read_register_base),
499 read_register_byte: config.gas_cost(ExtCosts::read_register_byte),
500 write_register_base: config.gas_cost(ExtCosts::write_register_base),
501 write_register_byte: config.gas_cost(ExtCosts::write_register_byte),
502 utf8_decoding_base: config.gas_cost(ExtCosts::utf8_decoding_base),
503 utf8_decoding_byte: config.gas_cost(ExtCosts::utf8_decoding_byte),
504 utf16_decoding_base: config.gas_cost(ExtCosts::utf16_decoding_base),
505 utf16_decoding_byte: config.gas_cost(ExtCosts::utf16_decoding_byte),
506 sha256_base: config.gas_cost(ExtCosts::sha256_base),
507 sha256_byte: config.gas_cost(ExtCosts::sha256_byte),
508 keccak256_base: config.gas_cost(ExtCosts::keccak256_base),
509 keccak256_byte: config.gas_cost(ExtCosts::keccak256_byte),
510 keccak512_base: config.gas_cost(ExtCosts::keccak512_base),
511 keccak512_byte: config.gas_cost(ExtCosts::keccak512_byte),
512 ripemd160_base: config.gas_cost(ExtCosts::ripemd160_base),
513 ripemd160_block: config.gas_cost(ExtCosts::ripemd160_block),
514 ed25519_verify_base: config.gas_cost(ExtCosts::ed25519_verify_base),
515 ed25519_verify_byte: config.gas_cost(ExtCosts::ed25519_verify_byte),
516 ecrecover_base: config.gas_cost(ExtCosts::ecrecover_base),
517 log_base: config.gas_cost(ExtCosts::log_base),
518 log_byte: config.gas_cost(ExtCosts::log_byte),
519 storage_write_base: config.gas_cost(ExtCosts::storage_write_base),
520 storage_write_key_byte: config.gas_cost(ExtCosts::storage_write_key_byte),
521 storage_write_value_byte: config.gas_cost(ExtCosts::storage_write_value_byte),
522 storage_write_evicted_byte: config.gas_cost(ExtCosts::storage_write_evicted_byte),
523 storage_read_base: config.gas_cost(ExtCosts::storage_read_base),
524 storage_read_key_byte: config.gas_cost(ExtCosts::storage_read_key_byte),
525 storage_read_value_byte: config.gas_cost(ExtCosts::storage_read_value_byte),
526 storage_large_read_overhead_base: config
527 .gas_cost(ExtCosts::storage_large_read_overhead_base),
528 storage_large_read_overhead_byte: config
529 .gas_cost(ExtCosts::storage_large_read_overhead_byte),
530 storage_remove_base: config.gas_cost(ExtCosts::storage_remove_base),
531 storage_remove_key_byte: config.gas_cost(ExtCosts::storage_remove_key_byte),
532 storage_remove_ret_value_byte: config.gas_cost(ExtCosts::storage_remove_ret_value_byte),
533 storage_has_key_base: config.gas_cost(ExtCosts::storage_has_key_base),
534 storage_has_key_byte: config.gas_cost(ExtCosts::storage_has_key_byte),
535 storage_iter_create_prefix_base: config
536 .gas_cost(ExtCosts::storage_iter_create_prefix_base),
537 storage_iter_create_prefix_byte: config
538 .gas_cost(ExtCosts::storage_iter_create_prefix_byte),
539 storage_iter_create_range_base: config
540 .gas_cost(ExtCosts::storage_iter_create_range_base),
541 storage_iter_create_from_byte: config.gas_cost(ExtCosts::storage_iter_create_from_byte),
542 storage_iter_create_to_byte: config.gas_cost(ExtCosts::storage_iter_create_to_byte),
543 storage_iter_next_base: config.gas_cost(ExtCosts::storage_iter_next_base),
544 storage_iter_next_key_byte: config.gas_cost(ExtCosts::storage_iter_next_key_byte),
545 storage_iter_next_value_byte: config.gas_cost(ExtCosts::storage_iter_next_value_byte),
546 touching_trie_node: config.gas_cost(ExtCosts::touching_trie_node),
547 read_cached_trie_node: config.gas_cost(ExtCosts::read_cached_trie_node),
548 promise_and_base: config.gas_cost(ExtCosts::promise_and_base),
549 promise_and_per_promise: config.gas_cost(ExtCosts::promise_and_per_promise),
550 promise_return: config.gas_cost(ExtCosts::promise_return),
551 validator_stake_base: config.gas_cost(ExtCosts::validator_stake_base),
552 validator_total_stake_base: config.gas_cost(ExtCosts::validator_total_stake_base),
553 alt_bn128_g1_multiexp_base: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_base),
554 alt_bn128_g1_multiexp_element: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_element),
555 alt_bn128_g1_sum_base: config.gas_cost(ExtCosts::alt_bn128_g1_sum_base),
556 alt_bn128_g1_sum_element: config.gas_cost(ExtCosts::alt_bn128_g1_sum_element),
557 alt_bn128_pairing_check_base: config.gas_cost(ExtCosts::alt_bn128_pairing_check_base),
558 alt_bn128_pairing_check_element: config
559 .gas_cost(ExtCosts::alt_bn128_pairing_check_element),
560 yield_create_base: config.gas_cost(ExtCosts::yield_create_base),
561 yield_create_byte: config.gas_cost(ExtCosts::yield_create_byte),
562 yield_resume_base: config.gas_cost(ExtCosts::yield_resume_base),
563 yield_resume_byte: config.gas_cost(ExtCosts::yield_resume_byte),
564 bls12381_p1_sum_base: config.gas_cost(ExtCosts::bls12381_p1_sum_base),
565 bls12381_p1_sum_element: config.gas_cost(ExtCosts::bls12381_p1_sum_element),
566 bls12381_p2_sum_base: config.gas_cost(ExtCosts::bls12381_p2_sum_base),
567 bls12381_p2_sum_element: config.gas_cost(ExtCosts::bls12381_p2_sum_element),
568 bls12381_g1_multiexp_base: config.gas_cost(ExtCosts::bls12381_g1_multiexp_base),
569 bls12381_g1_multiexp_element: config.gas_cost(ExtCosts::bls12381_g1_multiexp_element),
570 bls12381_g2_multiexp_base: config.gas_cost(ExtCosts::bls12381_g2_multiexp_base),
571 bls12381_g2_multiexp_element: config.gas_cost(ExtCosts::bls12381_g2_multiexp_element),
572 bls12381_map_fp_to_g1_base: config.gas_cost(ExtCosts::bls12381_map_fp_to_g1_base),
573 bls12381_map_fp_to_g1_element: config.gas_cost(ExtCosts::bls12381_map_fp_to_g1_element),
574 bls12381_map_fp2_to_g2_base: config.gas_cost(ExtCosts::bls12381_map_fp2_to_g2_base),
575 bls12381_map_fp2_to_g2_element: config
576 .gas_cost(ExtCosts::bls12381_map_fp2_to_g2_element),
577 bls12381_pairing_base: config.gas_cost(ExtCosts::bls12381_pairing_base),
578 bls12381_pairing_element: config.gas_cost(ExtCosts::bls12381_pairing_element),
579 bls12381_p1_decompress_base: config.gas_cost(ExtCosts::bls12381_p1_decompress_base),
580 bls12381_p1_decompress_element: config
581 .gas_cost(ExtCosts::bls12381_p1_decompress_element),
582 bls12381_p2_decompress_base: config.gas_cost(ExtCosts::bls12381_p2_decompress_base),
583 bls12381_p2_decompress_element: config
584 .gas_cost(ExtCosts::bls12381_p2_decompress_element),
585 contract_compile_base: 0,
587 contract_compile_bytes: 0,
588 }
589 }
590}
591
592impl From<ExtCostsConfigView> for crate::ExtCostsConfig {
593 fn from(view: ExtCostsConfigView) -> Self {
594 let costs = enum_map::enum_map! {
595 ExtCosts::base => view.base,
596 ExtCosts::contract_loading_base => view.contract_loading_base,
597 ExtCosts::contract_loading_bytes => view.contract_loading_bytes,
598 ExtCosts::read_memory_base => view.read_memory_base,
599 ExtCosts::read_memory_byte => view.read_memory_byte,
600 ExtCosts::write_memory_base => view.write_memory_base,
601 ExtCosts::write_memory_byte => view.write_memory_byte,
602 ExtCosts::read_register_base => view.read_register_base,
603 ExtCosts::read_register_byte => view.read_register_byte,
604 ExtCosts::write_register_base => view.write_register_base,
605 ExtCosts::write_register_byte => view.write_register_byte,
606 ExtCosts::utf8_decoding_base => view.utf8_decoding_base,
607 ExtCosts::utf8_decoding_byte => view.utf8_decoding_byte,
608 ExtCosts::utf16_decoding_base => view.utf16_decoding_base,
609 ExtCosts::utf16_decoding_byte => view.utf16_decoding_byte,
610 ExtCosts::sha256_base => view.sha256_base,
611 ExtCosts::sha256_byte => view.sha256_byte,
612 ExtCosts::keccak256_base => view.keccak256_base,
613 ExtCosts::keccak256_byte => view.keccak256_byte,
614 ExtCosts::keccak512_base => view.keccak512_base,
615 ExtCosts::keccak512_byte => view.keccak512_byte,
616 ExtCosts::ripemd160_base => view.ripemd160_base,
617 ExtCosts::ripemd160_block => view.ripemd160_block,
618 ExtCosts::ed25519_verify_base => view.ed25519_verify_base,
619 ExtCosts::ed25519_verify_byte => view.ed25519_verify_byte,
620 ExtCosts::ecrecover_base => view.ecrecover_base,
621 ExtCosts::log_base => view.log_base,
622 ExtCosts::log_byte => view.log_byte,
623 ExtCosts::storage_write_base => view.storage_write_base,
624 ExtCosts::storage_write_key_byte => view.storage_write_key_byte,
625 ExtCosts::storage_write_value_byte => view.storage_write_value_byte,
626 ExtCosts::storage_write_evicted_byte => view.storage_write_evicted_byte,
627 ExtCosts::storage_read_base => view.storage_read_base,
628 ExtCosts::storage_read_key_byte => view.storage_read_key_byte,
629 ExtCosts::storage_read_value_byte => view.storage_read_value_byte,
630 ExtCosts::storage_large_read_overhead_base => view.storage_large_read_overhead_base,
631 ExtCosts::storage_large_read_overhead_byte => view.storage_large_read_overhead_byte,
632 ExtCosts::storage_remove_base => view.storage_remove_base,
633 ExtCosts::storage_remove_key_byte => view.storage_remove_key_byte,
634 ExtCosts::storage_remove_ret_value_byte => view.storage_remove_ret_value_byte,
635 ExtCosts::storage_has_key_base => view.storage_has_key_base,
636 ExtCosts::storage_has_key_byte => view.storage_has_key_byte,
637 ExtCosts::storage_iter_create_prefix_base => view.storage_iter_create_prefix_base,
638 ExtCosts::storage_iter_create_prefix_byte => view.storage_iter_create_prefix_byte,
639 ExtCosts::storage_iter_create_range_base => view.storage_iter_create_range_base,
640 ExtCosts::storage_iter_create_from_byte => view.storage_iter_create_from_byte,
641 ExtCosts::storage_iter_create_to_byte => view.storage_iter_create_to_byte,
642 ExtCosts::storage_iter_next_base => view.storage_iter_next_base,
643 ExtCosts::storage_iter_next_key_byte => view.storage_iter_next_key_byte,
644 ExtCosts::storage_iter_next_value_byte => view.storage_iter_next_value_byte,
645 ExtCosts::touching_trie_node => view.touching_trie_node,
646 ExtCosts::read_cached_trie_node => view.read_cached_trie_node,
647 ExtCosts::promise_and_base => view.promise_and_base,
648 ExtCosts::promise_and_per_promise => view.promise_and_per_promise,
649 ExtCosts::promise_return => view.promise_return,
650 ExtCosts::validator_stake_base => view.validator_stake_base,
651 ExtCosts::validator_total_stake_base => view.validator_total_stake_base,
652 ExtCosts::alt_bn128_g1_multiexp_base => view.alt_bn128_g1_multiexp_base,
653 ExtCosts::alt_bn128_g1_multiexp_element => view.alt_bn128_g1_multiexp_element,
654 ExtCosts::alt_bn128_g1_sum_base => view.alt_bn128_g1_sum_base,
655 ExtCosts::alt_bn128_g1_sum_element => view.alt_bn128_g1_sum_element,
656 ExtCosts::alt_bn128_pairing_check_base => view.alt_bn128_pairing_check_base,
657 ExtCosts::alt_bn128_pairing_check_element => view.alt_bn128_pairing_check_element,
658 ExtCosts::yield_create_base => view.yield_create_base,
659 ExtCosts::yield_create_byte => view.yield_create_byte,
660 ExtCosts::yield_resume_base => view.yield_resume_base,
661 ExtCosts::yield_resume_byte => view.yield_resume_byte,
662 ExtCosts::bls12381_p1_sum_base => view.bls12381_p1_sum_base,
663 ExtCosts::bls12381_p1_sum_element => view.bls12381_p1_sum_element,
664 ExtCosts::bls12381_p2_sum_base => view.bls12381_p2_sum_base,
665 ExtCosts::bls12381_p2_sum_element => view.bls12381_p2_sum_element,
666 ExtCosts::bls12381_g1_multiexp_base => view.bls12381_g1_multiexp_base,
667 ExtCosts::bls12381_g1_multiexp_element => view.bls12381_g1_multiexp_element,
668 ExtCosts::bls12381_g2_multiexp_base => view.bls12381_g2_multiexp_base,
669 ExtCosts::bls12381_g2_multiexp_element => view.bls12381_g2_multiexp_element,
670 ExtCosts::bls12381_map_fp_to_g1_base => view.bls12381_map_fp_to_g1_base,
671 ExtCosts::bls12381_map_fp_to_g1_element => view.bls12381_map_fp_to_g1_element,
672 ExtCosts::bls12381_map_fp2_to_g2_base => view.bls12381_map_fp2_to_g2_base,
673 ExtCosts::bls12381_map_fp2_to_g2_element => view.bls12381_map_fp2_to_g2_element,
674 ExtCosts::bls12381_pairing_base => view.bls12381_pairing_base,
675 ExtCosts::bls12381_pairing_element => view.bls12381_pairing_element,
676 ExtCosts::bls12381_p1_decompress_base => view.bls12381_p1_decompress_base,
677 ExtCosts::bls12381_p1_decompress_element => view.bls12381_p1_decompress_element,
678 ExtCosts::bls12381_p2_decompress_base => view.bls12381_p2_decompress_base,
679 ExtCosts::bls12381_p2_decompress_element => view.bls12381_p2_decompress_element,
680 }
681 .map(|_, value| ParameterCost { gas: value, compute: value });
682 Self { costs }
683 }
684}
685
686#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
688#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
689pub struct WitnessConfigView {
690 pub main_storage_proof_size_soft_limit: usize,
693 pub combined_transactions_size_limit: usize,
697 pub new_transactions_validation_state_size_soft_limit: usize,
699}
700
701impl From<WitnessConfig> for WitnessConfigView {
702 fn from(config: WitnessConfig) -> Self {
703 Self {
704 main_storage_proof_size_soft_limit: config.main_storage_proof_size_soft_limit,
705 combined_transactions_size_limit: config.combined_transactions_size_limit,
706 new_transactions_validation_state_size_soft_limit: config
707 .new_transactions_validation_state_size_soft_limit,
708 }
709 }
710}
711
712#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
713#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
714pub struct CongestionControlConfigView {
715 pub max_congestion_incoming_gas: Gas,
719
720 pub max_congestion_outgoing_gas: Gas,
725
726 pub max_congestion_memory_consumption: u64,
731
732 pub max_congestion_missed_chunks: u64,
734
735 pub max_outgoing_gas: Gas,
740
741 pub min_outgoing_gas: Gas,
745
746 pub allowed_shard_outgoing_gas: Gas,
750
751 pub max_tx_gas: Gas,
756
757 pub min_tx_gas: Gas,
762
763 pub reject_tx_congestion_threshold: f64,
766
767 pub outgoing_receipts_usual_size_limit: u64,
771
772 pub outgoing_receipts_big_size_limit: u64,
776}
777
778impl From<CongestionControlConfig> for CongestionControlConfigView {
779 fn from(other: CongestionControlConfig) -> Self {
780 Self {
781 max_congestion_incoming_gas: other.max_congestion_incoming_gas,
782 max_congestion_outgoing_gas: other.max_congestion_outgoing_gas,
783 max_congestion_memory_consumption: other.max_congestion_memory_consumption,
784 max_congestion_missed_chunks: other.max_congestion_missed_chunks,
785 max_outgoing_gas: other.max_outgoing_gas,
786 min_outgoing_gas: other.min_outgoing_gas,
787 allowed_shard_outgoing_gas: other.allowed_shard_outgoing_gas,
788 max_tx_gas: other.max_tx_gas,
789 min_tx_gas: other.min_tx_gas,
790 reject_tx_congestion_threshold: other.reject_tx_congestion_threshold,
791 outgoing_receipts_usual_size_limit: other.outgoing_receipts_usual_size_limit,
792 outgoing_receipts_big_size_limit: other.outgoing_receipts_big_size_limit,
793 }
794 }
795}
796
797impl From<CongestionControlConfigView> for CongestionControlConfig {
798 fn from(other: CongestionControlConfigView) -> Self {
799 Self {
800 max_congestion_incoming_gas: other.max_congestion_incoming_gas,
801 max_congestion_outgoing_gas: other.max_congestion_outgoing_gas,
802 max_congestion_memory_consumption: other.max_congestion_memory_consumption,
803 max_congestion_missed_chunks: other.max_congestion_missed_chunks,
804 max_outgoing_gas: other.max_outgoing_gas,
805 min_outgoing_gas: other.min_outgoing_gas,
806 allowed_shard_outgoing_gas: other.allowed_shard_outgoing_gas,
807 max_tx_gas: other.max_tx_gas,
808 min_tx_gas: other.min_tx_gas,
809 reject_tx_congestion_threshold: other.reject_tx_congestion_threshold,
810 outgoing_receipts_usual_size_limit: other.outgoing_receipts_usual_size_limit,
811 outgoing_receipts_big_size_limit: other.outgoing_receipts_big_size_limit,
812 }
813 }
814}
815
816#[cfg(feature = "schemars")]
817pub type Rational32SchemarsProvider = [i32; 2];
818
819#[cfg(test)]
820#[cfg(not(feature = "nightly"))]
821mod tests {
822 #[test]
825 fn test_runtime_config_view() {
826 use crate::RuntimeConfig;
827 use crate::RuntimeConfigStore;
828 use crate::view::RuntimeConfigView;
829 use near_primitives_core::version::PROTOCOL_VERSION;
830
831 let config_store = RuntimeConfigStore::new(None);
832 let config = config_store.get_config(PROTOCOL_VERSION);
833 let view = RuntimeConfigView::from(RuntimeConfig::clone(config));
834 insta::assert_json_snapshot!(&view, { ".wasm_config.vm_kind" => "<REDACTED>"});
835 }
836}