Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ExtCostsConfig as simple map of costs #8115

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
526 changes: 153 additions & 373 deletions core/primitives-core/src/config.rs

Large diffs are not rendered by default.

71 changes: 0 additions & 71 deletions core/primitives-core/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
1 change: 0 additions & 1 deletion core/primitives/res/runtime_configs/53.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions core/primitives/res/runtime_configs/parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}

Expand Down
9 changes: 6 additions & 3 deletions core/primitives/src/runtime/parameter_table.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(), ""))
Expand Down
Loading