1use crate::config::{CongestionControlConfig, WitnessConfig};
2use crate::{ActionCosts, ExtCosts, Fee, ParameterCost};
3use near_account_id::AccountId;
4use near_primitives_core::types::Balance;
5use near_primitives_core::types::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 pub storage_amount_per_byte: Balance,
15 pub transaction_costs: RuntimeFeesConfigView,
18 pub wasm_config: VMConfigView,
20 pub account_creation_config: AccountCreationConfigView,
22 pub congestion_control_config: CongestionControlConfigView,
24 pub witness_config: WitnessConfigView,
26}
27
28#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
30#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
31pub struct RuntimeFeesConfigView {
32 pub action_receipt_creation_config: Fee,
38 pub data_receipt_creation_config: DataReceiptCreationConfigView,
40 pub action_creation_config: ActionCreationConfigView,
42 pub storage_usage_config: StorageUsageConfigView,
44
45 #[cfg_attr(feature = "schemars", schemars(with = "Rational32SchemarsProvider"))]
47 pub burnt_gas_reward: Rational32,
48
49 #[cfg_attr(feature = "schemars", schemars(with = "Rational32SchemarsProvider"))]
51 pub pessimistic_gas_price_inflation_ratio: Rational32,
52}
53
54#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
56#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
57pub struct AccountCreationConfigView {
58 pub min_allowed_top_level_account_length: u8,
60 pub registrar_account_id: AccountId,
63}
64
65#[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 pub linear_op_base_cost: u64,
225 pub linear_op_unit_cost: u64,
227
228 pub vm_kind: crate::vm::VMKind,
230 pub discard_custom_sections: bool,
232 pub saturating_float_to_int: bool,
234 pub global_contract_host_fns: bool,
236 pub reftypes_bulk_memory: bool,
238 pub deterministic_account_ids: bool,
240
241 pub storage_get_mode: crate::vm::StorageGetMode,
243 pub fix_contract_loading_cost: bool,
245 pub implicit_account_creation: bool,
247 pub eth_implicit_accounts: bool,
249
250 pub limit_config: crate::vm::LimitConfig,
255}
256
257impl From<crate::vm::Config> for VMConfigView {
258 fn from(config: crate::vm::Config) -> Self {
259 Self {
260 ext_costs: ExtCostsConfigView::from(config.ext_costs),
261 grow_mem_cost: config.grow_mem_cost,
262 regular_op_cost: config.regular_op_cost,
263 linear_op_base_cost: config.linear_op_base_cost,
264 linear_op_unit_cost: config.linear_op_unit_cost,
265 discard_custom_sections: config.discard_custom_sections,
266 limit_config: config.limit_config,
267 storage_get_mode: config.storage_get_mode,
268 fix_contract_loading_cost: config.fix_contract_loading_cost,
269 implicit_account_creation: config.implicit_account_creation,
270 vm_kind: config.vm_kind,
271 eth_implicit_accounts: config.eth_implicit_accounts,
272 saturating_float_to_int: config.saturating_float_to_int,
273 global_contract_host_fns: config.global_contract_host_fns,
274 reftypes_bulk_memory: config.reftypes_bulk_memory,
275 deterministic_account_ids: config.deterministic_account_ids,
276 }
277 }
278}
279
280impl From<VMConfigView> for crate::vm::Config {
281 fn from(view: VMConfigView) -> Self {
282 Self {
283 ext_costs: crate::ExtCostsConfig::from(view.ext_costs),
284 grow_mem_cost: view.grow_mem_cost,
285 regular_op_cost: view.regular_op_cost,
286 linear_op_base_cost: view.linear_op_base_cost,
287 linear_op_unit_cost: view.linear_op_unit_cost,
288 discard_custom_sections: view.discard_custom_sections,
289 limit_config: view.limit_config,
290 storage_get_mode: view.storage_get_mode,
291 fix_contract_loading_cost: view.fix_contract_loading_cost,
292 implicit_account_creation: view.implicit_account_creation,
293 vm_kind: view.vm_kind,
294 eth_implicit_accounts: view.eth_implicit_accounts,
295 saturating_float_to_int: view.saturating_float_to_int,
296 global_contract_host_fns: view.global_contract_host_fns,
297 reftypes_bulk_memory: view.reftypes_bulk_memory,
298 deterministic_account_ids: view.deterministic_account_ids,
299 }
300 }
301}
302
303#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
306#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
307pub struct ExtCostsConfigView {
308 pub base: Gas,
310
311 pub contract_loading_base: Gas,
313 pub contract_loading_bytes: Gas,
315
316 pub read_memory_base: Gas,
318 pub read_memory_byte: Gas,
320
321 pub write_memory_base: Gas,
323
324 pub write_memory_byte: Gas,
326
327 pub read_register_base: Gas,
329 pub read_register_byte: Gas,
331
332 pub write_register_base: Gas,
334 pub write_register_byte: Gas,
336
337 pub utf8_decoding_base: Gas,
339 pub utf8_decoding_byte: Gas,
341
342 pub utf16_decoding_base: Gas,
344 pub utf16_decoding_byte: Gas,
346
347 pub sha256_base: Gas,
349 pub sha256_byte: Gas,
351
352 pub keccak256_base: Gas,
354 pub keccak256_byte: Gas,
356
357 pub keccak512_base: Gas,
359 pub keccak512_byte: Gas,
361
362 pub ripemd160_base: Gas,
364 pub ripemd160_block: Gas,
366
367 pub ed25519_verify_base: Gas,
369 pub ed25519_verify_byte: Gas,
371
372 pub ecrecover_base: Gas,
374
375 pub log_base: Gas,
377 pub log_byte: Gas,
379
380 pub storage_write_base: Gas,
385 pub storage_write_key_byte: Gas,
387 pub storage_write_value_byte: Gas,
389 pub storage_write_evicted_byte: Gas,
391
392 pub storage_read_base: Gas,
394 pub storage_read_key_byte: Gas,
396 pub storage_read_value_byte: Gas,
398
399 pub storage_large_read_overhead_base: Gas,
401 pub storage_large_read_overhead_byte: Gas,
403
404 pub storage_remove_base: Gas,
406 pub storage_remove_key_byte: Gas,
408 pub storage_remove_ret_value_byte: Gas,
410
411 pub storage_has_key_base: Gas,
413 pub storage_has_key_byte: Gas,
415
416 pub storage_iter_create_prefix_base: Gas,
418 pub storage_iter_create_prefix_byte: Gas,
420
421 pub storage_iter_create_range_base: Gas,
423 pub storage_iter_create_from_byte: Gas,
425 pub storage_iter_create_to_byte: Gas,
427
428 pub storage_iter_next_base: Gas,
430 pub storage_iter_next_key_byte: Gas,
432 pub storage_iter_next_value_byte: Gas,
434
435 pub touching_trie_node: Gas,
437 pub read_cached_trie_node: Gas,
439
440 pub promise_and_base: Gas,
445 pub promise_and_per_promise: Gas,
447 pub promise_return: Gas,
449
450 pub validator_stake_base: Gas,
455 pub validator_total_stake_base: Gas,
457
458 pub contract_compile_base: Gas,
460 pub contract_compile_bytes: Gas,
461
462 pub alt_bn128_g1_multiexp_base: Gas,
467 pub alt_bn128_g1_multiexp_element: Gas,
469 pub alt_bn128_g1_sum_base: Gas,
471 pub alt_bn128_g1_sum_element: Gas,
473 pub alt_bn128_pairing_check_base: Gas,
475 pub alt_bn128_pairing_check_element: Gas,
477 pub yield_create_base: Gas,
479 pub yield_create_byte: Gas,
481 pub yield_resume_base: Gas,
483 pub yield_resume_byte: Gas,
485 pub bls12381_p1_sum_base: Gas,
486 pub bls12381_p1_sum_element: Gas,
487 pub bls12381_p2_sum_base: Gas,
488 pub bls12381_p2_sum_element: Gas,
489 pub bls12381_g1_multiexp_base: Gas,
490 pub bls12381_g1_multiexp_element: Gas,
491 pub bls12381_g2_multiexp_base: Gas,
492 pub bls12381_g2_multiexp_element: Gas,
493 pub bls12381_map_fp_to_g1_base: Gas,
494 pub bls12381_map_fp_to_g1_element: Gas,
495 pub bls12381_map_fp2_to_g2_base: Gas,
496 pub bls12381_map_fp2_to_g2_element: Gas,
497 pub bls12381_pairing_base: Gas,
498 pub bls12381_pairing_element: Gas,
499 pub bls12381_p1_decompress_base: Gas,
500 pub bls12381_p1_decompress_element: Gas,
501 pub bls12381_p2_decompress_base: Gas,
502 pub bls12381_p2_decompress_element: Gas,
503}
504
505impl From<crate::ExtCostsConfig> for ExtCostsConfigView {
506 fn from(config: crate::ExtCostsConfig) -> Self {
507 Self {
508 base: config.gas_cost(ExtCosts::base),
509 contract_loading_base: config.gas_cost(ExtCosts::contract_loading_base),
510 contract_loading_bytes: config.gas_cost(ExtCosts::contract_loading_bytes),
511 read_memory_base: config.gas_cost(ExtCosts::read_memory_base),
512 read_memory_byte: config.gas_cost(ExtCosts::read_memory_byte),
513 write_memory_base: config.gas_cost(ExtCosts::write_memory_base),
514 write_memory_byte: config.gas_cost(ExtCosts::write_memory_byte),
515 read_register_base: config.gas_cost(ExtCosts::read_register_base),
516 read_register_byte: config.gas_cost(ExtCosts::read_register_byte),
517 write_register_base: config.gas_cost(ExtCosts::write_register_base),
518 write_register_byte: config.gas_cost(ExtCosts::write_register_byte),
519 utf8_decoding_base: config.gas_cost(ExtCosts::utf8_decoding_base),
520 utf8_decoding_byte: config.gas_cost(ExtCosts::utf8_decoding_byte),
521 utf16_decoding_base: config.gas_cost(ExtCosts::utf16_decoding_base),
522 utf16_decoding_byte: config.gas_cost(ExtCosts::utf16_decoding_byte),
523 sha256_base: config.gas_cost(ExtCosts::sha256_base),
524 sha256_byte: config.gas_cost(ExtCosts::sha256_byte),
525 keccak256_base: config.gas_cost(ExtCosts::keccak256_base),
526 keccak256_byte: config.gas_cost(ExtCosts::keccak256_byte),
527 keccak512_base: config.gas_cost(ExtCosts::keccak512_base),
528 keccak512_byte: config.gas_cost(ExtCosts::keccak512_byte),
529 ripemd160_base: config.gas_cost(ExtCosts::ripemd160_base),
530 ripemd160_block: config.gas_cost(ExtCosts::ripemd160_block),
531 ed25519_verify_base: config.gas_cost(ExtCosts::ed25519_verify_base),
532 ed25519_verify_byte: config.gas_cost(ExtCosts::ed25519_verify_byte),
533 ecrecover_base: config.gas_cost(ExtCosts::ecrecover_base),
534 log_base: config.gas_cost(ExtCosts::log_base),
535 log_byte: config.gas_cost(ExtCosts::log_byte),
536 storage_write_base: config.gas_cost(ExtCosts::storage_write_base),
537 storage_write_key_byte: config.gas_cost(ExtCosts::storage_write_key_byte),
538 storage_write_value_byte: config.gas_cost(ExtCosts::storage_write_value_byte),
539 storage_write_evicted_byte: config.gas_cost(ExtCosts::storage_write_evicted_byte),
540 storage_read_base: config.gas_cost(ExtCosts::storage_read_base),
541 storage_read_key_byte: config.gas_cost(ExtCosts::storage_read_key_byte),
542 storage_read_value_byte: config.gas_cost(ExtCosts::storage_read_value_byte),
543 storage_large_read_overhead_base: config
544 .gas_cost(ExtCosts::storage_large_read_overhead_base),
545 storage_large_read_overhead_byte: config
546 .gas_cost(ExtCosts::storage_large_read_overhead_byte),
547 storage_remove_base: config.gas_cost(ExtCosts::storage_remove_base),
548 storage_remove_key_byte: config.gas_cost(ExtCosts::storage_remove_key_byte),
549 storage_remove_ret_value_byte: config.gas_cost(ExtCosts::storage_remove_ret_value_byte),
550 storage_has_key_base: config.gas_cost(ExtCosts::storage_has_key_base),
551 storage_has_key_byte: config.gas_cost(ExtCosts::storage_has_key_byte),
552 storage_iter_create_prefix_base: config
553 .gas_cost(ExtCosts::storage_iter_create_prefix_base),
554 storage_iter_create_prefix_byte: config
555 .gas_cost(ExtCosts::storage_iter_create_prefix_byte),
556 storage_iter_create_range_base: config
557 .gas_cost(ExtCosts::storage_iter_create_range_base),
558 storage_iter_create_from_byte: config.gas_cost(ExtCosts::storage_iter_create_from_byte),
559 storage_iter_create_to_byte: config.gas_cost(ExtCosts::storage_iter_create_to_byte),
560 storage_iter_next_base: config.gas_cost(ExtCosts::storage_iter_next_base),
561 storage_iter_next_key_byte: config.gas_cost(ExtCosts::storage_iter_next_key_byte),
562 storage_iter_next_value_byte: config.gas_cost(ExtCosts::storage_iter_next_value_byte),
563 touching_trie_node: config.gas_cost(ExtCosts::touching_trie_node),
564 read_cached_trie_node: config.gas_cost(ExtCosts::read_cached_trie_node),
565 promise_and_base: config.gas_cost(ExtCosts::promise_and_base),
566 promise_and_per_promise: config.gas_cost(ExtCosts::promise_and_per_promise),
567 promise_return: config.gas_cost(ExtCosts::promise_return),
568 validator_stake_base: config.gas_cost(ExtCosts::validator_stake_base),
569 validator_total_stake_base: config.gas_cost(ExtCosts::validator_total_stake_base),
570 alt_bn128_g1_multiexp_base: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_base),
571 alt_bn128_g1_multiexp_element: config.gas_cost(ExtCosts::alt_bn128_g1_multiexp_element),
572 alt_bn128_g1_sum_base: config.gas_cost(ExtCosts::alt_bn128_g1_sum_base),
573 alt_bn128_g1_sum_element: config.gas_cost(ExtCosts::alt_bn128_g1_sum_element),
574 alt_bn128_pairing_check_base: config.gas_cost(ExtCosts::alt_bn128_pairing_check_base),
575 alt_bn128_pairing_check_element: config
576 .gas_cost(ExtCosts::alt_bn128_pairing_check_element),
577 yield_create_base: config.gas_cost(ExtCosts::yield_create_base),
578 yield_create_byte: config.gas_cost(ExtCosts::yield_create_byte),
579 yield_resume_base: config.gas_cost(ExtCosts::yield_resume_base),
580 yield_resume_byte: config.gas_cost(ExtCosts::yield_resume_byte),
581 bls12381_p1_sum_base: config.gas_cost(ExtCosts::bls12381_p1_sum_base),
582 bls12381_p1_sum_element: config.gas_cost(ExtCosts::bls12381_p1_sum_element),
583 bls12381_p2_sum_base: config.gas_cost(ExtCosts::bls12381_p2_sum_base),
584 bls12381_p2_sum_element: config.gas_cost(ExtCosts::bls12381_p2_sum_element),
585 bls12381_g1_multiexp_base: config.gas_cost(ExtCosts::bls12381_g1_multiexp_base),
586 bls12381_g1_multiexp_element: config.gas_cost(ExtCosts::bls12381_g1_multiexp_element),
587 bls12381_g2_multiexp_base: config.gas_cost(ExtCosts::bls12381_g2_multiexp_base),
588 bls12381_g2_multiexp_element: config.gas_cost(ExtCosts::bls12381_g2_multiexp_element),
589 bls12381_map_fp_to_g1_base: config.gas_cost(ExtCosts::bls12381_map_fp_to_g1_base),
590 bls12381_map_fp_to_g1_element: config.gas_cost(ExtCosts::bls12381_map_fp_to_g1_element),
591 bls12381_map_fp2_to_g2_base: config.gas_cost(ExtCosts::bls12381_map_fp2_to_g2_base),
592 bls12381_map_fp2_to_g2_element: config
593 .gas_cost(ExtCosts::bls12381_map_fp2_to_g2_element),
594 bls12381_pairing_base: config.gas_cost(ExtCosts::bls12381_pairing_base),
595 bls12381_pairing_element: config.gas_cost(ExtCosts::bls12381_pairing_element),
596 bls12381_p1_decompress_base: config.gas_cost(ExtCosts::bls12381_p1_decompress_base),
597 bls12381_p1_decompress_element: config
598 .gas_cost(ExtCosts::bls12381_p1_decompress_element),
599 bls12381_p2_decompress_base: config.gas_cost(ExtCosts::bls12381_p2_decompress_base),
600 bls12381_p2_decompress_element: config
601 .gas_cost(ExtCosts::bls12381_p2_decompress_element),
602 contract_compile_base: Gas::ZERO,
604 contract_compile_bytes: Gas::ZERO,
605 }
606 }
607}
608
609impl From<ExtCostsConfigView> for crate::ExtCostsConfig {
610 fn from(view: ExtCostsConfigView) -> Self {
611 let costs = enum_map::enum_map! {
612 ExtCosts::base => view.base,
613 ExtCosts::contract_loading_base => view.contract_loading_base,
614 ExtCosts::contract_loading_bytes => view.contract_loading_bytes,
615 ExtCosts::read_memory_base => view.read_memory_base,
616 ExtCosts::read_memory_byte => view.read_memory_byte,
617 ExtCosts::write_memory_base => view.write_memory_base,
618 ExtCosts::write_memory_byte => view.write_memory_byte,
619 ExtCosts::read_register_base => view.read_register_base,
620 ExtCosts::read_register_byte => view.read_register_byte,
621 ExtCosts::write_register_base => view.write_register_base,
622 ExtCosts::write_register_byte => view.write_register_byte,
623 ExtCosts::utf8_decoding_base => view.utf8_decoding_base,
624 ExtCosts::utf8_decoding_byte => view.utf8_decoding_byte,
625 ExtCosts::utf16_decoding_base => view.utf16_decoding_base,
626 ExtCosts::utf16_decoding_byte => view.utf16_decoding_byte,
627 ExtCosts::sha256_base => view.sha256_base,
628 ExtCosts::sha256_byte => view.sha256_byte,
629 ExtCosts::keccak256_base => view.keccak256_base,
630 ExtCosts::keccak256_byte => view.keccak256_byte,
631 ExtCosts::keccak512_base => view.keccak512_base,
632 ExtCosts::keccak512_byte => view.keccak512_byte,
633 ExtCosts::ripemd160_base => view.ripemd160_base,
634 ExtCosts::ripemd160_block => view.ripemd160_block,
635 ExtCosts::ed25519_verify_base => view.ed25519_verify_base,
636 ExtCosts::ed25519_verify_byte => view.ed25519_verify_byte,
637 ExtCosts::ecrecover_base => view.ecrecover_base,
638 ExtCosts::log_base => view.log_base,
639 ExtCosts::log_byte => view.log_byte,
640 ExtCosts::storage_write_base => view.storage_write_base,
641 ExtCosts::storage_write_key_byte => view.storage_write_key_byte,
642 ExtCosts::storage_write_value_byte => view.storage_write_value_byte,
643 ExtCosts::storage_write_evicted_byte => view.storage_write_evicted_byte,
644 ExtCosts::storage_read_base => view.storage_read_base,
645 ExtCosts::storage_read_key_byte => view.storage_read_key_byte,
646 ExtCosts::storage_read_value_byte => view.storage_read_value_byte,
647 ExtCosts::storage_large_read_overhead_base => view.storage_large_read_overhead_base,
648 ExtCosts::storage_large_read_overhead_byte => view.storage_large_read_overhead_byte,
649 ExtCosts::storage_remove_base => view.storage_remove_base,
650 ExtCosts::storage_remove_key_byte => view.storage_remove_key_byte,
651 ExtCosts::storage_remove_ret_value_byte => view.storage_remove_ret_value_byte,
652 ExtCosts::storage_has_key_base => view.storage_has_key_base,
653 ExtCosts::storage_has_key_byte => view.storage_has_key_byte,
654 ExtCosts::storage_iter_create_prefix_base => view.storage_iter_create_prefix_base,
655 ExtCosts::storage_iter_create_prefix_byte => view.storage_iter_create_prefix_byte,
656 ExtCosts::storage_iter_create_range_base => view.storage_iter_create_range_base,
657 ExtCosts::storage_iter_create_from_byte => view.storage_iter_create_from_byte,
658 ExtCosts::storage_iter_create_to_byte => view.storage_iter_create_to_byte,
659 ExtCosts::storage_iter_next_base => view.storage_iter_next_base,
660 ExtCosts::storage_iter_next_key_byte => view.storage_iter_next_key_byte,
661 ExtCosts::storage_iter_next_value_byte => view.storage_iter_next_value_byte,
662 ExtCosts::touching_trie_node => view.touching_trie_node,
663 ExtCosts::read_cached_trie_node => view.read_cached_trie_node,
664 ExtCosts::promise_and_base => view.promise_and_base,
665 ExtCosts::promise_and_per_promise => view.promise_and_per_promise,
666 ExtCosts::promise_return => view.promise_return,
667 ExtCosts::validator_stake_base => view.validator_stake_base,
668 ExtCosts::validator_total_stake_base => view.validator_total_stake_base,
669 ExtCosts::alt_bn128_g1_multiexp_base => view.alt_bn128_g1_multiexp_base,
670 ExtCosts::alt_bn128_g1_multiexp_element => view.alt_bn128_g1_multiexp_element,
671 ExtCosts::alt_bn128_g1_sum_base => view.alt_bn128_g1_sum_base,
672 ExtCosts::alt_bn128_g1_sum_element => view.alt_bn128_g1_sum_element,
673 ExtCosts::alt_bn128_pairing_check_base => view.alt_bn128_pairing_check_base,
674 ExtCosts::alt_bn128_pairing_check_element => view.alt_bn128_pairing_check_element,
675 ExtCosts::yield_create_base => view.yield_create_base,
676 ExtCosts::yield_create_byte => view.yield_create_byte,
677 ExtCosts::yield_resume_base => view.yield_resume_base,
678 ExtCosts::yield_resume_byte => view.yield_resume_byte,
679 ExtCosts::bls12381_p1_sum_base => view.bls12381_p1_sum_base,
680 ExtCosts::bls12381_p1_sum_element => view.bls12381_p1_sum_element,
681 ExtCosts::bls12381_p2_sum_base => view.bls12381_p2_sum_base,
682 ExtCosts::bls12381_p2_sum_element => view.bls12381_p2_sum_element,
683 ExtCosts::bls12381_g1_multiexp_base => view.bls12381_g1_multiexp_base,
684 ExtCosts::bls12381_g1_multiexp_element => view.bls12381_g1_multiexp_element,
685 ExtCosts::bls12381_g2_multiexp_base => view.bls12381_g2_multiexp_base,
686 ExtCosts::bls12381_g2_multiexp_element => view.bls12381_g2_multiexp_element,
687 ExtCosts::bls12381_map_fp_to_g1_base => view.bls12381_map_fp_to_g1_base,
688 ExtCosts::bls12381_map_fp_to_g1_element => view.bls12381_map_fp_to_g1_element,
689 ExtCosts::bls12381_map_fp2_to_g2_base => view.bls12381_map_fp2_to_g2_base,
690 ExtCosts::bls12381_map_fp2_to_g2_element => view.bls12381_map_fp2_to_g2_element,
691 ExtCosts::bls12381_pairing_base => view.bls12381_pairing_base,
692 ExtCosts::bls12381_pairing_element => view.bls12381_pairing_element,
693 ExtCosts::bls12381_p1_decompress_base => view.bls12381_p1_decompress_base,
694 ExtCosts::bls12381_p1_decompress_element => view.bls12381_p1_decompress_element,
695 ExtCosts::bls12381_p2_decompress_base => view.bls12381_p2_decompress_base,
696 ExtCosts::bls12381_p2_decompress_element => view.bls12381_p2_decompress_element,
697 }
698 .map(|_, value| ParameterCost { gas: value, compute: value.as_gas() });
699 Self { costs }
700 }
701}
702
703#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Hash, PartialEq, Eq)]
705#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
706pub struct WitnessConfigView {
707 pub main_storage_proof_size_soft_limit: u64,
710 pub combined_transactions_size_limit: usize,
715 pub new_transactions_validation_state_size_soft_limit: u64,
717}
718
719impl From<WitnessConfig> for WitnessConfigView {
720 fn from(config: WitnessConfig) -> Self {
721 Self {
722 main_storage_proof_size_soft_limit: config.main_storage_proof_size_soft_limit,
723 combined_transactions_size_limit: config.combined_transactions_size_limit,
724 new_transactions_validation_state_size_soft_limit: config
725 .new_transactions_validation_state_size_soft_limit,
726 }
727 }
728}
729
730#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
732#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
733pub struct CongestionControlConfigView {
734 pub max_congestion_incoming_gas: Gas,
738
739 pub max_congestion_outgoing_gas: Gas,
744
745 pub max_congestion_memory_consumption: u64,
750
751 pub max_congestion_missed_chunks: u64,
753
754 pub max_outgoing_gas: Gas,
759
760 pub min_outgoing_gas: Gas,
764
765 pub allowed_shard_outgoing_gas: Gas,
769
770 pub max_tx_gas: Gas,
775
776 pub min_tx_gas: Gas,
781
782 pub reject_tx_congestion_threshold: f64,
785
786 pub outgoing_receipts_usual_size_limit: u64,
790
791 pub outgoing_receipts_big_size_limit: u64,
795}
796
797impl From<CongestionControlConfig> for CongestionControlConfigView {
798 fn from(other: CongestionControlConfig) -> 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
816impl From<CongestionControlConfigView> for CongestionControlConfig {
817 fn from(other: CongestionControlConfigView) -> Self {
818 Self {
819 max_congestion_incoming_gas: other.max_congestion_incoming_gas,
820 max_congestion_outgoing_gas: other.max_congestion_outgoing_gas,
821 max_congestion_memory_consumption: other.max_congestion_memory_consumption,
822 max_congestion_missed_chunks: other.max_congestion_missed_chunks,
823 max_outgoing_gas: other.max_outgoing_gas,
824 min_outgoing_gas: other.min_outgoing_gas,
825 allowed_shard_outgoing_gas: other.allowed_shard_outgoing_gas,
826 max_tx_gas: other.max_tx_gas,
827 min_tx_gas: other.min_tx_gas,
828 reject_tx_congestion_threshold: other.reject_tx_congestion_threshold,
829 outgoing_receipts_usual_size_limit: other.outgoing_receipts_usual_size_limit,
830 outgoing_receipts_big_size_limit: other.outgoing_receipts_big_size_limit,
831 }
832 }
833}
834
835#[cfg(feature = "schemars")]
836pub type Rational32SchemarsProvider = [i32; 2];
837
838#[cfg(test)]
839#[cfg(not(feature = "nightly"))]
840mod tests {
841 #[test]
844 fn test_runtime_config_view() {
845 use crate::RuntimeConfig;
846 use crate::RuntimeConfigStore;
847 use crate::view::RuntimeConfigView;
848 use near_primitives_core::version::PROTOCOL_VERSION;
849
850 let config_store = RuntimeConfigStore::new(None);
851 let config = config_store.get_config(PROTOCOL_VERSION);
852 let view = RuntimeConfigView::from(RuntimeConfig::clone(config));
853 insta::assert_json_snapshot!(&view, { ".wasm_config.vm_kind" => "<REDACTED>"});
854 }
855}