Skip to content

Commit

Permalink
[protocol_change] Decrease function call base cost
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev authored and VanBarbascu committed Apr 8, 2024
1 parent 52e24e4 commit 5f3d356
Show file tree
Hide file tree
Showing 22 changed files with 610 additions and 95 deletions.
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"CwaiZ4AmfJSnMN9rytYwwYHCTzLioC5xcjHzNkDex1HH");
} else {
insta::assert_snapshot!(hash, @"7MsX2sMzdFrbjw8iCsA9mvSS8eA1fjokx6LbuBvd4cmH");
insta::assert_snapshot!(hash, @"CxmRfDBCbukRuksZMKEwHe6o8zqc2eZFsXmbQvPygwYi");
}

for i in 1..5 {
Expand Down Expand Up @@ -84,7 +84,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"Dn18HUFm149fojXpwV1dYCfjdPh56S1k233kp7vmnFeE");
} else {
insta::assert_snapshot!(hash, @"6y8xg9TLmSR7Q66a5Vfy2iR1gp4t8psPMAPzTwA3E6Lg");
insta::assert_snapshot!(hash, @"6tqFaqvsAjrtkuPfnuXz2pJ1VPt1kvF95hVJR7x9JhXG");
}
}

Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc/jsonrpc-tests/res/genesis_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@
],
"use_production_config": false,
"records": []
}
}
18 changes: 18 additions & 0 deletions core/parameters/res/runtime_configs/66.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# These changes aim to increase the capacity of network when executing function calls for small
# smart contracts while still preserving the same gas costs for the largest smart contracts (4MB).
action_function_call: {
old: {
send_sir: 2_319_861_500_000,
send_not_sir: 2_319_861_500_000,
execution: 2_319_861_500_000,
},
new: {
send_sir: 200_000_000_000,
send_not_sir: 200_000_000_000,
execution: 780_000_000_000,
}
}
wasm_contract_loading_bytes: {
old: 216_750,
new: 1_089_295,
}
8 changes: 4 additions & 4 deletions core/parameters/res/runtime_configs/parameters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ action_deploy_contract_per_byte
- send_not_sir: 6_812_999
- execution: 64_572_944
action_function_call
- send_sir: 2_319_861_500_000
- send_not_sir: 2_319_861_500_000
- execution: 2_319_861_500_000
- send_sir: 200_000_000_000
- send_not_sir: 200_000_000_000
- execution: 780_000_000_000
action_function_call_per_byte
- send_sir: 2_235_934
- send_not_sir: 2_235_934
Expand Down Expand Up @@ -77,7 +77,7 @@ wasm_regular_op_cost 822_756
wasm_grow_mem_cost 1
wasm_base 264_768_111
wasm_contract_loading_base 35_445_963
wasm_contract_loading_bytes 216_750
wasm_contract_loading_bytes 1_089_295
wasm_read_memory_base 2_609_863_200
wasm_read_memory_byte 3_801_333
wasm_write_memory_base 2_803_794_861
Expand Down
12 changes: 8 additions & 4 deletions core/parameters/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
(62, include_config!("62.yaml")),
(63, include_config!("63.yaml")),
(64, include_config!("64.yaml")),
(129, include_config!("129.yaml")),
// Introduce ETH-implicit accounts.
(138, include_config!("138.yaml")),
(66, include_config!("66.yaml")),
];

/// Testnet parameters for versions <= 29, which (incorrectly) differed from mainnet parameters
Expand Down Expand Up @@ -155,7 +153,8 @@ mod tests {
use super::*;
use crate::cost::{ActionCosts, ExtCosts};
use near_primitives_core::version::ProtocolFeature::{
LowerDataReceiptAndEcrecoverBaseCost, LowerStorageCost, LowerStorageKeyLimit,
DecreaseFunctionCallBaseCost, LowerDataReceiptAndEcrecoverBaseCost, LowerStorageCost,
LowerStorageKeyLimit,
};
use std::collections::HashSet;

Expand Down Expand Up @@ -194,6 +193,11 @@ mod tests {
fn test_max_prepaid_gas() {
let store = RuntimeConfigStore::new(None);
for (protocol_version, config) in store.store.iter() {
if *protocol_version >= DecreaseFunctionCallBaseCost.protocol_version() {
continue;
}

// TODO(#10955): Enforce the depth limit directly, regardless of the gas costs.
assert!(
config.wasm_config.limit_config.max_total_prepaid_gas
/ config.fees.min_receipt_with_function_call_gas()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ expression: config_view
"execution": 64572944
},
"function_call_cost": {
"send_sir": 2319861500000,
"send_not_sir": 2319861500000,
"execution": 2319861500000
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 780000000000
},
"function_call_cost_per_byte": {
"send_sir": 2235934,
Expand Down Expand Up @@ -108,7 +108,7 @@ expression: config_view
"ext_costs": {
"base": 264768111,
"contract_loading_base": 35445963,
"contract_loading_bytes": 216750,
"contract_loading_bytes": 1089295,
"read_memory_base": 2609863200,
"read_memory_byte": 3801333,
"write_memory_base": 2803794861,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ expression: config_view
"execution": 64572944
},
"function_call_cost": {
"send_sir": 2319861500000,
"send_not_sir": 2319861500000,
"execution": 2319861500000
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 780000000000
},
"function_call_cost_per_byte": {
"send_sir": 2235934,
Expand Down Expand Up @@ -108,7 +108,7 @@ expression: config_view
"ext_costs": {
"base": 264768111,
"contract_loading_base": 35445963,
"contract_loading_bytes": 216750,
"contract_loading_bytes": 1089295,
"read_memory_base": 2609863200,
"read_memory_byte": 3801333,
"write_memory_base": 2803794861,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
---
source: core/parameters/src/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": 200000000000,
"send_not_sir": 200000000000,
"execution": 780000000000
},
"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
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
"base": 264768111,
"contract_loading_base": 35445963,
"contract_loading_bytes": 1089295,
"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,
"yield_create_base": 300000000000000,
"yield_create_byte": 300000000000000,
"yield_resume_base": 300000000000000,
"yield_resume_byte": 300000000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
"vm_kind": "<REDACTED>",
"disable_9393_fix": false,
"storage_get_mode": "FlatStorage",
"fix_contract_loading_cost": false,
"implicit_account_creation": true,
"math_extension": true,
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"eth_implicit_accounts": false,
"yield_resume_host_functions": false,
"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,
"yield_timeout_length_in_blocks": 200,
"max_yield_payload_size": 1024
}
},
"account_creation_config": {
"min_allowed_top_level_account_length": 65,
"registrar_account_id": "registrar"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ expression: config_view
"execution": 64572944
},
"function_call_cost": {
"send_sir": 2319861500000,
"send_not_sir": 2319861500000,
"execution": 2319861500000
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 780000000000
},
"function_call_cost_per_byte": {
"send_sir": 2235934,
Expand Down Expand Up @@ -108,7 +108,7 @@ expression: config_view
"ext_costs": {
"base": 264768111,
"contract_loading_base": 35445963,
"contract_loading_bytes": 216750,
"contract_loading_bytes": 1089295,
"read_memory_base": 2609863200,
"read_memory_byte": 3801333,
"write_memory_base": 2803794861,
Expand Down
Loading

0 comments on commit 5f3d356

Please sign in to comment.