From ebd9cf91ecd3de6e835f8731a9e4faa9ae19a34d Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Fri, 18 Aug 2023 19:40:46 +0300 Subject: [PATCH] Move flat-storage-reads/fix-contract-loading-cost/implicit-accounts features to runtime configuration (#9364) This PR is built on top of a previous PR (see the base branch). Here the noted protocol features have been replaced with runtime configuration via parameters instead. This would be one solution/option to getting rid of compile-time features in contract runtime which is interfering with limited replayability (compile-time feature control means that all of the crates still need to be built as a single compilation unit with consistent options.) cc @jakmeier cc #8197 --- chain/indexer/src/streamer/mod.rs | 7 +- chain/indexer/src/streamer/utils.rs | 3 - core/primitives-core/src/config.rs | 17 ++ core/primitives-core/src/parameter.rs | 4 + core/primitives-core/src/version.rs | 4 - core/primitives/res/runtime_configs/129.yaml | 1 + core/primitives/res/runtime_configs/35.yaml | 1 + core/primitives/res/runtime_configs/61.yaml | 1 + .../res/runtime_configs/parameters.snap | 3 + .../res/runtime_configs/parameters.yaml | 4 + .../runtime_configs/parameters_testnet.yaml | 3 + core/primitives/src/runtime/config_store.rs | 9 +- .../primitives/src/runtime/parameter_table.rs | 3 + ..._runtime__config_store__tests__0.json.snap | 3 + ...untime__config_store__tests__129.json.snap | 212 ++++++++++++++++++ ...runtime__config_store__tests__35.json.snap | 210 +++++++++++++++++ ...runtime__config_store__tests__42.json.snap | 3 + ...runtime__config_store__tests__48.json.snap | 3 + ...runtime__config_store__tests__49.json.snap | 3 + ...runtime__config_store__tests__50.json.snap | 3 + ...runtime__config_store__tests__52.json.snap | 3 + ...runtime__config_store__tests__53.json.snap | 3 + ...runtime__config_store__tests__57.json.snap | 3 + ...runtime__config_store__tests__59.json.snap | 3 + ...runtime__config_store__tests__61.json.snap | 3 + ...runtime__config_store__tests__62.json.snap | 3 + ...runtime__config_store__tests__63.json.snap | 3 + ...__config_store__tests__testnet_0.json.snap | 3 + ...config_store__tests__testnet_129.json.snap | 212 ++++++++++++++++++ ..._config_store__tests__testnet_35.json.snap | 210 +++++++++++++++++ ..._config_store__tests__testnet_42.json.snap | 3 + ..._config_store__tests__testnet_48.json.snap | 3 + ..._config_store__tests__testnet_49.json.snap | 3 + ..._config_store__tests__testnet_50.json.snap | 3 + ..._config_store__tests__testnet_52.json.snap | 3 + ..._config_store__tests__testnet_53.json.snap | 3 + ..._config_store__tests__testnet_57.json.snap | 3 + ..._config_store__tests__testnet_59.json.snap | 3 + ..._config_store__tests__testnet_61.json.snap | 3 + ..._config_store__tests__testnet_62.json.snap | 3 + ..._config_store__tests__testnet_63.json.snap | 3 + ...es__views__tests__runtime_config_view.snap | 3 + core/primitives/src/views.rs | 13 ++ .../features/fix_contract_loading_cost.rs | 3 +- .../src/tests/client/features/flat_storage.rs | 3 +- runtime/near-vm-runner/src/logic/logic.rs | 55 ++--- .../src/logic/tests/vm_logic_builder.rs | 9 +- runtime/near-vm-runner/src/near_vm_runner.rs | 25 +-- runtime/near-vm-runner/src/tests.rs | 14 -- .../src/tests/compile_errors.rs | 107 ++++----- .../src/tests/runtime_errors.rs | 135 +++++------ runtime/near-vm-runner/src/wasmer2_runner.rs | 25 +-- runtime/near-vm-runner/src/wasmer_runner.rs | 25 +-- runtime/near-vm-runner/src/wasmtime_runner.rs | 28 +-- .../src/costs_to_runtime_config.rs | 3 + runtime/runtime/src/actions.rs | 23 +- runtime/runtime/src/balance_checker.rs | 46 +--- runtime/runtime/src/config.rs | 40 +--- runtime/runtime/src/lib.rs | 43 +--- runtime/runtime/src/verifier.rs | 2 +- test-utils/testlib/src/fees_utils.rs | 10 +- 61 files changed, 1147 insertions(+), 441 deletions(-) create mode 100644 core/primitives/res/runtime_configs/129.yaml create mode 100644 core/primitives/res/runtime_configs/35.yaml create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__129.json.snap create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__35.json.snap create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_129.json.snap create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_35.json.snap diff --git a/chain/indexer/src/streamer/mod.rs b/chain/indexer/src/streamer/mod.rs index 4e624d578e1..a823d54669b 100644 --- a/chain/indexer/src/streamer/mod.rs +++ b/chain/indexer/src/streamer/mod.rs @@ -2,7 +2,6 @@ use std::time::Duration; use actix::Addr; use async_recursion::async_recursion; -use near_indexer_primitives::types::ProtocolVersion; use node_runtime::config::RuntimeConfig; use rocksdb::DB; use tokio::sync::mpsc; @@ -128,7 +127,6 @@ async fn build_streamer_message( let chunk_local_receipts = convert_transactions_sir_into_local_receipts( &client, &runtime_config, - protocol_config_view.protocol_version, indexer_transactions .iter() .filter(|tx| tx.transaction.signer_id == tx.transaction.receiver_id) @@ -175,7 +173,6 @@ async fn build_streamer_message( if let Some(receipt) = find_local_receipt_by_id_in_block( &client, &runtime_config, - protocol_config_view.protocol_version, prev_block, execution_outcome.id, ) @@ -188,7 +185,7 @@ async fn build_streamer_message( } }; receipt_execution_outcomes - .push(IndexerExecutionOutcomeWithReceipt { execution_outcome, receipt: receipt }); + .push(IndexerExecutionOutcomeWithReceipt { execution_outcome, receipt }); } // Blocks #47317863 and #47317864 @@ -246,7 +243,6 @@ async fn build_streamer_message( async fn find_local_receipt_by_id_in_block( client: &Addr, runtime_config: &RuntimeConfig, - protocol_version: ProtocolVersion, block: views::BlockView, receipt_id: near_primitives::hash::CryptoHash, ) -> Result, FailedToFetchData> { @@ -276,7 +272,6 @@ async fn find_local_receipt_by_id_in_block( let local_receipts = convert_transactions_sir_into_local_receipts( &client, &runtime_config, - protocol_version, vec![&indexer_transaction], &block, ) diff --git a/chain/indexer/src/streamer/utils.rs b/chain/indexer/src/streamer/utils.rs index 6def1506d29..6d3bbcd8d22 100644 --- a/chain/indexer/src/streamer/utils.rs +++ b/chain/indexer/src/streamer/utils.rs @@ -1,6 +1,5 @@ use actix::Addr; -use near_indexer_primitives::types::ProtocolVersion; use near_indexer_primitives::IndexerTransactionWithOutcome; use near_primitives::views; use node_runtime::config::{tx_cost, RuntimeConfig}; @@ -11,7 +10,6 @@ use super::fetchers::fetch_block; pub(crate) async fn convert_transactions_sir_into_local_receipts( client: &Addr, runtime_config: &RuntimeConfig, - protocol_version: ProtocolVersion, txs: Vec<&IndexerTransactionWithOutcome>, block: &views::BlockView, ) -> Result, FailedToFetchData> { @@ -44,7 +42,6 @@ pub(crate) async fn convert_transactions_sir_into_local_receipts( }, prev_block_gas_price, true, - protocol_version, ); views::ReceiptView { predecessor_id: tx.transaction.signer_id.clone(), diff --git a/core/primitives-core/src/config.rs b/core/primitives-core/src/config.rs index 376915326de..4ca1533ce5d 100644 --- a/core/primitives-core/src/config.rs +++ b/core/primitives-core/src/config.rs @@ -25,6 +25,17 @@ pub struct VMConfig { /// Disable the fix for the #9393 issue in near-vm-runner. pub disable_9393_fix: bool, + /// Enable the `FlatStorageReads` protocol feature. + /// + // TODO(nagisa): replace with StorageGetMode when VMConfig is moved to near-vm-runner. + pub flat_storage_reads: bool, + + /// Enable the `FixContractLoadingCost` protocol feature. + pub fix_contract_loading_cost: bool, + + /// Enable the `ImplicitAccountCreation` protocol feature. + pub implicit_account_creation: bool, + /// Describes limits for VM and Runtime. pub limit_config: VMLimitConfig, } @@ -184,6 +195,9 @@ impl VMConfig { regular_op_cost: (SAFETY_MULTIPLIER as u32) * 1285457, disable_9393_fix: false, limit_config: VMLimitConfig::test(), + fix_contract_loading_cost: cfg!(feature = "protocol_feature_fix_contract_loading_cost"), + flat_storage_reads: true, + implicit_account_creation: true, } } @@ -203,6 +217,9 @@ impl VMConfig { disable_9393_fix: false, // We shouldn't have any costs in the limit config. limit_config: VMLimitConfig { max_gas_burnt: u64::MAX, ..VMLimitConfig::test() }, + fix_contract_loading_cost: cfg!(feature = "protocol_feature_fix_contract_loading_cost"), + flat_storage_reads: true, + implicit_account_creation: true, } } } diff --git a/core/primitives-core/src/parameter.rs b/core/primitives-core/src/parameter.rs index e1824d26ee8..1b112f0fb11 100644 --- a/core/primitives-core/src/parameter.rs +++ b/core/primitives-core/src/parameter.rs @@ -146,8 +146,12 @@ pub enum Parameter { MaxLocalsPerContract, AccountIdValidityRulesVersion, + // Contract runtime features #[strum(serialize = "disable_9393_fix")] Disable9393Fix, + FlatStorageReads, + ImplicitAccountCreation, + FixContractLoadingCost, } #[derive( diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index 973366d49fd..4d03a93a336 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -101,17 +101,13 @@ pub enum ProtocolFeature { /// /// Flat Storage NEP-399: https://github.com/near/NEPs/blob/master/neps/nep-0399.md FlatStorageReads, - /// Enables preparation V2. Note that this setting is not supported in production settings /// without NearVmRuntime enabled alongside it, as the VM runner would be too slow. PreparationV2, - /// Enables Near-Vm. Note that this setting is not at all supported without PreparationV2, /// as it hardcodes preparation v2 code into the generated assembly. NearVmRuntime, - BlockHeaderV4, - /// In case not all validator seats are occupied our algorithm provide incorrect minimal seat /// price - it reports as alpha * sum_stake instead of alpha * sum_stake / (1 - alpha), where /// alpha is min stake ratio diff --git a/core/primitives/res/runtime_configs/129.yaml b/core/primitives/res/runtime_configs/129.yaml new file mode 100644 index 00000000000..c60af6224e9 --- /dev/null +++ b/core/primitives/res/runtime_configs/129.yaml @@ -0,0 +1 @@ +fix_contract_loading_cost: { old: false, new: true } diff --git a/core/primitives/res/runtime_configs/35.yaml b/core/primitives/res/runtime_configs/35.yaml new file mode 100644 index 00000000000..74b5b963cf5 --- /dev/null +++ b/core/primitives/res/runtime_configs/35.yaml @@ -0,0 +1 @@ +implicit_account_creation: { old: false, new: true } diff --git a/core/primitives/res/runtime_configs/61.yaml b/core/primitives/res/runtime_configs/61.yaml index 6f2943e1ea3..a7224cca644 100644 --- a/core/primitives/res/runtime_configs/61.yaml +++ b/core/primitives/res/runtime_configs/61.yaml @@ -5,3 +5,4 @@ wasm_storage_write_base: { old: 64_196_736_000, new: { gas: 64_196_736_000, c wasm_storage_remove_base: { old: 53_473_030_500, new: { gas: 53_473_030_500, compute: 200_000_000_000 } } wasm_storage_read_base: { old: 56_356_845_750, new: { gas: 56_356_845_750, compute: 200_000_000_000 } } wasm_storage_has_key_base: { old: 54_039_896_625, new: { gas: 54_039_896_625, compute: 200_000_000_000 } } +flat_storage_reads: { old: false, new: true } diff --git a/core/primitives/res/runtime_configs/parameters.snap b/core/primitives/res/runtime_configs/parameters.snap index 992e18c4ad7..665cc9452b7 100644 --- a/core/primitives/res/runtime_configs/parameters.snap +++ b/core/primitives/res/runtime_configs/parameters.snap @@ -164,4 +164,7 @@ wasmer2_stack_limit 204_800 max_locals_per_contract 1_000_000 account_id_validity_rules_version 1 disable_9393_fix false +flat_storage_reads true +implicit_account_creation true +fix_contract_loading_cost true diff --git a/core/primitives/res/runtime_configs/parameters.yaml b/core/primitives/res/runtime_configs/parameters.yaml index c2977b97a65..20a5e34f49d 100644 --- a/core/primitives/res/runtime_configs/parameters.yaml +++ b/core/primitives/res/runtime_configs/parameters.yaml @@ -197,4 +197,8 @@ max_promises_per_function_call_action: 1_024 max_number_input_data_dependencies: 128 account_id_validity_rules_version: 0 +# Contract runtime configuration disable_9393_fix: false +flat_storage_reads: false +implicit_account_creation: false +fix_contract_loading_cost: false diff --git a/core/primitives/res/runtime_configs/parameters_testnet.yaml b/core/primitives/res/runtime_configs/parameters_testnet.yaml index dbfde6c7195..f979bf13d57 100644 --- a/core/primitives/res/runtime_configs/parameters_testnet.yaml +++ b/core/primitives/res/runtime_configs/parameters_testnet.yaml @@ -194,3 +194,6 @@ max_promises_per_function_call_action: 1_024 max_number_input_data_dependencies: 128 disable_9393_fix: false +flat_storage_reads: false +implicit_account_creation: false +fix_contract_loading_cost: false diff --git a/core/primitives/src/runtime/config_store.rs b/core/primitives/src/runtime/config_store.rs index 79be3b0a738..6d623744bc3 100644 --- a/core/primitives/src/runtime/config_store.rs +++ b/core/primitives/src/runtime/config_store.rs @@ -18,6 +18,7 @@ static BASE_CONFIG: &str = include_config!("parameters.yaml"); /// Stores pairs of protocol versions for which runtime config was updated and /// the file containing the diffs in bytes. static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[ + (35, include_config!("35.yaml")), (42, include_config!("42.yaml")), (48, include_config!("48.yaml")), (49, include_config!("49.yaml")), @@ -33,6 +34,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[ (61, include_config!("61.yaml")), (62, include_config!("62.yaml")), (63, include_config!("63.yaml")), + (129, include_config!("129.yaml")), ]; /// Testnet parameters for versions <= 29, which (incorrectly) differed from mainnet parameters @@ -261,8 +263,8 @@ mod tests { ); let expected_config = { - let first_diff = CONFIG_DIFFS[0].1.parse().unwrap(); - base_params.apply_diff(first_diff).unwrap(); + base_params.apply_diff(CONFIG_DIFFS[0].1.parse().unwrap()).unwrap(); + base_params.apply_diff(CONFIG_DIFFS[1].1.parse().unwrap()).unwrap(); RuntimeConfig::new(&base_params).unwrap() }; assert_eq!(**config, expected_config); @@ -270,8 +272,7 @@ mod tests { let config = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version()); assert_eq!(config.fees.fee(ActionCosts::new_data_receipt_base).send_sir, 36_486_732_312); let expected_config = { - let second_diff = CONFIG_DIFFS[1].1.parse().unwrap(); - base_params.apply_diff(second_diff).unwrap(); + base_params.apply_diff(CONFIG_DIFFS[2].1.parse().unwrap()).unwrap(); RuntimeConfig::new(&base_params).unwrap() }; assert_eq!(config.as_ref(), &expected_config); diff --git a/core/primitives/src/runtime/parameter_table.rs b/core/primitives/src/runtime/parameter_table.rs index 44ebd909d79..ab508077375 100644 --- a/core/primitives/src/runtime/parameter_table.rs +++ b/core/primitives/src/runtime/parameter_table.rs @@ -291,6 +291,9 @@ impl TryFrom<&ParameterTable> for RuntimeConfig { disable_9393_fix: params.get(Parameter::Disable9393Fix)?, limit_config: serde_yaml::from_value(params.yaml_map(Parameter::vm_limits())) .map_err(InvalidConfigError::InvalidYaml)?, + fix_contract_loading_cost: params.get(Parameter::FixContractLoadingCost)?, + flat_storage_reads: params.get(Parameter::FlatStorageReads)?, + implicit_account_creation: params.get(Parameter::ImplicitAccountCreation)?, }, account_creation_config: AccountCreationConfig { min_allowed_top_level_account_length: params diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__0.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__0.json.snap index 8d3a9487167..8a93ca1a0c7 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__0.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__0.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 3856371, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": false, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__129.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__129.json.snap new file mode 100644 index 00000000000..a90398de500 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__129.json.snap @@ -0,0 +1,212 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "10000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 36486732312, + "send_not_sir": 36486732312, + "execution": 36486732312 + }, + "cost_per_byte": { + "send_sir": 17212011, + "send_not_sir": 17212011, + "execution": 17212011 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 3850000000000, + "send_not_sir": 3850000000000, + "execution": 3850000000000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 64572944 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 278821988457, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 822756, + "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": true, + "implicit_account_creation": true, + "limit_config": { + "max_gas_burnt": 300000000000000, + "max_stack_height": 262144, + "contract_prepare_version": 2, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 2048, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "max_functions_number_per_contract": 10000, + "wasmer2_stack_limit": 204800, + "max_locals_per_contract": 1000000, + "account_id_validity_rules_version": 1 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 32, + "registrar_account_id": "registrar" + } +} diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__35.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__35.json.snap new file mode 100644 index 00000000000..455fe6ba546 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__35.json.snap @@ -0,0 +1,210 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "100000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 4697339419375, + "send_not_sir": 4697339419375, + "execution": 4697339419375 + }, + "cost_per_byte": { + "send_sir": 59357464, + "send_not_sir": 59357464, + "execution": 59357464 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 99607375000, + "send_not_sir": 99607375000, + "execution": 99607375000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 6812999 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 3365369625000, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 3856371, + "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, + "limit_config": { + "max_gas_burnt": 200000000000000, + "max_stack_height": 16384, + "contract_prepare_version": 0, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 4194304, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "wasmer2_stack_limit": 102400, + "account_id_validity_rules_version": 0 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 32, + "registrar_account_id": "registrar" + } +} diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__42.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__42.json.snap index da92d2b6351..52f8f6ffa9d 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__42.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__42.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 3856371, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__48.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__48.json.snap index e9996d6cf48..c957aec2270 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__48.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__48.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 2207874, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__49.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__49.json.snap index 81a98cf3f6b..d1d0b6f9fa8 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__49.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__49.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__50.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__50.json.snap index fa98182d6f2..33c57d09cac 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__50.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__50.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__52.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__52.json.snap index 40a4e9072bf..fcf41019e9a 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__52.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__52.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__53.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__53.json.snap index 944ebbc71be..c6cb6e3854d 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__53.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__53.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__57.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__57.json.snap index df74cd295eb..0cd94553df9 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__57.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__57.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__59.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__59.json.snap index a806026f968..7c2c99b6d2e 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__59.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__59.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__61.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__61.json.snap index a806026f968..1e0511b72e5 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__61.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__61.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__62.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__62.json.snap index cf7a6a3cb42..209e73166d1 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__62.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__62.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": true, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 262144, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__63.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__63.json.snap index 94b3a526bb6..f4b3a898e20 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__63.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__63.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 262144, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_0.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_0.json.snap index 8d3a9487167..8a93ca1a0c7 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_0.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_0.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 3856371, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": false, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_129.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_129.json.snap new file mode 100644 index 00000000000..a90398de500 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_129.json.snap @@ -0,0 +1,212 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "10000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 36486732312, + "send_not_sir": 36486732312, + "execution": 36486732312 + }, + "cost_per_byte": { + "send_sir": 17212011, + "send_not_sir": 17212011, + "execution": 17212011 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 3850000000000, + "send_not_sir": 3850000000000, + "execution": 3850000000000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 64572944 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 278821988457, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 822756, + "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": true, + "implicit_account_creation": true, + "limit_config": { + "max_gas_burnt": 300000000000000, + "max_stack_height": 262144, + "contract_prepare_version": 2, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 2048, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "max_functions_number_per_contract": 10000, + "wasmer2_stack_limit": 204800, + "max_locals_per_contract": 1000000, + "account_id_validity_rules_version": 1 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 32, + "registrar_account_id": "registrar" + } +} diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_35.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_35.json.snap new file mode 100644 index 00000000000..455fe6ba546 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_35.json.snap @@ -0,0 +1,210 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "100000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 4697339419375, + "send_not_sir": 4697339419375, + "execution": 4697339419375 + }, + "cost_per_byte": { + "send_sir": 59357464, + "send_not_sir": 59357464, + "execution": 59357464 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 99607375000, + "send_not_sir": 99607375000, + "execution": 99607375000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 6812999 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 3365369625000, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 3856371, + "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, + "limit_config": { + "max_gas_burnt": 200000000000000, + "max_stack_height": 16384, + "contract_prepare_version": 0, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 4194304, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "wasmer2_stack_limit": 102400, + "account_id_validity_rules_version": 0 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 32, + "registrar_account_id": "registrar" + } +} diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_42.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_42.json.snap index da92d2b6351..52f8f6ffa9d 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_42.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_42.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 3856371, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_48.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_48.json.snap index e9996d6cf48..c957aec2270 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_48.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_48.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 2207874, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_49.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_49.json.snap index 81a98cf3f6b..d1d0b6f9fa8 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_49.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_49.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_50.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_50.json.snap index fa98182d6f2..33c57d09cac 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_50.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_50.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_52.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_52.json.snap index 40a4e9072bf..fcf41019e9a 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_52.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_52.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_53.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_53.json.snap index 944ebbc71be..c6cb6e3854d 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_53.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_53.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_57.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_57.json.snap index df74cd295eb..0cd94553df9 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_57.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_57.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_59.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_59.json.snap index a806026f968..7c2c99b6d2e 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_59.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_59.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": false, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_61.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_61.json.snap index a806026f968..1e0511b72e5 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_61.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_61.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 16384, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_62.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_62.json.snap index cf7a6a3cb42..209e73166d1 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_62.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_62.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": true, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 262144, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_63.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_63.json.snap index 94b3a526bb6..f4b3a898e20 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_63.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_63.json.snap @@ -173,6 +173,9 @@ expression: config_view "grow_mem_cost": 1, "regular_op_cost": 822756, "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 300000000000000, "max_stack_height": 262144, diff --git a/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap b/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap index aa4df5f7cdd..f84185e3fd7 100644 --- a/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap +++ b/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap @@ -173,6 +173,9 @@ expression: "&view" "grow_mem_cost": 1, "regular_op_cost": 3856371, "disable_9393_fix": false, + "flat_storage_reads": true, + "fix_contract_loading_cost": false, + "implicit_account_creation": true, "limit_config": { "max_gas_burnt": 200000000000000, "max_stack_height": 262144, diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index 558b8977588..df75ee09e88 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -2473,7 +2473,14 @@ pub struct VMConfigView { /// Gas cost of a regular operation. pub regular_op_cost: u32, + /// See [`VMConfig::disable_9393_fix`]. pub disable_9393_fix: bool, + /// See [`VMConfig::flat_storage_reads`]. + pub flat_storage_reads: bool, + /// See [`VMConfig::fix_contract_loading_cost`]. + pub fix_contract_loading_cost: bool, + /// See [`VMConfig::implicit_account_creation`]. + pub implicit_account_creation: bool, /// Describes limits for VM and Runtime. /// @@ -2490,6 +2497,9 @@ impl From for VMConfigView { regular_op_cost: config.regular_op_cost, disable_9393_fix: config.disable_9393_fix, limit_config: config.limit_config, + flat_storage_reads: config.flat_storage_reads, + fix_contract_loading_cost: config.fix_contract_loading_cost, + implicit_account_creation: config.implicit_account_creation, } } } @@ -2502,6 +2512,9 @@ impl From for VMConfig { regular_op_cost: view.regular_op_cost, disable_9393_fix: view.disable_9393_fix, limit_config: view.limit_config, + flat_storage_reads: view.flat_storage_reads, + fix_contract_loading_cost: view.fix_contract_loading_cost, + implicit_account_creation: view.implicit_account_creation, } } } diff --git a/integration-tests/src/tests/client/features/fix_contract_loading_cost.rs b/integration-tests/src/tests/client/features/fix_contract_loading_cost.rs index 8ced76eefc4..b1b77120fab 100644 --- a/integration-tests/src/tests/client/features/fix_contract_loading_cost.rs +++ b/integration-tests/src/tests/client/features/fix_contract_loading_cost.rs @@ -18,9 +18,10 @@ fn prepare_env_with_contract( let mut genesis = Genesis::test(vec![account.clone()], 1); genesis.config.epoch_length = epoch_length; genesis.config.protocol_version = protocol_version; + let runtime_config = near_primitives::runtime::config_store::RuntimeConfigStore::new(None); let mut env = TestEnv::builder(ChainGenesis::new(&genesis)) .real_epoch_managers(&genesis.config) - .nightshade_runtimes(&genesis) + .nightshade_runtimes_with_runtime_config_store(&genesis, vec![runtime_config]) .build(); deploy_test_contract(&mut env, account, &contract, epoch_length, 1); env diff --git a/integration-tests/src/tests/client/features/flat_storage.rs b/integration-tests/src/tests/client/features/flat_storage.rs index 8739218c393..8f11586afb9 100644 --- a/integration-tests/src/tests/client/features/flat_storage.rs +++ b/integration-tests/src/tests/client/features/flat_storage.rs @@ -29,9 +29,10 @@ fn test_flat_storage_upgrade() { genesis.config.epoch_length = epoch_length; genesis.config.protocol_version = old_protocol_version; let chain_genesis = ChainGenesis::new(&genesis); + let runtime_config = near_primitives::runtime::config_store::RuntimeConfigStore::new(None); let mut env = TestEnv::builder(chain_genesis) .real_epoch_managers(&genesis.config) - .nightshade_runtimes(&genesis) + .nightshade_runtimes_with_runtime_config_store(&genesis, vec![runtime_config]) .build(); // We assume that it is enough to process 4 blocks to get a single txn included and processed. diff --git a/runtime/near-vm-runner/src/logic/logic.rs b/runtime/near-vm-runner/src/logic/logic.rs index 7f4133de65d..6626974a989 100644 --- a/runtime/near-vm-runner/src/logic/logic.rs +++ b/runtime/near-vm-runner/src/logic/logic.rs @@ -7,7 +7,6 @@ use super::utils::split_method_names; use super::{HostError, VMLogicError}; use super::{StorageGetMode, ValuePtr}; use near_crypto::Secp256K1Signature; -use near_primitives_core::checked_feature; use near_primitives_core::config::ExtCosts::*; use near_primitives_core::config::ViewConfig; use near_primitives_core::config::{ActionCosts, ExtCosts, VMConfig}; @@ -15,7 +14,7 @@ use near_primitives_core::profile::ProfileDataV3; use near_primitives_core::runtime::fees::RuntimeFeesConfig; use near_primitives_core::runtime::fees::{transfer_exec_fee, transfer_send_fee}; use near_primitives_core::types::{ - AccountId, Balance, Compute, EpochHeight, Gas, GasWeight, ProtocolVersion, StorageUsage, + AccountId, Balance, Compute, EpochHeight, Gas, GasWeight, StorageUsage, }; use std::mem::size_of; @@ -65,9 +64,6 @@ pub struct VMLogic<'a> { /// Tracks the total log length. The sum of length of all logs. total_log_length: u64, - /// Current protocol version that is used for the function call. - current_protocol_version: ProtocolVersion, - /// Stores the amount of stack space remaining remaining_stack: u64, } @@ -128,14 +124,13 @@ impl PublicKeyBuffer { } impl<'a> VMLogic<'a> { - pub fn new_with_protocol_version( + pub fn new( ext: &'a mut dyn External, context: VMContext, config: &'a VMConfig, fees_config: &'a RuntimeFeesConfig, promise_results: &'a [PromiseResult], memory: &'a mut dyn MemoryLike, - current_protocol_version: ProtocolVersion, ) -> Self { // Overflow should be checked before calling VMLogic. let current_account_balance = context.account_balance + context.attached_deposit; @@ -169,7 +164,6 @@ impl<'a> VMLogic<'a> { registers: Default::default(), promises: vec![], total_log_length: 0, - current_protocol_version, remaining_stack: u64::from(config.limit_config.max_stack_height), } } @@ -1779,9 +1773,7 @@ impl<'a> VMLogic<'a> { let (receipt_idx, sir) = self.promise_idx_to_receipt_idx_with_sir(promise_idx)?; let receiver_id = self.ext.get_receipt_receiver(receipt_idx); let is_receiver_implicit = - checked_feature!("stable", ImplicitAccountCreation, self.current_protocol_version) - && receiver_id.is_implicit(); - + self.config.implicit_account_creation && receiver_id.is_implicit(); let send_fee = transfer_send_fee(self.fees_config, sir, is_receiver_implicit); let exec_fee = transfer_exec_fee(self.fees_config, is_receiver_implicit); let burn_gas = send_fee; @@ -2479,12 +2471,10 @@ impl<'a> VMLogic<'a> { } self.gas_counter.pay_per(storage_read_key_byte, key.len() as u64)?; let nodes_before = self.ext.get_trie_nodes_count(); - let read_mode = - if checked_feature!("stable", FlatStorageReads, self.current_protocol_version) { - StorageGetMode::FlatStorage - } else { - StorageGetMode::Trie - }; + let read_mode = match self.config.flat_storage_reads { + true => StorageGetMode::FlatStorage, + false => StorageGetMode::Trie, + }; let read = self.ext.storage_get(&key, read_mode); let nodes_delta = self .ext @@ -2628,12 +2618,10 @@ impl<'a> VMLogic<'a> { } self.gas_counter.pay_per(storage_has_key_byte, key.len() as u64)?; let nodes_before = self.ext.get_trie_nodes_count(); - let read_mode = - if checked_feature!("stable", FlatStorageReads, self.current_protocol_version) { - StorageGetMode::FlatStorage - } else { - StorageGetMode::Trie - }; + let read_mode = match self.config.flat_storage_reads { + true => StorageGetMode::FlatStorage, + false => StorageGetMode::Trie, + }; let res = self.ext.storage_has_key(&key, read_mode); let nodes_delta = self .ext @@ -2847,7 +2835,6 @@ impl<'a> VMLogic<'a> { pub fn before_loading_executable( &mut self, method_name: &str, - current_protocol_version: u32, wasm_code_bytes: usize, ) -> std::result::Result<(), super::errors::FunctionCallError> { if method_name.is_empty() { @@ -2856,11 +2843,7 @@ impl<'a> VMLogic<'a> { ); return Err(error); } - if checked_feature!( - "protocol_feature_fix_contract_loading_cost", - FixContractLoadingCost, - current_protocol_version - ) { + if self.config.fix_contract_loading_cost { if self.add_contract_loading_fee(wasm_code_bytes as u64).is_err() { let error = super::errors::FunctionCallError::HostError(super::HostError::GasExceeded); @@ -2873,14 +2856,9 @@ impl<'a> VMLogic<'a> { /// Legacy code to preserve old gas charging behaviour in old protocol versions. pub fn after_loading_executable( &mut self, - current_protocol_version: u32, wasm_code_bytes: usize, ) -> std::result::Result<(), super::errors::FunctionCallError> { - if !checked_feature!( - "protocol_feature_fix_contract_loading_cost", - FixContractLoadingCost, - current_protocol_version - ) { + if !self.config.fix_contract_loading_cost { if self.add_contract_loading_fee(wasm_code_bytes as u64).is_err() { return Err(super::errors::FunctionCallError::HostError( super::HostError::GasExceeded, @@ -2943,13 +2921,8 @@ impl VMOutcome { pub fn abort_but_nop_outcome_in_old_protocol( logic: VMLogic, error: FunctionCallError, - current_protocol_version: u32, ) -> VMOutcome { - if checked_feature!( - "protocol_feature_fix_contract_loading_cost", - FixContractLoadingCost, - current_protocol_version - ) { + if logic.config.fix_contract_loading_cost { Self::abort(logic, error) } else { Self::nop_outcome(error) diff --git a/runtime/near-vm-runner/src/logic/tests/vm_logic_builder.rs b/runtime/near-vm-runner/src/logic/tests/vm_logic_builder.rs index 0fe1965608c..562d9c3af57 100644 --- a/runtime/near-vm-runner/src/logic/tests/vm_logic_builder.rs +++ b/runtime/near-vm-runner/src/logic/tests/vm_logic_builder.rs @@ -3,9 +3,6 @@ use crate::logic::mocks::mock_memory::MockedMemory; use crate::logic::types::PromiseResult; use crate::logic::{MemSlice, VMConfig, VMContext, VMLogic}; use near_primitives_core::runtime::fees::RuntimeFeesConfig; -use near_primitives_core::types::ProtocolVersion; - -pub(super) const LATEST_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::MAX; pub(super) struct VMLogicBuilder { pub ext: MockedExternal, @@ -13,7 +10,6 @@ pub(super) struct VMLogicBuilder { pub fees_config: RuntimeFeesConfig, pub promise_results: Vec, pub memory: MockedMemory, - pub current_protocol_version: ProtocolVersion, pub context: VMContext, } @@ -25,7 +21,6 @@ impl Default for VMLogicBuilder { ext: MockedExternal::default(), memory: MockedMemory::default(), promise_results: vec![], - current_protocol_version: LATEST_PROTOCOL_VERSION, context: get_context(), } } @@ -41,14 +36,13 @@ impl VMLogicBuilder { pub fn build(&mut self) -> TestVMLogic<'_> { let context = self.context.clone(); - TestVMLogic::from(VMLogic::new_with_protocol_version( + TestVMLogic::from(VMLogic::new( &mut self.ext, context, &self.config, &self.fees_config, &self.promise_results, &mut self.memory, - self.current_protocol_version, )) } @@ -59,7 +53,6 @@ impl VMLogicBuilder { ext: MockedExternal::default(), memory: MockedMemory::default(), promise_results: vec![], - current_protocol_version: LATEST_PROTOCOL_VERSION, context: get_context(), } } diff --git a/runtime/near-vm-runner/src/near_vm_runner.rs b/runtime/near-vm-runner/src/near_vm_runner.rs index aa6d459f3d8..d9bb4e4d4a1 100644 --- a/runtime/near-vm-runner/src/near_vm_runner.rs +++ b/runtime/near-vm-runner/src/near_vm_runner.rs @@ -677,21 +677,10 @@ impl crate::runner::VM for NearVM { // FIXME: this mostly duplicates the `run_module` method. // Note that we don't clone the actual backing memory, just increase the RC. let vmmemory = memory.vm(); - let mut logic = VMLogic::new_with_protocol_version( - ext, - context, - &self.config, - fees_config, - promise_results, - &mut memory, - current_protocol_version, - ); + let mut logic = + VMLogic::new(ext, context, &self.config, fees_config, promise_results, &mut memory); - let result = logic.before_loading_executable( - method_name, - current_protocol_version, - code.code().len(), - ); + let result = logic.before_loading_executable(method_name, code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -704,7 +693,7 @@ impl crate::runner::VM for NearVM { } }; - let result = logic.after_loading_executable(current_protocol_version, code.code().len()); + let result = logic.after_loading_executable(code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -715,11 +704,7 @@ impl crate::runner::VM for NearVM { artifact.engine(), ); if let Err(e) = get_entrypoint_index(&*artifact, method_name) { - return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( - logic, - e, - current_protocol_version, - )); + return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e)); } match self.run_method(&artifact, import, method_name)? { Ok(()) => Ok(VMOutcome::ok(logic)), diff --git a/runtime/near-vm-runner/src/tests.rs b/runtime/near-vm-runner/src/tests.rs index 44fdad6b8fd..30db67134f8 100644 --- a/runtime/near-vm-runner/src/tests.rs +++ b/runtime/near-vm-runner/src/tests.rs @@ -57,17 +57,3 @@ fn create_context(input: Vec) -> VMContext { output_data_receivers: vec![], } } - -/// Small helper to compute expected loading gas cost charged before loading. -/// -/// Includes hard-coded value for runtime parameter values -/// `wasm_contract_loading_base` and `wasm_contract_loading_bytes` which would -/// have to be updated if they change in the future. -#[allow(unused)] -fn prepaid_loading_gas(bytes: usize) -> u64 { - if cfg!(feature = "protocol_feature_fix_contract_loading_cost") { - 35_445_963 + bytes as u64 * 21_6750 - } else { - 0 - } -} diff --git a/runtime/near-vm-runner/src/tests/compile_errors.rs b/runtime/near-vm-runner/src/tests/compile_errors.rs index 0c0d3ec18bd..d70fa030eb7 100644 --- a/runtime/near-vm-runner/src/tests/compile_errors.rs +++ b/runtime/near-vm-runner/src/tests/compile_errors.rs @@ -2,6 +2,8 @@ use super::test_builder::test_builder; use expect_test::expect; use near_primitives_core::version::ProtocolFeature; +const FIX_CONTRACT_LOADING_COST: u32 = 129; + #[test] fn test_initializer_wrong_signature_contract() { test_builder() @@ -13,16 +15,12 @@ fn test_initializer_wrong_signature_contract() { (func (export "main")) )"#, ) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48017463 used gas 48017463 Err: PrepareError: Error happened while deserializing the module. @@ -36,16 +34,14 @@ fn test_function_not_defined_contract() { test_builder() .wat(r#"(module (export "hello" (func 0)))"#) .method("hello") - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 39564213 used gas 39564213 Err: PrepareError: Error happened while deserializing the module. @@ -68,16 +64,14 @@ fn function_type_not_defined_contract(bad_type: u64) -> Vec { fn test_function_type_not_defined_contract_1() { test_builder() .wasm(&function_type_not_defined_contract(1)) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44982963 used gas 44982963 Err: PrepareError: Error happened while deserializing the module. @@ -90,16 +84,14 @@ fn test_function_type_not_defined_contract_1() { fn test_function_type_not_defined_contract_2() { test_builder() .wasm(&function_type_not_defined_contract(0)) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44982963 used gas 44982963 Err: PrepareError: Error happened while deserializing the module. @@ -111,16 +103,13 @@ fn test_function_type_not_defined_contract_2() { fn test_garbage_contract() { test_builder() .wasm(&[]) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 35445963 used gas 35445963 Err: PrepareError: Error happened while deserializing the module. @@ -133,16 +122,14 @@ fn test_evil_function_index() { test_builder() .wat(r#"(module (func (export "main") call 4294967295))"#) .method("abort_with_zero") - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44115963 used gas 44115963 Err: PrepareError: Error happened while deserializing the module. @@ -164,9 +151,8 @@ fn test_limit_contract_functions_number() { .protocol_features(&[ ProtocolFeature::LimitContractFunctionsNumber, ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13048032213 used gas 13048032213 @@ -177,7 +163,6 @@ fn test_limit_contract_functions_number() { expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13054614261 used gas 13054614261 "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13054614261 used gas 13054614261 "#]], @@ -193,9 +178,8 @@ fn test_limit_contract_functions_number() { .protocol_features(&[ ProtocolFeature::LimitContractFunctionsNumber, ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13049332713 used gas 13049332713 @@ -208,7 +192,6 @@ fn test_limit_contract_functions_number() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Too many functions in contract. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13049332713 used gas 13049332713 Err: PrepareError: Too many functions in contract. @@ -226,9 +209,10 @@ fn test_limit_contract_functions_number() { ) .protocol_features(&[ ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, ]) + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -238,7 +222,6 @@ fn test_limit_contract_functions_number() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Too many functions in contract. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 19554433713 used gas 19554433713 Err: PrepareError: Too many functions in contract. @@ -256,9 +239,9 @@ fn test_limit_contract_functions_number() { ) .protocol_features(&[ ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, + ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -268,7 +251,6 @@ fn test_limit_contract_functions_number() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Too many functions in contract. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 13051283463 used gas 13051283463 Err: PrepareError: Too many functions in contract. @@ -289,9 +271,11 @@ fn test_limit_locals() { ) .protocol_features(&[ ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, ]) + + .protocol_version( + FIX_CONTRACT_LOADING_COST + ) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -301,7 +285,6 @@ fn test_limit_locals() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened while deserializing the module. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 43682463 used gas 43682463 Err: PrepareError: Error happened while deserializing the module. @@ -345,9 +328,9 @@ fn test_limit_locals_global() { .protocol_features(&[ ProtocolFeature::LimitContractLocals, ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, + ]) + .protocol_version(FIX_CONTRACT_LOADING_COST,) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 195407463 used gas 195407463 @@ -360,7 +343,6 @@ fn test_limit_locals_global() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Too many locals declared in the contract. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 195407463 used gas 195407463 Err: PrepareError: Too many locals declared in the contract. @@ -447,24 +429,25 @@ fn test_sandbox_only_function() { #[test] fn extension_saturating_float_to_int() { - let tb = test_builder().wat( - r#" + test_builder() + .wat( + r#" (module (func $test_trunc (param $x f64) (result i32) (i32.trunc_sat_f64_s (local.get $x))) ) "#, - ); - - #[cfg(feature = "nightly")] - tb.expect(&expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48450963 used gas 48450963 - Err: PrepareError: Error happened while deserializing the module. - "#]]); - #[cfg(not(feature = "nightly"))] - tb.expect(&expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 - Err: PrepareError: Error happened while deserializing the module. - "#]]); + ) + .protocol_version(FIX_CONTRACT_LOADING_COST) + .expects(&[ + expect![[r#" + VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 + Err: PrepareError: Error happened while deserializing the module. + "#]], + expect![[r#" + VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48450963 used gas 48450963 + Err: PrepareError: Error happened while deserializing the module. + "#]], + ]); } #[test] diff --git a/runtime/near-vm-runner/src/tests/runtime_errors.rs b/runtime/near-vm-runner/src/tests/runtime_errors.rs index f68a644aac5..3e523ce209e 100644 --- a/runtime/near-vm-runner/src/tests/runtime_errors.rs +++ b/runtime/near-vm-runner/src/tests/runtime_errors.rs @@ -3,6 +3,8 @@ use expect_test::expect; use near_primitives_core::version::ProtocolFeature; use std::fmt::Write; +const FIX_CONTRACT_LOADING_COST: u32 = 129; + static INFINITE_INITIALIZER_CONTRACT: &str = r#" (module (func $start (loop (br 0))) @@ -26,15 +28,12 @@ fn test_infinite_initializer_export_not_found() { test_builder() .wat(INFINITE_INITIALIZER_CONTRACT) .method("no-such-method") - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]).expects(&[ + .protocol_version(FIX_CONTRACT_LOADING_COST) + .expects(&[ expect![[r#" VMOutcome: balance 0 storage_usage 0 return data None burnt gas 0 used gas 0 Err: MethodNotFound "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 49101213 used gas 49101213 Err: MethodNotFound @@ -70,16 +69,12 @@ fn test_imported_memory() { ]) // Wasmtime classifies this error as link error at the moment. .opaque_error() - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: ... "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44982963 used gas 44982963 Err: ... @@ -92,16 +87,12 @@ fn test_multiple_memories() { test_builder() .wat("(module (memory 1 2) (memory 3 4))") .opaque_error() - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: ... "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 39130713 used gas 39130713 Err: ... @@ -113,15 +104,12 @@ fn test_multiple_memories() { fn test_export_not_found() { test_builder().wat(SIMPLE_CONTRACT) .method("no-such-method") - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]).expects(&[ + .protocol_version(FIX_CONTRACT_LOADING_COST) + .expects(&[ expect![[r#" VMOutcome: balance 0 storage_usage 0 return data None burnt gas 0 used gas 0 Err: MethodNotFound "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 42815463 used gas 42815463 Err: MethodNotFound @@ -320,16 +308,12 @@ fn test_indirect_call_to_wrong_signature_contract() { fn test_wrong_signature_contract() { test_builder() .wat(r#"(module (func (export "main") (param i32)))"#) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 0 storage_usage 0 return data None burnt gas 0 used gas 0 Err: MethodInvalidSignature "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 43032213 used gas 43032213 Err: MethodInvalidSignature @@ -341,16 +325,12 @@ fn test_wrong_signature_contract() { fn test_export_wrong_type() { test_builder() .wat(r#"(module (global (export "main") i32 (i32.const 123)))"#) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 0 storage_usage 0 return data None burnt gas 0 used gas 0 Err: MethodNotFound "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 41298213 used gas 41298213 Err: MethodNotFound @@ -546,16 +526,12 @@ fn bad_import_func(env: &str) -> Vec { fn test_bad_import_1() { test_builder() .wasm(&bad_import_global("no-such-module")) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened during instantiation. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 50618463 used gas 50618463 Err: PrepareError: Error happened during instantiation. @@ -567,16 +543,12 @@ fn test_bad_import_1() { fn test_bad_import_2() { test_builder() .wasm(&bad_import_func("no-such-module")) - .protocol_features(&[ - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, - ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: PrepareError: Error happened during instantiation. "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 50184963 used gas 50184963 Err: PrepareError: Error happened during instantiation. @@ -591,9 +563,8 @@ fn test_bad_import_3() { .opaque_error() .protocol_features(&[ ProtocolFeature::PreparationV2, - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] - ProtocolFeature::FixContractLoadingCost, ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48234213 used gas 48234213 @@ -603,7 +574,6 @@ fn test_bad_import_3() { VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 Err: ... "#]], - #[cfg(feature = "protocol_feature_fix_contract_loading_cost")] expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48234213 used gas 48234213 Err: ... @@ -887,10 +857,10 @@ fn gas_overflow_indirect_call() { "#]]); } -#[cfg(feature = "protocol_feature_fix_contract_loading_cost")] mod fix_contract_loading_cost_protocol_upgrade { + use near_primitives_core::config::ExtCosts; + use super::*; - use crate::tests::prepaid_loading_gas; static ALMOST_TRIVIAL_CONTRACT: &str = r#" (module @@ -908,9 +878,9 @@ mod fix_contract_loading_cost_protocol_upgrade { test_builder() .wat(ALMOST_TRIVIAL_CONTRACT) .protocol_features(&[ - ProtocolFeature::PreparationV2, - ProtocolFeature::FixContractLoadingCost, + ProtocolFeature::PreparationV2 ]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 47406987 used gas 47406987 @@ -928,42 +898,43 @@ mod fix_contract_loading_cost_protocol_upgrade { // after. Both charge the same amount of gas. #[test] fn test_fn_loading_gas_protocol_upgrade_exceed_loading() { - let tb = test_builder().wat(ALMOST_TRIVIAL_CONTRACT); - let loading_cost = prepaid_loading_gas(tb.get_wasm().len()); - tb - .gas(loading_cost) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) - .expects(&[ - expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44115963 used gas 44115963 - Err: Exceeded the prepaid gas. - "#]], - expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44115963 used gas 44115963 - Err: Exceeded the prepaid gas. - "#]], - ]); + let expect = expect![[r#" + VMOutcome: balance 4 storage_usage 12 return data None burnt gas 44115963 used gas 44115963 + Err: Exceeded the prepaid gas. + "#]]; + let test_after = test_builder().wat(ALMOST_TRIVIAL_CONTRACT); + let cfg_costs = &test_after.configs().next().unwrap().wasm_config.ext_costs; + let loading_base = cfg_costs.gas_cost(ExtCosts::contract_loading_base); + let loading_byte = cfg_costs.gas_cost(ExtCosts::contract_loading_bytes); + let wasm_length = test_after.get_wasm().len(); + test_after.gas(loading_base + wasm_length as u64 * loading_byte).expect(&expect); + test_builder() + .wat(ALMOST_TRIVIAL_CONTRACT) + .only_protocol_versions(vec![FIX_CONTRACT_LOADING_COST - 1]) + .gas(loading_base + wasm_length as u64 * loading_byte) + .expect(&expect); } /// Executing with enough gas to finish loading but not to execute the full /// contract should have the same outcome before and after. #[test] fn test_fn_loading_gas_protocol_upgrade_exceed_executing() { - let tb = test_builder().wat(ALMOST_TRIVIAL_CONTRACT); - let loading_cost = prepaid_loading_gas(tb.get_wasm().len()); - tb - .gas(loading_cost + 884037) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) - .expects(&[ - expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 45000000 used gas 45000000 - Err: Exceeded the prepaid gas. - "#]], - expect![[r#" - VMOutcome: balance 4 storage_usage 12 return data None burnt gas 45000000 used gas 45000000 - Err: Exceeded the prepaid gas. - "#]], - ]); + let expect = expect![[r#" + VMOutcome: balance 4 storage_usage 12 return data None burnt gas 45000000 used gas 45000000 + Err: Exceeded the prepaid gas. + "#]]; + let test_after = test_builder().wat(ALMOST_TRIVIAL_CONTRACT); + let cfg_costs = &test_after.configs().next().unwrap().wasm_config.ext_costs; + let loading_base = cfg_costs.gas_cost(ExtCosts::contract_loading_base); + let loading_byte = cfg_costs.gas_cost(ExtCosts::contract_loading_bytes); + let wasm_length = test_after.get_wasm().len(); + let prepaid_gas = loading_base + wasm_length as u64 * loading_byte + 884037; + test_after.gas(prepaid_gas).expect(&expect); + test_builder() + .wat(ALMOST_TRIVIAL_CONTRACT) + .only_protocol_versions(vec![FIX_CONTRACT_LOADING_COST - 1]) + .gas(prepaid_gas) + .expect(&expect); } /// Failure during preparation must remain free of gas charges for old versions @@ -979,7 +950,7 @@ mod fix_contract_loading_cost_protocol_upgrade { test_builder() .wat(r#"(module (export "main" (func 0)))"#) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -993,7 +964,7 @@ mod fix_contract_loading_cost_protocol_upgrade { test_builder() .wasm(&bad_import_global("wtf")) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -1007,7 +978,7 @@ mod fix_contract_loading_cost_protocol_upgrade { test_builder() .wasm(&bad_import_func("wtf")) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -1026,7 +997,7 @@ mod fix_contract_loading_cost_protocol_upgrade { ..Default::default() } .make()) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 @@ -1046,7 +1017,7 @@ mod fix_contract_loading_cost_protocol_upgrade { ..Default::default() } .make()) - .protocol_features(&[ProtocolFeature::FixContractLoadingCost]) + .protocol_version(FIX_CONTRACT_LOADING_COST) .expects(&[ expect![[r#" VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0 diff --git a/runtime/near-vm-runner/src/wasmer2_runner.rs b/runtime/near-vm-runner/src/wasmer2_runner.rs index 1f8107dfa1b..c11dd8ee00e 100644 --- a/runtime/near-vm-runner/src/wasmer2_runner.rs +++ b/runtime/near-vm-runner/src/wasmer2_runner.rs @@ -580,21 +580,10 @@ impl crate::runner::VM for Wasmer2VM { // FIXME: this mostly duplicates the `run_module` method. // Note that we don't clone the actual backing memory, just increase the RC. let vmmemory = memory.vm(); - let mut logic = VMLogic::new_with_protocol_version( - ext, - context, - &self.config, - fees_config, - promise_results, - &mut memory, - current_protocol_version, - ); + let mut logic = + VMLogic::new(ext, context, &self.config, fees_config, promise_results, &mut memory); - let result = logic.before_loading_executable( - method_name, - current_protocol_version, - code.code().len(), - ); + let result = logic.before_loading_executable(method_name, code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -607,7 +596,7 @@ impl crate::runner::VM for Wasmer2VM { } }; - let result = logic.after_loading_executable(current_protocol_version, code.code().len()); + let result = logic.after_loading_executable(code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -618,11 +607,7 @@ impl crate::runner::VM for Wasmer2VM { artifact.engine(), ); if let Err(e) = get_entrypoint_index(&*artifact, method_name) { - return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( - logic, - e, - current_protocol_version, - )); + return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e)); } match self.run_method(&artifact, import, method_name)? { Ok(()) => Ok(VMOutcome::ok(logic)), diff --git a/runtime/near-vm-runner/src/wasmer_runner.rs b/runtime/near-vm-runner/src/wasmer_runner.rs index 2e241c80c5b..f5202a537b1 100644 --- a/runtime/near-vm-runner/src/wasmer_runner.rs +++ b/runtime/near-vm-runner/src/wasmer_runner.rs @@ -374,21 +374,10 @@ impl crate::runner::VM for Wasmer0VM { // Note that we don't clone the actual backing memory, just increase the RC. let memory_copy = memory.clone(); - let mut logic = VMLogic::new_with_protocol_version( - ext, - context, - &self.config, - fees_config, - promise_results, - &mut memory, - current_protocol_version, - ); + let mut logic = + VMLogic::new(ext, context, &self.config, fees_config, promise_results, &mut memory); - let result = logic.before_loading_executable( - method_name, - current_protocol_version, - code.code().len(), - ); + let result = logic.before_loading_executable(method_name, code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -409,7 +398,7 @@ impl crate::runner::VM for Wasmer0VM { } }; - let result = logic.after_loading_executable(current_protocol_version, code.code().len()); + let result = logic.after_loading_executable(code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -418,11 +407,7 @@ impl crate::runner::VM for Wasmer0VM { imports::wasmer::build(memory_copy, &mut logic, current_protocol_version); if let Err(e) = check_method(&module, method_name) { - return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( - logic, - e, - current_protocol_version, - )); + return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e)); } match run_method(&module, &import_object, method_name)? { diff --git a/runtime/near-vm-runner/src/wasmtime_runner.rs b/runtime/near-vm-runner/src/wasmtime_runner.rs index c5acdd51eb0..131b31980e3 100644 --- a/runtime/near-vm-runner/src/wasmtime_runner.rs +++ b/runtime/near-vm-runner/src/wasmtime_runner.rs @@ -175,21 +175,10 @@ impl crate::runner::VM for WasmtimeVM { ) .unwrap(); let memory_copy = memory.0; - let mut logic = VMLogic::new_with_protocol_version( - ext, - context, - &self.config, - fees_config, - promise_results, - &mut memory, - current_protocol_version, - ); + let mut logic = + VMLogic::new(ext, context, &self.config, fees_config, promise_results, &mut memory); - let result = logic.before_loading_executable( - method_name, - current_protocol_version, - code.code().len(), - ); + let result = logic.before_loading_executable(method_name, code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -205,7 +194,7 @@ impl crate::runner::VM for WasmtimeVM { }; let mut linker = Linker::new(&engine); - let result = logic.after_loading_executable(current_protocol_version, code.code().len()); + let result = logic.after_loading_executable(code.code().len()); if let Err(e) = result { return Ok(VMOutcome::abort(logic, e)); } @@ -227,18 +216,13 @@ impl crate::runner::VM for WasmtimeVM { let err = FunctionCallError::MethodResolveError( MethodResolveError::MethodInvalidSignature, ); - return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( - logic, - err, - current_protocol_version, - )); + return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, err)); } } _ => { return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( logic, FunctionCallError::MethodResolveError(MethodResolveError::MethodNotFound), - current_protocol_version, )); } }, @@ -246,7 +230,6 @@ impl crate::runner::VM for WasmtimeVM { return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( logic, FunctionCallError::MethodResolveError(MethodResolveError::MethodNotFound), - current_protocol_version, )); } } @@ -263,7 +246,6 @@ impl crate::runner::VM for WasmtimeVM { return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol( logic, FunctionCallError::MethodResolveError(MethodResolveError::MethodNotFound), - current_protocol_version, )); } }, diff --git a/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs b/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs index 330ca497c0d..3fe1aae2d1f 100644 --- a/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs +++ b/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs @@ -36,6 +36,9 @@ pub fn costs_to_runtime_config(cost_table: &CostTable) -> anyhow::Result Result, account_id: &AccountId, - current_protocol_version: ProtocolVersion, + config: &RuntimeConfig, is_the_only_action: bool, is_refund: bool, ) -> Result<(), ActionError> { @@ -896,9 +891,8 @@ pub(crate) fn check_account_existence( } .into()); } else { - if checked_feature!("stable", ImplicitAccountCreation, current_protocol_version) - && account_id.is_implicit() - { + // TODO: this should be `config.implicit_account_creation`. + if config.wasm_config.implicit_account_creation && account_id.is_implicit() { // If the account doesn't exist and it's 64-length hex account ID, then you // should only be able to create it using single transfer action. // Because you should not be able to add another access key to the account in @@ -917,11 +911,8 @@ pub(crate) fn check_account_existence( } Action::Transfer(_) => { if account.is_none() { - return if checked_feature!( - "stable", - ImplicitAccountCreation, - current_protocol_version - ) && is_the_only_action + return if config.wasm_config.implicit_account_creation + && is_the_only_action && account_id.is_implicit() && !is_refund { @@ -1374,7 +1365,7 @@ mod tests { &Action::Delegate(signed_delegate_action), &mut None, &sender_id, - 1, + &RuntimeConfig::test(), false, false ), diff --git a/runtime/runtime/src/balance_checker.rs b/runtime/runtime/src/balance_checker.rs index 8b963c56221..e600476cd95 100644 --- a/runtime/runtime/src/balance_checker.rs +++ b/runtime/runtime/src/balance_checker.rs @@ -13,7 +13,6 @@ use near_primitives::runtime::config::RuntimeConfig; use near_primitives::transaction::SignedTransaction; use near_primitives::trie_key::TrieKey; use near_primitives::types::{AccountId, Balance}; -use near_primitives::version::ProtocolVersion; use near_store::{get, get_account, get_postponed_receipt, TrieAccess, TrieUpdate}; use near_vm_runner::logic::ActionCosts; use std::collections::HashSet; @@ -38,7 +37,6 @@ fn get_delayed_receipts( /// Calculates and returns cost of a receipt. fn receipt_cost( config: &RuntimeConfig, - current_protocol_version: ProtocolVersion, receipt: &Receipt, ) -> Result { Ok(match &receipt.receipt { @@ -47,21 +45,12 @@ fn receipt_cost( if !AccountId::is_system(&receipt.predecessor_id) { let mut total_gas = safe_add_gas( config.fees.fee(ActionCosts::new_action_receipt).exec_fee(), - total_prepaid_exec_fees( - config, - &action_receipt.actions, - &receipt.receiver_id, - current_protocol_version, - )?, + total_prepaid_exec_fees(config, &action_receipt.actions, &receipt.receiver_id)?, )?; total_gas = safe_add_gas(total_gas, total_prepaid_gas(&action_receipt.actions)?)?; total_gas = safe_add_gas( total_gas, - total_prepaid_send_fees( - config, - &action_receipt.actions, - current_protocol_version, - )?, + total_prepaid_send_fees(config, &action_receipt.actions)?, )?; let total_gas_cost = safe_gas_to_balance(action_receipt.gas_price, total_gas)?; total_cost = safe_add_balance(total_cost, total_gas_cost)?; @@ -75,11 +64,10 @@ fn receipt_cost( /// Calculates and returns total cost of all the receipts. fn total_receipts_cost( config: &RuntimeConfig, - current_protocol_version: ProtocolVersion, receipts: &[Receipt], ) -> Result { receipts.iter().try_fold(0, |accumulator, receipt| { - let cost = receipt_cost(config, current_protocol_version, receipt)?; + let cost = receipt_cost(config, receipt)?; safe_add_balance(accumulator, cost) }) } @@ -102,14 +90,13 @@ fn total_accounts_balance( fn total_postponed_receipts_cost( state: &dyn TrieAccess, config: &RuntimeConfig, - current_protocol_version: ProtocolVersion, receipt_ids: &HashSet<(AccountId, crate::CryptoHash)>, ) -> Result { receipt_ids.iter().try_fold(0, |total, item| { let (account_id, receipt_id) = item; let cost = match get_postponed_receipt(state, account_id, *receipt_id)? { None => return Ok(total), - Some(receipt) => receipt_cost(config, current_protocol_version, &receipt)?, + Some(receipt) => receipt_cost(config, &receipt)?, }; safe_add_balance(total, cost).map_err(|_| RuntimeError::UnexpectedIntegerOverflow) }) @@ -123,7 +110,6 @@ pub(crate) fn check_balance( transactions: &[SignedTransaction], outgoing_receipts: &[Receipt], stats: &ApplyStats, - current_protocol_version: ProtocolVersion, ) -> Result<(), RuntimeError> { let initial_state = final_state.trie(); @@ -173,7 +159,7 @@ pub(crate) fn check_balance( let final_accounts_balance = total_accounts_balance(final_state, &all_accounts_ids)?; // Receipts let receipts_cost = |receipts: &[Receipt]| -> Result { - total_receipts_cost(config, current_protocol_version, receipts) + total_receipts_cost(config, receipts) }; let incoming_receipts_balance = receipts_cost(incoming_receipts)?; let outgoing_receipts_balance = receipts_cost(outgoing_receipts)?; @@ -208,18 +194,10 @@ pub(crate) fn check_balance( }) .collect::, StorageError>>()?; - let initial_postponed_receipts_balance = total_postponed_receipts_cost( - initial_state, - config, - current_protocol_version, - &all_potential_postponed_receipt_ids, - )?; - let final_postponed_receipts_balance = total_postponed_receipts_cost( - final_state, - config, - current_protocol_version, - &all_potential_postponed_receipt_ids, - )?; + let initial_postponed_receipts_balance = + total_postponed_receipts_cost(initial_state, config, &all_potential_postponed_receipt_ids)?; + let final_postponed_receipts_balance = + total_postponed_receipts_cost(final_state, config, &all_potential_postponed_receipt_ids)?; // Sum it up let initial_balance = safe_add_balance_apply!( @@ -277,7 +255,6 @@ mod tests { use crate::near_primitives::shard_layout::ShardUId; use assert_matches::assert_matches; - use near_primitives::version::PROTOCOL_VERSION; /// Initial balance used in tests. pub const TESTING_INIT_BALANCE: Balance = 1_000_000_000 * NEAR_BASE; @@ -298,7 +275,6 @@ mod tests { &[], &[], &ApplyStats::default(), - PROTOCOL_VERSION, ) .unwrap(); } @@ -316,7 +292,6 @@ mod tests { &[], &[], &ApplyStats::default(), - PROTOCOL_VERSION, ) .unwrap_err(); assert_matches!(err, RuntimeError::BalanceMismatchError(_)); @@ -376,7 +351,6 @@ mod tests { &[], &[], &ApplyStats::default(), - PROTOCOL_VERSION, ) .unwrap(); } @@ -450,7 +424,6 @@ mod tests { other_burnt_amount: 0, slashed_burnt_amount: 0, }, - PROTOCOL_VERSION, ) .unwrap(); } @@ -501,7 +474,6 @@ mod tests { &[tx], &[], &ApplyStats::default(), - PROTOCOL_VERSION, ), Err(RuntimeError::UnexpectedIntegerOverflow) ); diff --git a/runtime/runtime/src/config.rs b/runtime/runtime/src/config.rs index 380c4be63a4..36ab54cc334 100644 --- a/runtime/runtime/src/config.rs +++ b/runtime/runtime/src/config.rs @@ -15,7 +15,6 @@ use near_primitives::transaction::{ Action, AddKeyAction, DeployContractAction, FunctionCallAction, Transaction, }; use near_primitives::types::{AccountId, Balance, Compute, Gas}; -use near_primitives::version::{checked_feature, ProtocolVersion}; /// Describes the cost of converting this transaction into a receipt. #[derive(Debug)] @@ -77,7 +76,6 @@ pub fn total_send_fees( sender_is_receiver: bool, actions: &[Action], receiver_id: &AccountId, - current_protocol_version: ProtocolVersion, ) -> Result { let mut result = 0; let fees = &config.fees; @@ -101,8 +99,7 @@ pub fn total_send_fees( Transfer(_) => { // Account for implicit account creation let is_receiver_implicit = - checked_feature!("stable", ImplicitAccountCreation, current_protocol_version) - && receiver_id.is_implicit(); + config.wasm_config.implicit_account_creation && receiver_id.is_implicit(); transfer_send_fee(fees, sender_is_receiver, is_receiver_implicit) } Stake(_) => fees.fee(ActionCosts::stake).send_fee(sender_is_receiver), @@ -136,7 +133,6 @@ pub fn total_send_fees( sender_is_receiver, &delegate_action.get_actions(), &delegate_action.receiver_id, - current_protocol_version, )? } }; @@ -153,7 +149,6 @@ pub fn total_send_fees( pub fn total_prepaid_send_fees( config: &RuntimeConfig, actions: &[Action], - current_protocol_version: ProtocolVersion, ) -> Result { let mut result = 0; for action in actions { @@ -168,7 +163,6 @@ pub fn total_prepaid_send_fees( sender_is_receiver, &delegate_action.get_actions(), &delegate_action.receiver_id, - current_protocol_version, )? } _ => 0, @@ -178,12 +172,7 @@ pub fn total_prepaid_send_fees( Ok(result) } -pub fn exec_fee( - config: &RuntimeConfig, - action: &Action, - receiver_id: &AccountId, - current_protocol_version: ProtocolVersion, -) -> Gas { +pub fn exec_fee(config: &RuntimeConfig, action: &Action, receiver_id: &AccountId) -> Gas { use Action::*; let fees = &config.fees; match action { @@ -201,8 +190,7 @@ pub fn exec_fee( Transfer(_) => { // Account for implicit account creation let is_receiver_implicit = - checked_feature!("stable", ImplicitAccountCreation, current_protocol_version) - && receiver_id.is_implicit(); + config.wasm_config.implicit_account_creation && receiver_id.is_implicit(); transfer_exec_fee(fees, is_receiver_implicit) } Stake(_) => fees.fee(ActionCosts::stake).exec_fee(), @@ -233,7 +221,6 @@ pub fn tx_cost( transaction: &Transaction, gas_price: Balance, sender_is_receiver: bool, - current_protocol_version: ProtocolVersion, ) -> Result { let fees = &config.fees; let mut gas_burnt: Gas = fees.fee(ActionCosts::new_action_receipt).send_fee(sender_is_receiver); @@ -244,12 +231,11 @@ pub fn tx_cost( sender_is_receiver, &transaction.actions, &transaction.receiver_id, - current_protocol_version, )?, )?; let prepaid_gas = safe_add_gas( total_prepaid_gas(&transaction.actions)?, - total_prepaid_send_fees(config, &transaction.actions, current_protocol_version)?, + total_prepaid_send_fees(config, &transaction.actions)?, )?; // If signer is equals to receiver the receipt will be processed at the same block as this // transaction. Otherwise it will processed in the next block and the gas might be inflated. @@ -274,12 +260,7 @@ pub fn tx_cost( safe_add_gas(prepaid_gas, fees.fee(ActionCosts::new_action_receipt).exec_fee())?; gas_remaining = safe_add_gas( gas_remaining, - total_prepaid_exec_fees( - config, - &transaction.actions, - &transaction.receiver_id, - current_protocol_version, - )?, + total_prepaid_exec_fees(config, &transaction.actions, &transaction.receiver_id)?, )?; let burnt_amount = safe_gas_to_balance(gas_price, gas_burnt)?; let remaining_gas_amount = safe_gas_to_balance(receipt_gas_price, gas_remaining)?; @@ -293,7 +274,6 @@ pub fn total_prepaid_exec_fees( config: &RuntimeConfig, actions: &[Action], receiver_id: &AccountId, - current_protocol_version: ProtocolVersion, ) -> Result { let mut result = 0; let fees = &config.fees; @@ -306,20 +286,14 @@ pub fn total_prepaid_exec_fees( config, &actions, &signed_delegate_action.delegate_action.receiver_id, - current_protocol_version, )?; delta = safe_add_gas( delta, - exec_fee( - config, - action, - &signed_delegate_action.delegate_action.receiver_id, - current_protocol_version, - ), + exec_fee(config, action, &signed_delegate_action.delegate_action.receiver_id), )?; delta = safe_add_gas(delta, fees.fee(ActionCosts::new_action_receipt).exec_fee())?; } else { - delta = exec_fee(config, action, receiver_id, current_protocol_version); + delta = exec_fee(config, action, receiver_id); } result = safe_add_gas(result, delta)?; diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 7ec032a1ae6..1b4f52a5645 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -298,12 +298,7 @@ impl Runtime { actions: &[Action], epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { - let exec_fees = exec_fee( - &apply_state.config, - action, - &receipt.receiver_id, - apply_state.current_protocol_version, - ); + let exec_fees = exec_fee(&apply_state.config, action, &receipt.receiver_id); let mut result = ActionResult::default(); result.gas_used = exec_fees; result.gas_burnt = exec_fees; @@ -317,7 +312,7 @@ impl Runtime { action, account, account_id, - apply_state.current_protocol_version, + &apply_state.config, is_the_only_action, is_refund, ) { @@ -383,11 +378,7 @@ impl Runtime { } } else { // Implicit account creation - debug_assert!(checked_feature!( - "stable", - ImplicitAccountCreation, - apply_state.current_protocol_version - )); + debug_assert!(apply_state.config.wasm_config.implicit_account_creation); debug_assert!(!is_refund); action_implicit_account_creation_transfer( state_update, @@ -613,7 +604,6 @@ impl Runtime { receipt, action_receipt, &mut result, - apply_state.current_protocol_version, &apply_state.config, )? }; @@ -772,21 +762,15 @@ impl Runtime { receipt: &Receipt, action_receipt: &ActionReceipt, result: &mut ActionResult, - current_protocol_version: ProtocolVersion, config: &RuntimeConfig, ) -> Result { let total_deposit = total_deposit(&action_receipt.actions)?; let prepaid_gas = safe_add_gas( total_prepaid_gas(&action_receipt.actions)?, - total_prepaid_send_fees(config, &action_receipt.actions, current_protocol_version)?, + total_prepaid_send_fees(config, &action_receipt.actions)?, )?; let prepaid_exec_gas = safe_add_gas( - total_prepaid_exec_fees( - config, - &action_receipt.actions, - &receipt.receiver_id, - current_protocol_version, - )?, + total_prepaid_exec_fees(config, &action_receipt.actions, &receipt.receiver_id)?, config.fees.fee(ActionCosts::new_action_receipt).exec_fee(), )?; let deposit_refund = if result.result.is_err() { total_deposit } else { 0 }; @@ -1466,7 +1450,6 @@ impl Runtime { transactions, &outgoing_receipts, &stats, - apply_state.current_protocol_version, )?; state_update.commit(StateChangeCause::UpdatedDelayedReceipts); @@ -2250,13 +2233,7 @@ mod tests { let expected_gas_burnt = safe_add_gas( apply_state.config.fees.fee(ActionCosts::new_action_receipt).exec_fee(), - total_prepaid_exec_fees( - &apply_state.config, - &actions, - &alice_account(), - PROTOCOL_VERSION, - ) - .unwrap(), + total_prepaid_exec_fees(&apply_state.config, &actions, &alice_account()).unwrap(), ) .unwrap(); let receipts = vec![Receipt { @@ -2319,13 +2296,7 @@ mod tests { let expected_gas_burnt = safe_add_gas( apply_state.config.fees.fee(ActionCosts::new_action_receipt).exec_fee(), - total_prepaid_exec_fees( - &apply_state.config, - &actions, - &alice_account(), - PROTOCOL_VERSION, - ) - .unwrap(), + total_prepaid_exec_fees(&apply_state.config, &actions, &alice_account()).unwrap(), ) .unwrap(); let receipts = vec![Receipt { diff --git a/runtime/runtime/src/verifier.rs b/runtime/runtime/src/verifier.rs index 30454b3168f..d4be6e673f5 100644 --- a/runtime/runtime/src/verifier.rs +++ b/runtime/runtime/src/verifier.rs @@ -123,7 +123,7 @@ pub fn validate_transaction( let sender_is_receiver = &transaction.receiver_id == signer_id; - tx_cost(&config, transaction, gas_price, sender_is_receiver, current_protocol_version) + tx_cost(&config, transaction, gas_price, sender_is_receiver) .map_err(|_| InvalidTxError::CostOverflow.into()) } diff --git a/test-utils/testlib/src/fees_utils.rs b/test-utils/testlib/src/fees_utils.rs index 8aa654d9cf3..ddd964946a5 100644 --- a/test-utils/testlib/src/fees_utils.rs +++ b/test-utils/testlib/src/fees_utils.rs @@ -5,7 +5,6 @@ use near_primitives::runtime::config::RuntimeConfig; use near_primitives::runtime::fees::RuntimeFeesConfig; use near_primitives::transaction::Action; use near_primitives::types::{AccountId, Balance, Gas}; -use near_primitives::version::PROTOCOL_VERSION; pub struct FeeHelper { pub rt_cfg: RuntimeConfig, @@ -182,14 +181,7 @@ impl FeeHelper { let total_gas = base.exec_fee() + base.send_fee(sir) + receipt.send_fee(sir) - + node_runtime::config::total_send_fees( - &self.rt_cfg, - sir, - actions, - receiver, - PROTOCOL_VERSION, - ) - .unwrap(); + + node_runtime::config::total_send_fees(&self.rt_cfg, sir, actions, receiver).unwrap(); self.gas_to_balance(total_gas) } }