From 89af585bfbdfafdfdbea7ef0aca02c0bcf4a1367 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 24 Nov 2022 15:57:48 +0100 Subject: [PATCH 1/4] refactor: ExtCostsConfig as simple map of costs This is the next step in the refactoring steps for changing gas profiles to track gas by parameter (#8033). Here we make `ExtCostsConfig` opaque and look up parameters by ```rust pub fn cost(&self, param: ExtCosts) -> Gas ``` instead of using a specific field inside. There are side-effects for this in 1. parameter definition 2. JSON RPC 3. parameter estimator 1) We no longer load the parameters through "parameter table -> JSON -> serde_deser" steps because `ExtCostsConfig` no longer has serde derives. Instead each `ExtCosts` maps to a `Parameter` that allows looking up the value directly from `ParameterTable`. This explicit mapping also replaces the `Parameter::ext_costs()` iterator previously used to find all parameters that are ext costs. We used to define `wasm_read_cached_trie_node` in `53.txt` and fill old values with serde default. Serde was removed here, so I changed it to define the parameter the base files. This is equivalent to the old behavior, only it is less clear when we added the parameter. 2) JSON RPC must keep the old format. Thus, I added `ExtCostsConfigView` and `VMConfigView` there. It is a direct copy-paste of the old structs in the old format but without serde magic to fill in missing values. 3) The estimator generates a `ExtCostsConfig` from estimations. This is now done through a mapping from estimated costs to `ExtCosts`. # Testing The exact JSON output is checked in existing tests `test_json_unchanged`. --- core/primitives-core/src/config.rs | 524 +++++------------- core/primitives-core/src/parameter.rs | 71 --- core/primitives/res/runtime_configs/53.txt | 1 - .../res/runtime_configs/parameters.txt | 1 + .../runtime_configs/parameters_testnet.txt | 1 + core/primitives/src/runtime/config_store.rs | 6 +- .../primitives/src/runtime/parameter_table.rs | 9 +- core/primitives/src/views.rs | 357 +++++++++++- nearcore/src/runtime/mod.rs | 5 +- .../src/costs_to_runtime_config.rs | 151 ++--- 10 files changed, 593 insertions(+), 533 deletions(-) diff --git a/core/primitives-core/src/config.rs b/core/primitives-core/src/config.rs index b8f41f858f7..358b7538d16 100644 --- a/core/primitives-core/src/config.rs +++ b/core/primitives-core/src/config.rs @@ -1,5 +1,7 @@ +use crate::parameter::Parameter; use crate::types::Gas; +use enum_map::{enum_map, EnumMap}; use serde::{Deserialize, Serialize}; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; @@ -12,7 +14,7 @@ use strum::{Display, EnumCount}; /// protocol specific behavior of the contract runtime. The former contains /// configuration for the WASM runtime specifically, while the latter contains /// configuration for the transaction runtime and WASM runtime. -#[derive(Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct VMConfig { /// Costs for runtime externals pub ext_costs: ExtCostsConfig, @@ -256,183 +258,9 @@ pub struct ViewConfig { pub max_gas_burnt: Gas, } -#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct ExtCostsConfig { - /// Base cost for calling a host function. - pub base: Gas, - - /// Base cost of loading a pre-compiled contract - pub contract_loading_base: Gas, - /// Cost per byte of loading a pre-compiled contract - pub contract_loading_bytes: Gas, - - /// Base cost for guest memory read - pub read_memory_base: Gas, - /// Cost for guest memory read - pub read_memory_byte: Gas, - - /// Base cost for guest memory write - pub write_memory_base: Gas, - /// Cost for guest memory write per byte - pub write_memory_byte: Gas, - - /// Base cost for reading from register - pub read_register_base: Gas, - /// Cost for reading byte from register - pub read_register_byte: Gas, - - /// Base cost for writing into register - pub write_register_base: Gas, - /// Cost for writing byte into register - pub write_register_byte: Gas, - - /// Base cost of decoding utf8. It's used for `log_utf8` and `panic_utf8`. - pub utf8_decoding_base: Gas, - /// Cost per byte of decoding utf8. It's used for `log_utf8` and `panic_utf8`. - pub utf8_decoding_byte: Gas, - - /// Base cost of decoding utf16. It's used for `log_utf16`. - pub utf16_decoding_base: Gas, - /// Cost per byte of decoding utf16. It's used for `log_utf16`. - pub utf16_decoding_byte: Gas, - - /// Cost of getting sha256 base - pub sha256_base: Gas, - /// Cost of getting sha256 per byte - pub sha256_byte: Gas, - - /// Cost of getting sha256 base - pub keccak256_base: Gas, - /// Cost of getting sha256 per byte - pub keccak256_byte: Gas, - - /// Cost of getting sha256 base - pub keccak512_base: Gas, - /// Cost of getting sha256 per byte - pub keccak512_byte: Gas, - - /// Cost of getting ripemd160 base - pub ripemd160_base: Gas, - /// Cost of getting ripemd160 per message block - pub ripemd160_block: Gas, - - /// Cost of getting ed25519 base - #[cfg(feature = "protocol_feature_ed25519_verify")] - pub ed25519_verify_base: Gas, - /// Cost of getting ed25519 per byte - #[cfg(feature = "protocol_feature_ed25519_verify")] - pub ed25519_verify_byte: Gas, - - /// Cost of calling ecrecover - pub ecrecover_base: Gas, - - /// Cost for calling logging. - pub log_base: Gas, - /// Cost for logging per byte - pub log_byte: Gas, - - // ############### - // # Storage API # - // ############### - /// Storage trie write key base cost - pub storage_write_base: Gas, - /// Storage trie write key per byte cost - pub storage_write_key_byte: Gas, - /// Storage trie write value per byte cost - pub storage_write_value_byte: Gas, - /// Storage trie write cost per byte of evicted value. - pub storage_write_evicted_byte: Gas, - - /// Storage trie read key base cost - pub storage_read_base: Gas, - /// Storage trie read key per byte cost - pub storage_read_key_byte: Gas, - /// Storage trie read value cost per byte cost - pub storage_read_value_byte: Gas, - - /// Remove key from trie base cost - pub storage_remove_base: Gas, - /// Remove key from trie per byte cost - pub storage_remove_key_byte: Gas, - /// Remove key from trie ret value byte cost - pub storage_remove_ret_value_byte: Gas, - - /// Storage trie check for key existence cost base - pub storage_has_key_base: Gas, - /// Storage trie check for key existence per key byte - pub storage_has_key_byte: Gas, - - /// Create trie prefix iterator cost base - pub storage_iter_create_prefix_base: Gas, - /// Create trie prefix iterator cost per byte. - pub storage_iter_create_prefix_byte: Gas, - - /// Create trie range iterator cost base - pub storage_iter_create_range_base: Gas, - /// Create trie range iterator cost per byte of from key. - pub storage_iter_create_from_byte: Gas, - /// Create trie range iterator cost per byte of to key. - pub storage_iter_create_to_byte: Gas, - - /// Trie iterator per key base cost - pub storage_iter_next_base: Gas, - /// Trie iterator next key byte cost - pub storage_iter_next_key_byte: Gas, - /// Trie iterator next key byte cost - pub storage_iter_next_value_byte: Gas, - - /// Cost per reading trie node from DB - pub touching_trie_node: Gas, - /// Cost for reading trie node from memory - #[serde(default = "default_read_cached_trie_node")] - pub read_cached_trie_node: Gas, - - // ############### - // # Promise API # - // ############### - /// Cost for calling `promise_and` - pub promise_and_base: Gas, - /// Cost for calling `promise_and` for each promise - pub promise_and_per_promise: Gas, - /// Cost for calling `promise_return` - pub promise_return: Gas, - - // ############### - // # Validator API # - // ############### - /// Cost of calling `validator_stake`. - pub validator_stake_base: Gas, - /// Cost of calling `validator_total_stake`. - pub validator_total_stake_base: Gas, - - // Workaround to keep JSON serialization backwards-compatible - // . - // - // Remove once #5516 is fixed. - #[serde(default, rename = "contract_compile_base")] - pub _unused1: Gas, - #[serde(default, rename = "contract_compile_bytes")] - pub _unused2: Gas, - - // ############# - // # Alt BN128 # - // ############# - /// Base cost for multiexp - pub alt_bn128_g1_multiexp_base: Gas, - /// Per element cost for multiexp - pub alt_bn128_g1_multiexp_element: Gas, - /// Base cost for sum - pub alt_bn128_g1_sum_base: Gas, - /// Per element cost for sum - pub alt_bn128_g1_sum_element: Gas, - /// Base cost for pairing check - pub alt_bn128_pairing_check_base: Gas, - /// Per element cost for pairing check - pub alt_bn128_pairing_check_element: Gas, -} - -fn default_read_cached_trie_node() -> Gas { - SAFETY_MULTIPLIER * 760_000_000 + pub costs: EnumMap, } // We multiply the actual computed costs by the fixed factor to ensure we @@ -440,153 +268,104 @@ fn default_read_cached_trie_node() -> Gas { const SAFETY_MULTIPLIER: u64 = 3; impl ExtCostsConfig { + pub fn cost(&self, param: ExtCosts) -> Gas { + self.costs[param] + } + /// Convenience constructor to use in tests where the exact gas cost does /// not need to correspond to a specific protocol version. pub fn test() -> ExtCostsConfig { - ExtCostsConfig { - base: SAFETY_MULTIPLIER * 88256037, - contract_loading_base: SAFETY_MULTIPLIER * 11815321, - contract_loading_bytes: SAFETY_MULTIPLIER * 72250, - read_memory_base: SAFETY_MULTIPLIER * 869954400, - read_memory_byte: SAFETY_MULTIPLIER * 1267111, - write_memory_base: SAFETY_MULTIPLIER * 934598287, - write_memory_byte: SAFETY_MULTIPLIER * 907924, - read_register_base: SAFETY_MULTIPLIER * 839055062, - read_register_byte: SAFETY_MULTIPLIER * 32854, - write_register_base: SAFETY_MULTIPLIER * 955174162, - write_register_byte: SAFETY_MULTIPLIER * 1267188, - utf8_decoding_base: SAFETY_MULTIPLIER * 1037259687, - utf8_decoding_byte: SAFETY_MULTIPLIER * 97193493, - utf16_decoding_base: SAFETY_MULTIPLIER * 1181104350, - utf16_decoding_byte: SAFETY_MULTIPLIER * 54525831, - sha256_base: SAFETY_MULTIPLIER * 1513656750, - sha256_byte: SAFETY_MULTIPLIER * 8039117, - keccak256_base: SAFETY_MULTIPLIER * 1959830425, - keccak256_byte: SAFETY_MULTIPLIER * 7157035, - keccak512_base: SAFETY_MULTIPLIER * 1937129412, - keccak512_byte: SAFETY_MULTIPLIER * 12216567, - ripemd160_base: SAFETY_MULTIPLIER * 284558362, + let costs = enum_map! { + ExtCosts::base => SAFETY_MULTIPLIER * 88256037, + ExtCosts::contract_loading_base => SAFETY_MULTIPLIER * 11815321, + ExtCosts::contract_loading_bytes => SAFETY_MULTIPLIER * 72250, + ExtCosts::read_memory_base => SAFETY_MULTIPLIER * 869954400, + ExtCosts::read_memory_byte => SAFETY_MULTIPLIER * 1267111, + ExtCosts::write_memory_base => SAFETY_MULTIPLIER * 934598287, + ExtCosts::write_memory_byte => SAFETY_MULTIPLIER * 907924, + ExtCosts::read_register_base => SAFETY_MULTIPLIER * 839055062, + ExtCosts::read_register_byte => SAFETY_MULTIPLIER * 32854, + ExtCosts::write_register_base => SAFETY_MULTIPLIER * 955174162, + ExtCosts::write_register_byte => SAFETY_MULTIPLIER * 1267188, + ExtCosts::utf8_decoding_base => SAFETY_MULTIPLIER * 1037259687, + ExtCosts::utf8_decoding_byte => SAFETY_MULTIPLIER * 97193493, + ExtCosts::utf16_decoding_base => SAFETY_MULTIPLIER * 1181104350, + ExtCosts::utf16_decoding_byte => SAFETY_MULTIPLIER * 54525831, + ExtCosts::sha256_base => SAFETY_MULTIPLIER * 1513656750, + ExtCosts::sha256_byte => SAFETY_MULTIPLIER * 8039117, + ExtCosts::keccak256_base => SAFETY_MULTIPLIER * 1959830425, + ExtCosts::keccak256_byte => SAFETY_MULTIPLIER * 7157035, + ExtCosts::keccak512_base => SAFETY_MULTIPLIER * 1937129412, + ExtCosts::keccak512_byte => SAFETY_MULTIPLIER * 12216567, + ExtCosts::ripemd160_base => SAFETY_MULTIPLIER * 284558362, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_base: SAFETY_MULTIPLIER * 1513656750, + ExtCosts::ed25519_verify_base => SAFETY_MULTIPLIER * 1513656750, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_byte: SAFETY_MULTIPLIER * 7157035, - // Cost per byte is 3542227. There are 64 bytes in a block. - ripemd160_block: SAFETY_MULTIPLIER * 226702528, - ecrecover_base: SAFETY_MULTIPLIER * 1121789875000, - log_base: SAFETY_MULTIPLIER * 1181104350, - log_byte: SAFETY_MULTIPLIER * 4399597, - storage_write_base: SAFETY_MULTIPLIER * 21398912000, - storage_write_key_byte: SAFETY_MULTIPLIER * 23494289, - storage_write_value_byte: SAFETY_MULTIPLIER * 10339513, - storage_write_evicted_byte: SAFETY_MULTIPLIER * 10705769, - storage_read_base: SAFETY_MULTIPLIER * 18785615250, - storage_read_key_byte: SAFETY_MULTIPLIER * 10317511, - storage_read_value_byte: SAFETY_MULTIPLIER * 1870335, - storage_remove_base: SAFETY_MULTIPLIER * 17824343500, - storage_remove_key_byte: SAFETY_MULTIPLIER * 12740128, - storage_remove_ret_value_byte: SAFETY_MULTIPLIER * 3843852, - storage_has_key_base: SAFETY_MULTIPLIER * 18013298875, - storage_has_key_byte: SAFETY_MULTIPLIER * 10263615, - storage_iter_create_prefix_base: SAFETY_MULTIPLIER * 0, - storage_iter_create_prefix_byte: SAFETY_MULTIPLIER * 0, - storage_iter_create_range_base: SAFETY_MULTIPLIER * 0, - storage_iter_create_from_byte: SAFETY_MULTIPLIER * 0, - storage_iter_create_to_byte: SAFETY_MULTIPLIER * 0, - storage_iter_next_base: SAFETY_MULTIPLIER * 0, - storage_iter_next_key_byte: SAFETY_MULTIPLIER * 0, - storage_iter_next_value_byte: SAFETY_MULTIPLIER * 0, - touching_trie_node: SAFETY_MULTIPLIER * 5367318642, - read_cached_trie_node: default_read_cached_trie_node(), - promise_and_base: SAFETY_MULTIPLIER * 488337800, - promise_and_per_promise: SAFETY_MULTIPLIER * 1817392, - promise_return: SAFETY_MULTIPLIER * 186717462, - validator_stake_base: SAFETY_MULTIPLIER * 303944908800, - validator_total_stake_base: SAFETY_MULTIPLIER * 303944908800, - _unused1: 0, - _unused2: 0, - alt_bn128_g1_multiexp_base: 713_000_000_000, - alt_bn128_g1_multiexp_element: 320_000_000_000, - alt_bn128_pairing_check_base: 9_686_000_000_000, - alt_bn128_pairing_check_element: 5_102_000_000_000, - alt_bn128_g1_sum_base: 3_000_000_000, - alt_bn128_g1_sum_element: 5_000_000_000, - } + ExtCosts::ed25519_verify_byte => SAFETY_MULTIPLIER * 7157035, + ExtCosts::ripemd160_block => SAFETY_MULTIPLIER * 226702528, + ExtCosts::ecrecover_base => SAFETY_MULTIPLIER * 1121789875000, + ExtCosts::log_base => SAFETY_MULTIPLIER * 1181104350, + ExtCosts::log_byte => SAFETY_MULTIPLIER * 4399597, + ExtCosts::storage_write_base => SAFETY_MULTIPLIER * 21398912000, + ExtCosts::storage_write_key_byte => SAFETY_MULTIPLIER * 23494289, + ExtCosts::storage_write_value_byte => SAFETY_MULTIPLIER * 10339513, + ExtCosts::storage_write_evicted_byte => SAFETY_MULTIPLIER * 10705769, + ExtCosts::storage_read_base => SAFETY_MULTIPLIER * 18785615250, + ExtCosts::storage_read_key_byte => SAFETY_MULTIPLIER * 10317511, + ExtCosts::storage_read_value_byte => SAFETY_MULTIPLIER * 1870335, + ExtCosts::storage_remove_base => SAFETY_MULTIPLIER * 17824343500, + ExtCosts::storage_remove_key_byte => SAFETY_MULTIPLIER * 12740128, + ExtCosts::storage_remove_ret_value_byte => SAFETY_MULTIPLIER * 3843852, + ExtCosts::storage_has_key_base => SAFETY_MULTIPLIER * 18013298875, + ExtCosts::storage_has_key_byte => SAFETY_MULTIPLIER * 10263615, + ExtCosts::storage_iter_create_prefix_base => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_create_prefix_byte => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_create_range_base => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_create_from_byte => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_create_to_byte => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_next_base => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_next_key_byte => SAFETY_MULTIPLIER * 0, + ExtCosts::storage_iter_next_value_byte => SAFETY_MULTIPLIER * 0, + ExtCosts::touching_trie_node => SAFETY_MULTIPLIER * 5367318642, + ExtCosts::read_cached_trie_node => SAFETY_MULTIPLIER * 760_000_000, + ExtCosts::promise_and_base => SAFETY_MULTIPLIER * 488337800, + ExtCosts::promise_and_per_promise => SAFETY_MULTIPLIER * 1817392, + ExtCosts::promise_return => SAFETY_MULTIPLIER * 186717462, + ExtCosts::validator_stake_base => SAFETY_MULTIPLIER * 303944908800, + ExtCosts::validator_total_stake_base => SAFETY_MULTIPLIER * 303944908800, + ExtCosts::alt_bn128_g1_multiexp_base => 713_000_000_000, + ExtCosts::alt_bn128_g1_multiexp_element => 320_000_000_000, + ExtCosts::alt_bn128_pairing_check_base => 9_686_000_000_000, + ExtCosts::alt_bn128_pairing_check_element => 5_102_000_000_000, + ExtCosts::alt_bn128_g1_sum_base => 3_000_000_000, + ExtCosts::alt_bn128_g1_sum_element => 5_000_000_000, + }; + ExtCostsConfig { costs } } fn free() -> ExtCostsConfig { ExtCostsConfig { - base: 0, - contract_loading_base: 0, - contract_loading_bytes: 0, - read_memory_base: 0, - read_memory_byte: 0, - write_memory_base: 0, - write_memory_byte: 0, - read_register_base: 0, - read_register_byte: 0, - write_register_base: 0, - write_register_byte: 0, - utf8_decoding_base: 0, - utf8_decoding_byte: 0, - utf16_decoding_base: 0, - utf16_decoding_byte: 0, - sha256_base: 0, - sha256_byte: 0, - keccak256_base: 0, - keccak256_byte: 0, - keccak512_base: 0, - keccak512_byte: 0, - ripemd160_base: 0, - ripemd160_block: 0, - #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_base: 0, - #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_byte: 0, - ecrecover_base: 0, - log_base: 0, - log_byte: 0, - storage_write_base: 0, - storage_write_key_byte: 0, - storage_write_value_byte: 0, - storage_write_evicted_byte: 0, - storage_read_base: 0, - storage_read_key_byte: 0, - storage_read_value_byte: 0, - storage_remove_base: 0, - storage_remove_key_byte: 0, - storage_remove_ret_value_byte: 0, - storage_has_key_base: 0, - storage_has_key_byte: 0, - 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: 0, - read_cached_trie_node: 0, - promise_and_base: 0, - promise_and_per_promise: 0, - promise_return: 0, - validator_stake_base: 0, - validator_total_stake_base: 0, - _unused1: 0, - _unused2: 0, - alt_bn128_g1_multiexp_base: 0, - alt_bn128_g1_multiexp_element: 0, - alt_bn128_pairing_check_base: 0, - alt_bn128_pairing_check_element: 0, - alt_bn128_g1_sum_base: 0, - alt_bn128_g1_sum_element: 0, + costs: enum_map! { + _ => 0 + }, } } } /// Strongly-typed representation of the fees for counting. #[derive( - Copy, Clone, Hash, PartialEq, Eq, Debug, PartialOrd, Ord, EnumCount, Display, strum::EnumIter, + Copy, + Clone, + Hash, + PartialEq, + Eq, + Debug, + PartialOrd, + Ord, + EnumCount, + Display, + strum::EnumIter, + enum_map::Enum, )] #[allow(non_camel_case_types)] pub enum ExtCosts { @@ -691,71 +470,74 @@ pub enum ActionCosts { impl ExtCosts { pub fn value(self, config: &ExtCostsConfig) -> Gas { - use ExtCosts::*; + config.cost(self) + } + + pub fn param(&self) -> Parameter { match self { - base => config.base, - contract_loading_base => config.contract_loading_base, - contract_loading_bytes => config.contract_loading_bytes, - read_memory_base => config.read_memory_base, - read_memory_byte => config.read_memory_byte, - write_memory_base => config.write_memory_base, - write_memory_byte => config.write_memory_byte, - read_register_base => config.read_register_base, - read_register_byte => config.read_register_byte, - write_register_base => config.write_register_base, - write_register_byte => config.write_register_byte, - utf8_decoding_base => config.utf8_decoding_base, - utf8_decoding_byte => config.utf8_decoding_byte, - utf16_decoding_base => config.utf16_decoding_base, - utf16_decoding_byte => config.utf16_decoding_byte, - sha256_base => config.sha256_base, - sha256_byte => config.sha256_byte, - keccak256_base => config.keccak256_base, - keccak256_byte => config.keccak256_byte, - keccak512_base => config.keccak512_base, - keccak512_byte => config.keccak512_byte, - ripemd160_base => config.ripemd160_base, - ripemd160_block => config.ripemd160_block, + ExtCosts::base => Parameter::WasmBase, + ExtCosts::contract_loading_base => Parameter::WasmContractLoadingBase, + ExtCosts::contract_loading_bytes => Parameter::WasmContractLoadingBytes, + ExtCosts::read_memory_base => Parameter::WasmReadMemoryBase, + ExtCosts::read_memory_byte => Parameter::WasmReadMemoryByte, + ExtCosts::write_memory_base => Parameter::WasmWriteMemoryBase, + ExtCosts::write_memory_byte => Parameter::WasmWriteMemoryByte, + ExtCosts::read_register_base => Parameter::WasmReadRegisterBase, + ExtCosts::read_register_byte => Parameter::WasmReadRegisterByte, + ExtCosts::write_register_base => Parameter::WasmWriteRegisterBase, + ExtCosts::write_register_byte => Parameter::WasmWriteRegisterByte, + ExtCosts::utf8_decoding_base => Parameter::WasmUtf8DecodingBase, + ExtCosts::utf8_decoding_byte => Parameter::WasmUtf8DecodingByte, + ExtCosts::utf16_decoding_base => Parameter::WasmUtf16DecodingBase, + ExtCosts::utf16_decoding_byte => Parameter::WasmUtf16DecodingByte, + ExtCosts::sha256_base => Parameter::WasmSha256Base, + ExtCosts::sha256_byte => Parameter::WasmSha256Byte, + ExtCosts::keccak256_base => Parameter::WasmKeccak256Base, + ExtCosts::keccak256_byte => Parameter::WasmKeccak256Byte, + ExtCosts::keccak512_base => Parameter::WasmKeccak512Base, + ExtCosts::keccak512_byte => Parameter::WasmKeccak512Byte, + ExtCosts::ripemd160_base => Parameter::WasmRipemd160Base, + ExtCosts::ripemd160_block => Parameter::WasmRipemd160Block, + ExtCosts::ecrecover_base => Parameter::WasmEcrecoverBase, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_base => config.ed25519_verify_base, + ExtCosts::ed25519_verify_base => Parameter::WasmEd25519VerifyBase, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_byte => config.ed25519_verify_byte, - ecrecover_base => config.ecrecover_base, - log_base => config.log_base, - log_byte => config.log_byte, - storage_write_base => config.storage_write_base, - storage_write_key_byte => config.storage_write_key_byte, - storage_write_value_byte => config.storage_write_value_byte, - storage_write_evicted_byte => config.storage_write_evicted_byte, - storage_read_base => config.storage_read_base, - storage_read_key_byte => config.storage_read_key_byte, - storage_read_value_byte => config.storage_read_value_byte, - storage_remove_base => config.storage_remove_base, - storage_remove_key_byte => config.storage_remove_key_byte, - storage_remove_ret_value_byte => config.storage_remove_ret_value_byte, - storage_has_key_base => config.storage_has_key_base, - storage_has_key_byte => config.storage_has_key_byte, - storage_iter_create_prefix_base => config.storage_iter_create_prefix_base, - storage_iter_create_prefix_byte => config.storage_iter_create_prefix_byte, - storage_iter_create_range_base => config.storage_iter_create_range_base, - storage_iter_create_from_byte => config.storage_iter_create_from_byte, - storage_iter_create_to_byte => config.storage_iter_create_to_byte, - storage_iter_next_base => config.storage_iter_next_base, - storage_iter_next_key_byte => config.storage_iter_next_key_byte, - storage_iter_next_value_byte => config.storage_iter_next_value_byte, - touching_trie_node => config.touching_trie_node, - read_cached_trie_node => config.read_cached_trie_node, - promise_and_base => config.promise_and_base, - promise_and_per_promise => config.promise_and_per_promise, - promise_return => config.promise_return, - validator_stake_base => config.validator_stake_base, - validator_total_stake_base => config.validator_total_stake_base, - alt_bn128_g1_multiexp_base => config.alt_bn128_g1_multiexp_base, - alt_bn128_g1_multiexp_element => config.alt_bn128_g1_multiexp_element, - alt_bn128_pairing_check_base => config.alt_bn128_pairing_check_base, - alt_bn128_pairing_check_element => config.alt_bn128_pairing_check_element, - alt_bn128_g1_sum_base => config.alt_bn128_g1_sum_base, - alt_bn128_g1_sum_element => config.alt_bn128_g1_sum_element, + ExtCosts::ed25519_verify_byte => Parameter::WasmEd25519VerifyByte, + ExtCosts::log_base => Parameter::WasmLogBase, + ExtCosts::log_byte => Parameter::WasmLogByte, + ExtCosts::storage_write_base => Parameter::WasmStorageWriteBase, + ExtCosts::storage_write_key_byte => Parameter::WasmStorageWriteKeyByte, + ExtCosts::storage_write_value_byte => Parameter::WasmStorageWriteValueByte, + ExtCosts::storage_write_evicted_byte => Parameter::WasmStorageWriteEvictedByte, + ExtCosts::storage_read_base => Parameter::WasmStorageReadBase, + ExtCosts::storage_read_key_byte => Parameter::WasmStorageReadKeyByte, + ExtCosts::storage_read_value_byte => Parameter::WasmStorageReadValueByte, + ExtCosts::storage_remove_base => Parameter::WasmStorageRemoveBase, + ExtCosts::storage_remove_key_byte => Parameter::WasmStorageRemoveKeyByte, + ExtCosts::storage_remove_ret_value_byte => Parameter::WasmStorageRemoveRetValueByte, + ExtCosts::storage_has_key_base => Parameter::WasmStorageHasKeyBase, + ExtCosts::storage_has_key_byte => Parameter::WasmStorageHasKeyByte, + ExtCosts::storage_iter_create_prefix_base => Parameter::WasmStorageIterCreatePrefixBase, + ExtCosts::storage_iter_create_prefix_byte => Parameter::WasmStorageIterCreatePrefixByte, + ExtCosts::storage_iter_create_range_base => Parameter::WasmStorageIterCreateRangeBase, + ExtCosts::storage_iter_create_from_byte => Parameter::WasmStorageIterCreateFromByte, + ExtCosts::storage_iter_create_to_byte => Parameter::WasmStorageIterCreateToByte, + ExtCosts::storage_iter_next_base => Parameter::WasmStorageIterNextBase, + ExtCosts::storage_iter_next_key_byte => Parameter::WasmStorageIterNextKeyByte, + ExtCosts::storage_iter_next_value_byte => Parameter::WasmStorageIterNextValueByte, + ExtCosts::touching_trie_node => Parameter::WasmTouchingTrieNode, + ExtCosts::read_cached_trie_node => Parameter::WasmReadCachedTrieNode, + ExtCosts::promise_and_base => Parameter::WasmPromiseAndBase, + ExtCosts::promise_and_per_promise => Parameter::WasmPromiseAndPerPromise, + ExtCosts::promise_return => Parameter::WasmPromiseReturn, + ExtCosts::validator_stake_base => Parameter::WasmValidatorStakeBase, + ExtCosts::validator_total_stake_base => Parameter::WasmValidatorTotalStakeBase, + ExtCosts::alt_bn128_g1_multiexp_base => Parameter::WasmAltBn128G1MultiexpBase, + ExtCosts::alt_bn128_g1_multiexp_element => Parameter::WasmAltBn128G1MultiexpElement, + ExtCosts::alt_bn128_pairing_check_base => Parameter::WasmAltBn128PairingCheckBase, + ExtCosts::alt_bn128_pairing_check_element => Parameter::WasmAltBn128PairingCheckElement, + ExtCosts::alt_bn128_g1_sum_base => Parameter::WasmAltBn128G1SumBase, + ExtCosts::alt_bn128_g1_sum_element => Parameter::WasmAltBn128G1SumElement, } } } diff --git a/core/primitives-core/src/parameter.rs b/core/primitives-core/src/parameter.rs index 872f3575fec..547dbe4900b 100644 --- a/core/primitives-core/src/parameter.rs +++ b/core/primitives-core/src/parameter.rs @@ -210,77 +210,6 @@ pub enum FeeParameter { } impl Parameter { - /// Iterate through all parameters that define external gas costs that may - /// be charged during WASM execution. These are essentially all costs from - /// host function calls. Note that the gas cost for regular WASM operation - /// is treated separately and therefore not included in this list. - pub fn ext_costs() -> slice::Iter<'static, Parameter> { - [ - Parameter::WasmBase, - Parameter::WasmContractLoadingBase, - Parameter::WasmContractLoadingBytes, - Parameter::WasmReadMemoryBase, - Parameter::WasmReadMemoryByte, - Parameter::WasmWriteMemoryBase, - Parameter::WasmWriteMemoryByte, - Parameter::WasmReadRegisterBase, - Parameter::WasmReadRegisterByte, - Parameter::WasmWriteRegisterBase, - Parameter::WasmWriteRegisterByte, - Parameter::WasmUtf8DecodingBase, - Parameter::WasmUtf8DecodingByte, - Parameter::WasmUtf16DecodingBase, - Parameter::WasmUtf16DecodingByte, - Parameter::WasmSha256Base, - Parameter::WasmSha256Byte, - Parameter::WasmKeccak256Base, - Parameter::WasmKeccak256Byte, - Parameter::WasmKeccak512Base, - Parameter::WasmKeccak512Byte, - Parameter::WasmRipemd160Base, - Parameter::WasmRipemd160Block, - Parameter::WasmEcrecoverBase, - Parameter::WasmEd25519VerifyBase, - Parameter::WasmEd25519VerifyByte, - Parameter::WasmLogBase, - Parameter::WasmLogByte, - Parameter::WasmStorageWriteBase, - Parameter::WasmStorageWriteKeyByte, - Parameter::WasmStorageWriteValueByte, - Parameter::WasmStorageWriteEvictedByte, - Parameter::WasmStorageReadBase, - Parameter::WasmStorageReadKeyByte, - Parameter::WasmStorageReadValueByte, - Parameter::WasmStorageRemoveBase, - Parameter::WasmStorageRemoveKeyByte, - Parameter::WasmStorageRemoveRetValueByte, - Parameter::WasmStorageHasKeyBase, - Parameter::WasmStorageHasKeyByte, - Parameter::WasmStorageIterCreatePrefixBase, - Parameter::WasmStorageIterCreatePrefixByte, - Parameter::WasmStorageIterCreateRangeBase, - Parameter::WasmStorageIterCreateFromByte, - Parameter::WasmStorageIterCreateToByte, - Parameter::WasmStorageIterNextBase, - Parameter::WasmStorageIterNextKeyByte, - Parameter::WasmStorageIterNextValueByte, - Parameter::WasmTouchingTrieNode, - Parameter::WasmReadCachedTrieNode, - Parameter::WasmPromiseAndBase, - Parameter::WasmPromiseAndPerPromise, - Parameter::WasmPromiseReturn, - Parameter::WasmValidatorStakeBase, - Parameter::WasmValidatorTotalStakeBase, - Parameter::WasmAltBn128G1MultiexpBase, - Parameter::WasmAltBn128G1MultiexpElement, - Parameter::WasmAltBn128PairingCheckBase, - Parameter::WasmAltBn128PairingCheckElement, - Parameter::WasmAltBn128G1SumBase, - Parameter::WasmAltBn128G1SumElement, - ] - .iter() - } - /// Iterate through all parameters that define numerical limits for /// contracts that are executed in the WASM VM. pub fn vm_limits() -> slice::Iter<'static, Parameter> { diff --git a/core/primitives/res/runtime_configs/53.txt b/core/primitives/res/runtime_configs/53.txt index 1b2f0ce84f9..13bd07041f3 100644 --- a/core/primitives/res/runtime_configs/53.txt +++ b/core/primitives/res/runtime_configs/53.txt @@ -1,5 +1,4 @@ action_deploy_contract_per_byte_execution: 6_812_999 -> 64_572_944 -wasm_read_cached_trie_node: 2_280_000_000 wasmer2_stack_limit: 204_800 max_length_storage_key: 4_194_304 -> 2_048 max_locals_per_contract: 1_000_000 diff --git a/core/primitives/res/runtime_configs/parameters.txt b/core/primitives/res/runtime_configs/parameters.txt index ceeb3ac3333..c4ab8633ab6 100644 --- a/core/primitives/res/runtime_configs/parameters.txt +++ b/core/primitives/res/runtime_configs/parameters.txt @@ -119,6 +119,7 @@ wasm_storage_iter_next_base: 0 wasm_storage_iter_next_key_byte: 0 wasm_storage_iter_next_value_byte: 0 wasm_touching_trie_node: 16_101_955_926 +wasm_read_cached_trie_node: 2_280_000_000 wasm_promise_and_base: 1_465_013_400 wasm_promise_and_per_promise: 5_452_176 wasm_promise_return: 560_152_386 diff --git a/core/primitives/res/runtime_configs/parameters_testnet.txt b/core/primitives/res/runtime_configs/parameters_testnet.txt index 0cad1863c3b..158cce82351 100644 --- a/core/primitives/res/runtime_configs/parameters_testnet.txt +++ b/core/primitives/res/runtime_configs/parameters_testnet.txt @@ -115,6 +115,7 @@ wasm_storage_iter_next_base: 0 wasm_storage_iter_next_key_byte: 0 wasm_storage_iter_next_value_byte: 0 wasm_touching_trie_node: 16_101_955_926 +wasm_read_cached_trie_node: 2_280_000_000 wasm_promise_and_base: 1_465_013_400 wasm_promise_and_per_promise: 5_452_176 wasm_promise_return: 560_152_386 diff --git a/core/primitives/src/runtime/config_store.rs b/core/primitives/src/runtime/config_store.rs index 7b337c82eba..46bdc750095 100644 --- a/core/primitives/src/runtime/config_store.rs +++ b/core/primitives/src/runtime/config_store.rs @@ -109,7 +109,7 @@ mod tests { use crate::version::ProtocolFeature::{ LowerDataReceiptAndEcrecoverBaseCost, LowerStorageCost, LowerStorageKeyLimit, }; - use near_primitives_core::config::ActionCosts; + use near_primitives_core::config::{ActionCosts, ExtCosts}; const GENESIS_PROTOCOL_VERSION: ProtocolVersion = 29; const RECEIPTS_DEPTH: u64 = 63; @@ -212,8 +212,8 @@ mod tests { let base_cfg = store.get_config(LowerStorageCost.protocol_version()); let new_cfg = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version()); assert!( - base_cfg.wasm_config.ext_costs.ecrecover_base - > new_cfg.wasm_config.ext_costs.ecrecover_base + base_cfg.wasm_config.ext_costs.cost(ExtCosts::ecrecover_base) + > new_cfg.wasm_config.ext_costs.cost(ExtCosts::ecrecover_base) ); } diff --git a/core/primitives/src/runtime/parameter_table.rs b/core/primitives/src/runtime/parameter_table.rs index 50372ed6fff..d040df0d4be 100644 --- a/core/primitives/src/runtime/parameter_table.rs +++ b/core/primitives/src/runtime/parameter_table.rs @@ -1,5 +1,5 @@ use super::config::{AccountCreationConfig, RuntimeConfig}; -use near_primitives_core::config::VMConfig; +use near_primitives_core::config::{ExtCostsConfig, VMConfig}; use near_primitives_core::parameter::{FeeParameter, Parameter}; use near_primitives_core::runtime::fees::{RuntimeFeesConfig, StorageUsageConfig}; use num_rational::Rational; @@ -81,8 +81,11 @@ impl TryFrom<&ParameterTable> for RuntimeConfig { }, }, wasm_config: VMConfig { - ext_costs: serde_json::from_value(params.json_map(Parameter::ext_costs(), "wasm_")) - .map_err(InvalidConfigError::WrongStructure)?, + ext_costs: ExtCostsConfig { + costs: enum_map::enum_map! { + cost => params.get_parsed(cost.param())? + }, + }, grow_mem_cost: params.get_parsed(Parameter::WasmGrowMemCost)?, regular_op_cost: params.get_parsed(Parameter::WasmRegularOpCost)?, limit_config: serde_json::from_value(params.json_map(Parameter::vm_limits(), "")) diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index 60376d0e8d6..c9298015980 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use borsh::{BorshDeserialize, BorshSerialize}; use chrono::DateTime; -use near_primitives_core::config::{ActionCosts, VMConfig}; +use near_primitives_core::config::{ActionCosts, ExtCosts, VMConfig}; use near_primitives_core::runtime::fees::Fee; use num_rational::Rational; use serde::{Deserialize, Serialize}; @@ -1977,10 +1977,7 @@ pub struct RuntimeConfigView { /// processing transaction and receipts. pub transaction_costs: RuntimeFeesConfigView, /// Config of wasm operations. - /// - /// TODO: This should be refactored to `VMConfigView` to detach the config - /// format from RPC output. - pub wasm_config: VMConfig, + pub wasm_config: VMConfigView, /// Config that defines rules for account creation. pub account_creation_config: AccountCreationConfigView, } @@ -2139,7 +2136,7 @@ impl From for RuntimeConfigView { .fees .pessimistic_gas_price_inflation_ratio, }, - wasm_config: config.wasm_config, + wasm_config: VMConfigView::from(config.wasm_config), account_creation_config: AccountCreationConfigView { min_allowed_top_level_account_length: config .account_creation_config @@ -2189,7 +2186,7 @@ impl From for RuntimeConfig { }, }, - wasm_config: config.wasm_config, + wasm_config: VMConfig::from(config.wasm_config), account_creation_config: crate::runtime::config::AccountCreationConfig { min_allowed_top_level_account_length: config .account_creation_config @@ -2199,3 +2196,349 @@ impl From for RuntimeConfig { } } } + +#[derive(Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq)] +pub struct VMConfigView { + /// Costs for runtime externals + pub ext_costs: ExtCostsConfigView, + + /// Gas cost of a growing memory by single page. + pub grow_mem_cost: u32, + /// Gas cost of a regular operation. + pub regular_op_cost: u32, + + /// Describes limits for VM and Runtime. + /// + /// TODO: Consider changing this to `VMLimitConfigView` to avoid dependency + /// on runtime. + pub limit_config: near_primitives_core::config::VMLimitConfig, +} + +impl From for VMConfigView { + fn from(config: VMConfig) -> Self { + Self { + ext_costs: ExtCostsConfigView::from(config.ext_costs), + grow_mem_cost: config.grow_mem_cost, + regular_op_cost: config.regular_op_cost, + limit_config: config.limit_config, + } + } +} + +impl From for VMConfig { + fn from(view: VMConfigView) -> Self { + Self { + ext_costs: near_primitives_core::config::ExtCostsConfig::from(view.ext_costs), + grow_mem_cost: view.grow_mem_cost, + regular_op_cost: view.regular_op_cost, + limit_config: view.limit_config, + } + } +} + +/// Typed view of ExtCostsConfig t preserve JSON output field names in protocol +/// config RPC output. +#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)] +pub struct ExtCostsConfigView { + /// Base cost for calling a host function. + pub base: Gas, + + /// Base cost of loading a pre-compiled contract + pub contract_loading_base: Gas, + /// Cost per byte of loading a pre-compiled contract + pub contract_loading_bytes: Gas, + + /// Base cost for guest memory read + pub read_memory_base: Gas, + /// Cost for guest memory read + pub read_memory_byte: Gas, + + /// Base cost for guest memory write + pub write_memory_base: Gas, + /// Cost for guest memory write per byte + pub write_memory_byte: Gas, + + /// Base cost for reading from register + pub read_register_base: Gas, + /// Cost for reading byte from register + pub read_register_byte: Gas, + + /// Base cost for writing into register + pub write_register_base: Gas, + /// Cost for writing byte into register + pub write_register_byte: Gas, + + /// Base cost of decoding utf8. It's used for `log_utf8` and `panic_utf8`. + pub utf8_decoding_base: Gas, + /// Cost per byte of decoding utf8. It's used for `log_utf8` and `panic_utf8`. + pub utf8_decoding_byte: Gas, + + /// Base cost of decoding utf16. It's used for `log_utf16`. + pub utf16_decoding_base: Gas, + /// Cost per byte of decoding utf16. It's used for `log_utf16`. + pub utf16_decoding_byte: Gas, + + /// Cost of getting sha256 base + pub sha256_base: Gas, + /// Cost of getting sha256 per byte + pub sha256_byte: Gas, + + /// Cost of getting sha256 base + pub keccak256_base: Gas, + /// Cost of getting sha256 per byte + pub keccak256_byte: Gas, + + /// Cost of getting sha256 base + pub keccak512_base: Gas, + /// Cost of getting sha256 per byte + pub keccak512_byte: Gas, + + /// Cost of getting ripemd160 base + pub ripemd160_base: Gas, + /// Cost of getting ripemd160 per message block + pub ripemd160_block: Gas, + + /// Cost of getting ed25519 base + #[cfg(feature = "protocol_feature_ed25519_verify")] + pub ed25519_verify_base: Gas, + /// Cost of getting ed25519 per byte + #[cfg(feature = "protocol_feature_ed25519_verify")] + pub ed25519_verify_byte: Gas, + + /// Cost of calling ecrecover + pub ecrecover_base: Gas, + + /// Cost for calling logging. + pub log_base: Gas, + /// Cost for logging per byte + pub log_byte: Gas, + + // ############### + // # Storage API # + // ############### + /// Storage trie write key base cost + pub storage_write_base: Gas, + /// Storage trie write key per byte cost + pub storage_write_key_byte: Gas, + /// Storage trie write value per byte cost + pub storage_write_value_byte: Gas, + /// Storage trie write cost per byte of evicted value. + pub storage_write_evicted_byte: Gas, + + /// Storage trie read key base cost + pub storage_read_base: Gas, + /// Storage trie read key per byte cost + pub storage_read_key_byte: Gas, + /// Storage trie read value cost per byte cost + pub storage_read_value_byte: Gas, + + /// Remove key from trie base cost + pub storage_remove_base: Gas, + /// Remove key from trie per byte cost + pub storage_remove_key_byte: Gas, + /// Remove key from trie ret value byte cost + pub storage_remove_ret_value_byte: Gas, + + /// Storage trie check for key existence cost base + pub storage_has_key_base: Gas, + /// Storage trie check for key existence per key byte + pub storage_has_key_byte: Gas, + + /// Create trie prefix iterator cost base + pub storage_iter_create_prefix_base: Gas, + /// Create trie prefix iterator cost per byte. + pub storage_iter_create_prefix_byte: Gas, + + /// Create trie range iterator cost base + pub storage_iter_create_range_base: Gas, + /// Create trie range iterator cost per byte of from key. + pub storage_iter_create_from_byte: Gas, + /// Create trie range iterator cost per byte of to key. + pub storage_iter_create_to_byte: Gas, + + /// Trie iterator per key base cost + pub storage_iter_next_base: Gas, + /// Trie iterator next key byte cost + pub storage_iter_next_key_byte: Gas, + /// Trie iterator next key byte cost + pub storage_iter_next_value_byte: Gas, + + /// Cost per reading trie node from DB + pub touching_trie_node: Gas, + /// Cost for reading trie node from memory + pub read_cached_trie_node: Gas, + + // ############### + // # Promise API # + // ############### + /// Cost for calling `promise_and` + pub promise_and_base: Gas, + /// Cost for calling `promise_and` for each promise + pub promise_and_per_promise: Gas, + /// Cost for calling `promise_return` + pub promise_return: Gas, + + // ############### + // # Validator API # + // ############### + /// Cost of calling `validator_stake`. + pub validator_stake_base: Gas, + /// Cost of calling `validator_total_stake`. + pub validator_total_stake_base: Gas, + + // Removed parameters, only here for keeping the output backward-compatible. + pub contract_compile_base: Gas, + pub contract_compile_bytes: Gas, + + // ############# + // # Alt BN128 # + // ############# + /// Base cost for multiexp + pub alt_bn128_g1_multiexp_base: Gas, + /// Per element cost for multiexp + pub alt_bn128_g1_multiexp_element: Gas, + /// Base cost for sum + pub alt_bn128_g1_sum_base: Gas, + /// Per element cost for sum + pub alt_bn128_g1_sum_element: Gas, + /// Base cost for pairing check + pub alt_bn128_pairing_check_base: Gas, + /// Per element cost for pairing check + pub alt_bn128_pairing_check_element: Gas, +} + +impl From for ExtCostsConfigView { + fn from(config: near_primitives_core::config::ExtCostsConfig) -> Self { + Self { + base: config.cost(ExtCosts::base), + contract_loading_base: config.cost(ExtCosts::contract_loading_base), + contract_loading_bytes: config.cost(ExtCosts::contract_loading_bytes), + read_memory_base: config.cost(ExtCosts::read_memory_base), + read_memory_byte: config.cost(ExtCosts::read_memory_byte), + write_memory_base: config.cost(ExtCosts::write_memory_base), + write_memory_byte: config.cost(ExtCosts::write_memory_byte), + read_register_base: config.cost(ExtCosts::read_register_base), + read_register_byte: config.cost(ExtCosts::read_register_byte), + write_register_base: config.cost(ExtCosts::write_register_base), + write_register_byte: config.cost(ExtCosts::write_register_byte), + utf8_decoding_base: config.cost(ExtCosts::utf8_decoding_base), + utf8_decoding_byte: config.cost(ExtCosts::utf8_decoding_byte), + utf16_decoding_base: config.cost(ExtCosts::utf16_decoding_base), + utf16_decoding_byte: config.cost(ExtCosts::utf16_decoding_byte), + sha256_base: config.cost(ExtCosts::sha256_base), + sha256_byte: config.cost(ExtCosts::sha256_byte), + keccak256_base: config.cost(ExtCosts::keccak256_base), + keccak256_byte: config.cost(ExtCosts::keccak256_byte), + keccak512_base: config.cost(ExtCosts::keccak512_base), + keccak512_byte: config.cost(ExtCosts::keccak512_byte), + ripemd160_base: config.cost(ExtCosts::ripemd160_base), + ripemd160_block: config.cost(ExtCosts::ripemd160_block), + ecrecover_base: config.cost(ExtCosts::ecrecover_base), + log_base: config.cost(ExtCosts::log_base), + log_byte: config.cost(ExtCosts::log_byte), + storage_write_base: config.cost(ExtCosts::storage_write_base), + storage_write_key_byte: config.cost(ExtCosts::storage_write_key_byte), + storage_write_value_byte: config.cost(ExtCosts::storage_write_value_byte), + storage_write_evicted_byte: config.cost(ExtCosts::storage_write_evicted_byte), + storage_read_base: config.cost(ExtCosts::storage_read_base), + storage_read_key_byte: config.cost(ExtCosts::storage_read_key_byte), + storage_read_value_byte: config.cost(ExtCosts::storage_read_value_byte), + storage_remove_base: config.cost(ExtCosts::storage_remove_base), + storage_remove_key_byte: config.cost(ExtCosts::storage_remove_key_byte), + storage_remove_ret_value_byte: config.cost(ExtCosts::storage_remove_ret_value_byte), + storage_has_key_base: config.cost(ExtCosts::storage_has_key_base), + storage_has_key_byte: config.cost(ExtCosts::storage_has_key_byte), + storage_iter_create_prefix_base: config.cost(ExtCosts::storage_iter_create_prefix_base), + storage_iter_create_prefix_byte: config.cost(ExtCosts::storage_iter_create_prefix_byte), + storage_iter_create_range_base: config.cost(ExtCosts::storage_iter_create_range_base), + storage_iter_create_from_byte: config.cost(ExtCosts::storage_iter_create_from_byte), + storage_iter_create_to_byte: config.cost(ExtCosts::storage_iter_create_to_byte), + storage_iter_next_base: config.cost(ExtCosts::storage_iter_next_base), + storage_iter_next_key_byte: config.cost(ExtCosts::storage_iter_next_key_byte), + storage_iter_next_value_byte: config.cost(ExtCosts::storage_iter_next_value_byte), + touching_trie_node: config.cost(ExtCosts::touching_trie_node), + read_cached_trie_node: config.cost(ExtCosts::read_cached_trie_node), + promise_and_base: config.cost(ExtCosts::promise_and_base), + promise_and_per_promise: config.cost(ExtCosts::promise_and_per_promise), + promise_return: config.cost(ExtCosts::promise_return), + validator_stake_base: config.cost(ExtCosts::validator_stake_base), + validator_total_stake_base: config.cost(ExtCosts::validator_total_stake_base), + alt_bn128_g1_multiexp_base: config.cost(ExtCosts::alt_bn128_g1_multiexp_base), + alt_bn128_g1_multiexp_element: config.cost(ExtCosts::alt_bn128_g1_multiexp_element), + alt_bn128_g1_sum_base: config.cost(ExtCosts::alt_bn128_g1_sum_base), + alt_bn128_g1_sum_element: config.cost(ExtCosts::alt_bn128_g1_sum_element), + alt_bn128_pairing_check_base: config.cost(ExtCosts::alt_bn128_pairing_check_base), + alt_bn128_pairing_check_element: config.cost(ExtCosts::alt_bn128_pairing_check_element), + // removed parameters + contract_compile_base: 0, + contract_compile_bytes: 0, + } + } +} + +impl From for near_primitives_core::config::ExtCostsConfig { + fn from(view: ExtCostsConfigView) -> Self { + let costs = enum_map::enum_map! { + ExtCosts::base => view.base, + ExtCosts::contract_loading_base => view.contract_loading_base, + ExtCosts::contract_loading_bytes => view.contract_loading_bytes, + ExtCosts::read_memory_base => view.read_memory_base, + ExtCosts::read_memory_byte => view.read_memory_byte, + ExtCosts::write_memory_base => view.write_memory_base, + ExtCosts::write_memory_byte => view.write_memory_byte, + ExtCosts::read_register_base => view.read_register_base, + ExtCosts::read_register_byte => view.read_register_byte, + ExtCosts::write_register_base => view.write_register_base, + ExtCosts::write_register_byte => view.write_register_byte, + ExtCosts::utf8_decoding_base => view.utf8_decoding_base, + ExtCosts::utf8_decoding_byte => view.utf8_decoding_byte, + ExtCosts::utf16_decoding_base => view.utf16_decoding_base, + ExtCosts::utf16_decoding_byte => view.utf16_decoding_byte, + ExtCosts::sha256_base => view.sha256_base, + ExtCosts::sha256_byte => view.sha256_byte, + ExtCosts::keccak256_base => view.keccak256_base, + ExtCosts::keccak256_byte => view.keccak256_byte, + ExtCosts::keccak512_base => view.keccak512_base, + ExtCosts::keccak512_byte => view.keccak512_byte, + ExtCosts::ripemd160_base => view.ripemd160_base, + ExtCosts::ripemd160_block => view.ripemd160_block, + ExtCosts::ecrecover_base => view.ecrecover_base, + ExtCosts::log_base => view.log_base, + ExtCosts::log_byte => view.log_byte, + ExtCosts::storage_write_base => view.storage_write_base, + ExtCosts::storage_write_key_byte => view.storage_write_key_byte, + ExtCosts::storage_write_value_byte => view.storage_write_value_byte, + ExtCosts::storage_write_evicted_byte => view.storage_write_evicted_byte, + ExtCosts::storage_read_base => view.storage_read_base, + ExtCosts::storage_read_key_byte => view.storage_read_key_byte, + ExtCosts::storage_read_value_byte => view.storage_read_value_byte, + ExtCosts::storage_remove_base => view.storage_remove_base, + ExtCosts::storage_remove_key_byte => view.storage_remove_key_byte, + ExtCosts::storage_remove_ret_value_byte => view.storage_remove_ret_value_byte, + ExtCosts::storage_has_key_base => view.storage_has_key_base, + ExtCosts::storage_has_key_byte => view.storage_has_key_byte, + ExtCosts::storage_iter_create_prefix_base => view.storage_iter_create_prefix_base, + ExtCosts::storage_iter_create_prefix_byte => view.storage_iter_create_prefix_byte, + ExtCosts::storage_iter_create_range_base => view.storage_iter_create_range_base, + ExtCosts::storage_iter_create_from_byte => view.storage_iter_create_from_byte, + ExtCosts::storage_iter_create_to_byte => view.storage_iter_create_to_byte, + ExtCosts::storage_iter_next_base => view.storage_iter_next_base, + ExtCosts::storage_iter_next_key_byte => view.storage_iter_next_key_byte, + ExtCosts::storage_iter_next_value_byte => view.storage_iter_next_value_byte, + ExtCosts::touching_trie_node => view.touching_trie_node, + ExtCosts::read_cached_trie_node => view.read_cached_trie_node, + ExtCosts::promise_and_base => view.promise_and_base, + ExtCosts::promise_and_per_promise => view.promise_and_per_promise, + ExtCosts::promise_return => view.promise_return, + ExtCosts::validator_stake_base => view.validator_stake_base, + ExtCosts::validator_total_stake_base => view.validator_total_stake_base, + ExtCosts::alt_bn128_g1_multiexp_base => view.alt_bn128_g1_multiexp_base, + ExtCosts::alt_bn128_g1_multiexp_element => view.alt_bn128_g1_multiexp_element, + ExtCosts::alt_bn128_g1_sum_base => view.alt_bn128_g1_sum_base, + ExtCosts::alt_bn128_g1_sum_element => view.alt_bn128_g1_sum_element, + ExtCosts::alt_bn128_pairing_check_base => view.alt_bn128_pairing_check_base, + ExtCosts::alt_bn128_pairing_check_element => view.alt_bn128_pairing_check_element, + }; + Self { costs } + } +} diff --git a/nearcore/src/runtime/mod.rs b/nearcore/src/runtime/mod.rs index 4209f768664..63c0daf63a5 100644 --- a/nearcore/src/runtime/mod.rs +++ b/nearcore/src/runtime/mod.rs @@ -18,6 +18,7 @@ use near_o11y::log_assert; use near_pool::types::PoolIterator; use near_primitives::account::{AccessKey, Account}; use near_primitives::challenge::ChallengesResult; +use near_primitives::config::ExtCosts; use near_primitives::contract::ContractCode; use near_primitives::epoch_manager::block_info::BlockInfo; use near_primitives::epoch_manager::EpochConfig; @@ -830,8 +831,8 @@ impl RuntimeAdapter for NightshadeRuntime { // of parameters, this corresponds to about 13megs worth of // transactions. let size_limit = transactions_gas_limit - / (runtime_config.wasm_config.ext_costs.storage_write_value_byte - + runtime_config.wasm_config.ext_costs.storage_read_value_byte); + / (runtime_config.wasm_config.ext_costs.cost(ExtCosts::storage_write_value_byte) + + runtime_config.wasm_config.ext_costs.cost(ExtCosts::storage_read_value_byte)); while total_gas_burnt < transactions_gas_limit && total_size < size_limit { if let Some(iter) = pool_iterator.next() { 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 3318afd4a98..91b146ab22e 100644 --- a/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs +++ b/runtime/runtime-params-estimator/src/costs_to_runtime_config.rs @@ -1,9 +1,8 @@ use near_primitives::runtime::config::AccountCreationConfig; use near_primitives::runtime::config_store::RuntimeConfigStore; use near_primitives::runtime::fees::{Fee, RuntimeFeesConfig}; -use near_primitives::types::Gas; use near_primitives::version::PROTOCOL_VERSION; -use near_vm_logic::{ActionCosts, ExtCostsConfig, VMConfig}; +use near_vm_logic::{ActionCosts, ExtCosts, ExtCostsConfig, VMConfig}; use node_runtime::config::RuntimeConfig; use anyhow::Context; @@ -76,80 +75,82 @@ fn runtime_fees_config(cost_table: &CostTable) -> anyhow::Result anyhow::Result { - let get = |cost: Cost| -> anyhow::Result { - cost_table.get(cost).with_context(|| format!("undefined cost: {}", cost)) - }; + Ok(ExtCostsConfig { + costs: enum_map::enum_map! { + // TODO: storage_iter_* operations below are deprecated, so just hardcode zero price, + // and remove those operations ASAP. + ExtCosts::storage_iter_create_prefix_base => 0, + ExtCosts::storage_iter_create_prefix_byte => 0, + ExtCosts::storage_iter_create_range_base => 0, + ExtCosts::storage_iter_create_from_byte => 0, + ExtCosts::storage_iter_create_to_byte => 0, + ExtCosts::storage_iter_next_base => 0, + ExtCosts::storage_iter_next_key_byte => 0, + ExtCosts::storage_iter_next_value_byte => 0, + // TODO: accurately price host functions that expose validator information. + ExtCosts::validator_stake_base => 303944908800, + ExtCosts::validator_total_stake_base => 303944908800, + cost => { + let estimation = estimation(cost).with_context(|| format!("external WASM cost has no estimation defined: {}", cost))?; + cost_table.get(estimation).with_context(|| format!("undefined external WASM cost: {}", cost))? + }, + }, + }) +} - let res = ExtCostsConfig { - base: get(Cost::HostFunctionCall)?, - contract_loading_base: 0, - contract_loading_bytes: 0, - read_memory_base: get(Cost::ReadMemoryBase)?, - read_memory_byte: get(Cost::ReadMemoryByte)?, - write_memory_base: get(Cost::WriteMemoryBase)?, - write_memory_byte: get(Cost::WriteMemoryByte)?, - read_register_base: get(Cost::ReadRegisterBase)?, - read_register_byte: get(Cost::ReadRegisterByte)?, - write_register_base: get(Cost::WriteRegisterBase)?, - write_register_byte: get(Cost::WriteRegisterByte)?, - utf8_decoding_base: get(Cost::Utf8DecodingBase)?, - utf8_decoding_byte: get(Cost::Utf8DecodingByte)?, - utf16_decoding_base: get(Cost::Utf16DecodingBase)?, - utf16_decoding_byte: get(Cost::Utf16DecodingByte)?, - sha256_base: get(Cost::Sha256Base)?, - sha256_byte: get(Cost::Sha256Byte)?, - keccak256_base: get(Cost::Keccak256Base)?, - keccak256_byte: get(Cost::Keccak256Byte)?, - keccak512_base: get(Cost::Keccak512Base)?, - keccak512_byte: get(Cost::Keccak512Byte)?, - ripemd160_base: get(Cost::Ripemd160Base)?, - ripemd160_block: get(Cost::Ripemd160Block)?, - ecrecover_base: get(Cost::EcrecoverBase)?, +fn estimation(cost: ExtCosts) -> Option { + Some(match cost { + ExtCosts::base => Cost::HostFunctionCall, + ExtCosts::read_memory_base => Cost::ReadMemoryBase, + ExtCosts::read_memory_byte => Cost::ReadMemoryByte, + ExtCosts::write_memory_base => Cost::WriteMemoryBase, + ExtCosts::write_memory_byte => Cost::WriteMemoryByte, + ExtCosts::read_register_base => Cost::ReadRegisterBase, + ExtCosts::read_register_byte => Cost::ReadRegisterByte, + ExtCosts::write_register_base => Cost::WriteRegisterBase, + ExtCosts::write_register_byte => Cost::WriteRegisterByte, + ExtCosts::utf8_decoding_base => Cost::Utf8DecodingBase, + ExtCosts::utf8_decoding_byte => Cost::Utf8DecodingByte, + ExtCosts::utf16_decoding_base => Cost::Utf16DecodingBase, + ExtCosts::utf16_decoding_byte => Cost::Utf16DecodingByte, + ExtCosts::sha256_base => Cost::Sha256Base, + ExtCosts::sha256_byte => Cost::Sha256Byte, + ExtCosts::keccak256_base => Cost::Keccak256Base, + ExtCosts::keccak256_byte => Cost::Keccak256Byte, + ExtCosts::keccak512_base => Cost::Keccak512Base, + ExtCosts::keccak512_byte => Cost::Keccak512Byte, + ExtCosts::ripemd160_base => Cost::Ripemd160Base, + ExtCosts::ripemd160_block => Cost::Ripemd160Block, + ExtCosts::ecrecover_base => Cost::EcrecoverBase, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_base: get(Cost::Ed25519VerifyBase)?, + ExtCosts::ed25519_verify_base => Cost::Ed25519VerifyBase, #[cfg(feature = "protocol_feature_ed25519_verify")] - ed25519_verify_byte: get(Cost::Ed25519VerifyByte)?, - log_base: get(Cost::LogBase)?, - log_byte: get(Cost::LogByte)?, - storage_write_base: get(Cost::StorageWriteBase)?, - storage_write_key_byte: get(Cost::StorageWriteKeyByte)?, - storage_write_value_byte: get(Cost::StorageWriteValueByte)?, - storage_write_evicted_byte: get(Cost::StorageWriteEvictedByte)?, - storage_read_base: get(Cost::StorageReadBase)?, - storage_read_key_byte: get(Cost::StorageReadKeyByte)?, - storage_read_value_byte: get(Cost::StorageReadValueByte)?, - storage_remove_base: get(Cost::StorageRemoveBase)?, - storage_remove_key_byte: get(Cost::StorageRemoveKeyByte)?, - storage_remove_ret_value_byte: get(Cost::StorageRemoveRetValueByte)?, - storage_has_key_base: get(Cost::StorageHasKeyBase)?, - storage_has_key_byte: get(Cost::StorageHasKeyByte)?, - // TODO: storage_iter_* operations below are deprecated, so just hardcode zero price, - // and remove those operations ASAP. - 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: get(Cost::TouchingTrieNode)?, - read_cached_trie_node: get(Cost::ReadCachedTrieNode)?, - promise_and_base: get(Cost::PromiseAndBase)?, - promise_and_per_promise: get(Cost::PromiseAndPerPromise)?, - promise_return: get(Cost::PromiseReturn)?, - // TODO: accurately price host functions that expose validator information. - validator_stake_base: 303944908800, - validator_total_stake_base: 303944908800, - _unused1: 0, - _unused2: 0, - alt_bn128_g1_sum_base: get(Cost::AltBn128G1SumBase)?, - alt_bn128_g1_sum_element: get(Cost::AltBn128G1SumElement)?, - alt_bn128_g1_multiexp_base: get(Cost::AltBn128G1MultiexpBase)?, - alt_bn128_g1_multiexp_element: get(Cost::AltBn128G1MultiexpElement)?, - alt_bn128_pairing_check_base: get(Cost::AltBn128PairingCheckBase)?, - alt_bn128_pairing_check_element: get(Cost::AltBn128PairingCheckElement)?, - }; - - Ok(res) + ExtCosts::ed25519_verify_byte => Cost::Ed25519VerifyByte, + ExtCosts::log_base => Cost::LogBase, + ExtCosts::log_byte => Cost::LogByte, + ExtCosts::storage_write_base => Cost::StorageWriteBase, + ExtCosts::storage_write_key_byte => Cost::StorageWriteKeyByte, + ExtCosts::storage_write_value_byte => Cost::StorageWriteValueByte, + ExtCosts::storage_write_evicted_byte => Cost::StorageWriteEvictedByte, + ExtCosts::storage_read_base => Cost::StorageReadBase, + ExtCosts::storage_read_key_byte => Cost::StorageReadKeyByte, + ExtCosts::storage_read_value_byte => Cost::StorageReadValueByte, + ExtCosts::storage_remove_base => Cost::StorageRemoveBase, + ExtCosts::storage_remove_key_byte => Cost::StorageRemoveKeyByte, + ExtCosts::storage_remove_ret_value_byte => Cost::StorageRemoveRetValueByte, + ExtCosts::storage_has_key_base => Cost::StorageHasKeyBase, + ExtCosts::storage_has_key_byte => Cost::StorageHasKeyByte, + ExtCosts::touching_trie_node => Cost::TouchingTrieNode, + ExtCosts::read_cached_trie_node => Cost::ReadCachedTrieNode, + ExtCosts::promise_and_base => Cost::PromiseAndBase, + ExtCosts::promise_and_per_promise => Cost::PromiseAndPerPromise, + ExtCosts::promise_return => Cost::PromiseReturn, + ExtCosts::alt_bn128_g1_sum_base => Cost::AltBn128G1SumBase, + ExtCosts::alt_bn128_g1_sum_element => Cost::AltBn128G1SumElement, + ExtCosts::alt_bn128_g1_multiexp_base => Cost::AltBn128G1MultiexpBase, + ExtCosts::alt_bn128_g1_multiexp_element => Cost::AltBn128G1MultiexpElement, + ExtCosts::alt_bn128_pairing_check_base => Cost::AltBn128PairingCheckBase, + ExtCosts::alt_bn128_pairing_check_element => Cost::AltBn128PairingCheckElement, + _ => return None, + }) } From ca6a6321ae73ff620fc062275eaa079f8a1149f0 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 24 Nov 2022 16:09:05 +0100 Subject: [PATCH 2/4] update integration tests --- integration-tests/src/tests/client/process_blocks.rs | 6 +++--- integration-tests/src/tests/runtime/sanity_checks.rs | 4 +++- integration-tests/src/tests/standard_cases/mod.rs | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index b9e5508e155..9c2e06a940b 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -9,7 +9,7 @@ use assert_matches::assert_matches; use futures::{future, FutureExt}; use near_chain::test_utils::ValidatorSchedule; use near_chunks::test_utils::MockClientAdapterForShardsManager; -use near_primitives::config::ActionCosts; +use near_primitives::config::{ActionCosts, ExtCosts}; use near_primitives::num_rational::{Ratio, Rational32}; use near_actix_test_utils::run_actix; @@ -2657,13 +2657,13 @@ fn test_execution_metadata() { { "cost_category": "WASM_HOST_COST", "cost": "BASE", - "gas_used": config.wasm_config.ext_costs.base.to_string() + "gas_used": config.wasm_config.ext_costs.cost(ExtCosts::base).to_string() }, // We include compilation costs into running the function. { "cost_category": "WASM_HOST_COST", "cost": "CONTRACT_LOADING_BASE", - "gas_used": config.wasm_config.ext_costs.contract_loading_base.to_string() + "gas_used": config.wasm_config.ext_costs.cost(ExtCosts::contract_loading_base).to_string() }, { "cost_category": "WASM_HOST_COST", diff --git a/integration-tests/src/tests/runtime/sanity_checks.rs b/integration-tests/src/tests/runtime/sanity_checks.rs index 56c036f0dcd..e1b30bfd1aa 100644 --- a/integration-tests/src/tests/runtime/sanity_checks.rs +++ b/integration-tests/src/tests/runtime/sanity_checks.rs @@ -1,5 +1,6 @@ use crate::node::{Node, RuntimeNode}; use near_chain_configs::Genesis; +use near_primitives::config::ExtCosts; use near_primitives::runtime::config::RuntimeConfig; use near_primitives::runtime::config_store::RuntimeConfigStore; use near_primitives::serialize::to_base64; @@ -233,7 +234,8 @@ fn test_sanity_used_gas() { // Executing `used_gas` costs `base_cost`. When executing `used_gas` twice // within a metered block, the returned values should differ by that amount. - let base_cost = node.client.read().unwrap().runtime_config.wasm_config.ext_costs.base; + let base_cost = + node.client.read().unwrap().runtime_config.wasm_config.ext_costs.cost(ExtCosts::base); assert_eq!(used_gas[1] - used_gas[0], base_cost); // The fees for executing a metered block's WASM code should be paid before diff --git a/integration-tests/src/tests/standard_cases/mod.rs b/integration-tests/src/tests/standard_cases/mod.rs index 3d54381d98c..314751fb02e 100644 --- a/integration-tests/src/tests/standard_cases/mod.rs +++ b/integration-tests/src/tests/standard_cases/mod.rs @@ -7,7 +7,7 @@ use assert_matches::assert_matches; use near_crypto::{InMemorySigner, KeyType}; use near_jsonrpc_primitives::errors::ServerError; use near_primitives::account::{AccessKey, AccessKeyPermission, FunctionCallPermission}; -use near_primitives::config::ActionCosts; +use near_primitives::config::{ActionCosts, ExtCosts}; use near_primitives::errors::{ ActionError, ActionErrorKind, InvalidAccessKeyError, InvalidTxError, TxExecutionError, }; @@ -1347,12 +1347,12 @@ fn get_trie_nodes_count( for cost in metadata.gas_profile.clone().unwrap_or_default().iter() { match cost.cost.as_str() { "TOUCHING_TRIE_NODE" => { - count.db_reads += - cost.gas_used / runtime_config.wasm_config.ext_costs.touching_trie_node; + count.db_reads += cost.gas_used + / runtime_config.wasm_config.ext_costs.cost(ExtCosts::touching_trie_node); } "READ_CACHED_TRIE_NODE" => { - count.mem_reads += - cost.gas_used / runtime_config.wasm_config.ext_costs.read_cached_trie_node; + count.mem_reads += cost.gas_used + / runtime_config.wasm_config.ext_costs.cost(ExtCosts::read_cached_trie_node); } _ => {} }; From e4b96e416e9dbbd376c30f41800a302efaf46bd3 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 24 Nov 2022 16:20:31 +0100 Subject: [PATCH 3/4] fix nightly --- core/primitives/src/views.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index c9298015980..614489e7a6f 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -2433,6 +2433,10 @@ impl From for ExtCostsConfigView { keccak512_byte: config.cost(ExtCosts::keccak512_byte), ripemd160_base: config.cost(ExtCosts::ripemd160_base), ripemd160_block: config.cost(ExtCosts::ripemd160_block), + #[cfg(feature = "protocol_feature_ed25519_verify")] + ed25519_verify_base: config.cost(ExtCosts::ed25519_verify_base), + #[cfg(feature = "protocol_feature_ed25519_verify")] + ed25519_verify_byte: config.cost(ExtCosts::ed25519_verify_byte), ecrecover_base: config.cost(ExtCosts::ecrecover_base), log_base: config.cost(ExtCosts::log_base), log_byte: config.cost(ExtCosts::log_byte), @@ -2502,6 +2506,10 @@ impl From for near_primitives_core::config::ExtCostsConfig { ExtCosts::keccak512_byte => view.keccak512_byte, ExtCosts::ripemd160_base => view.ripemd160_base, ExtCosts::ripemd160_block => view.ripemd160_block, + #[cfg(feature = "protocol_feature_ed25519_verify")] + ExtCosts::ed25519_verify_base => view.ed25519_verify_base, + #[cfg(feature = "protocol_feature_ed25519_verify")] + ExtCosts::ed25519_verify_byte => view.ed25519_verify_byte, ExtCosts::ecrecover_base => view.ecrecover_base, ExtCosts::log_base => view.log_base, ExtCosts::log_byte => view.log_byte, From 0228681233ed182c0c4fe0ff88fd1727be6343d5 Mon Sep 17 00:00:00 2001 From: jakob Date: Wed, 7 Dec 2022 09:29:47 +0100 Subject: [PATCH 4/4] remove unnecessary `EnumCount` derives --- core/primitives-core/src/config.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/primitives-core/src/config.rs b/core/primitives-core/src/config.rs index 358b7538d16..25cba9c1299 100644 --- a/core/primitives-core/src/config.rs +++ b/core/primitives-core/src/config.rs @@ -5,7 +5,7 @@ use enum_map::{enum_map, EnumMap}; use serde::{Deserialize, Serialize}; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; -use strum::{Display, EnumCount}; +use strum::Display; /// Dynamic configuration parameters required for the WASM runtime to /// execute a smart contract. @@ -362,7 +362,6 @@ impl ExtCostsConfig { Debug, PartialOrd, Ord, - EnumCount, Display, strum::EnumIter, enum_map::Enum, @@ -444,7 +443,6 @@ pub enum ExtCosts { Debug, PartialOrd, Ord, - EnumCount, Display, strum::EnumIter, enum_map::Enum,