Skip to content

Commit

Permalink
feat: gas profile by parameter (near#8148)
Browse files Browse the repository at this point in the history
This resolves near#8033, completing the gas profile by parameter effort.

The main achievement here is that we can now  look at gas profiles and
know exactly for which parameter it has been spent.

Code wise, the old `enum Cost` used in profiles only is finally gone.

The tricky parts in this PR are to make sure that old profiles stored on DB
are still understood and presented correctly in RPC calls.
  • Loading branch information
jakmeier authored and nikurt committed Jan 15, 2023
1 parent b9073bb commit b133a43
Show file tree
Hide file tree
Showing 21 changed files with 1,955 additions and 373 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
`opentelemetry-otlp`: [#7563](https://github.com/near/nearcore/pull/7563).
* Tracing of requests across processes:
[#8004](https://github.com/near/nearcore/pull/8004).
* Gas profiles as displayed in the `EXPERIMENTAL_tx_status` are now more
detailed and give the gas cost per parameter.

## 1.30.0

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ near-account-id = { path = "../account-id", features = ["arbitrary"] }

[dev-dependencies]
serde_json.workspace = true
insta.workspace = true

[features]
default = []
protocol_feature_ed25519_verify = []
nightly = ["protocol_feature_ed25519_verify"]
155 changes: 79 additions & 76 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ impl ExtCostsConfig {
}

/// Strongly-typed representation of the fees for counting.
///
/// Do not change the enum discriminants here, they are used for borsh
/// (de-)serialization.
#[derive(
Copy,
Clone,
Expand All @@ -374,69 +377,69 @@ impl ExtCostsConfig {
)]
#[allow(non_camel_case_types)]
pub enum ExtCosts {
base,
contract_loading_base,
contract_loading_bytes,
read_memory_base,
read_memory_byte,
write_memory_base,
write_memory_byte,
read_register_base,
read_register_byte,
write_register_base,
write_register_byte,
utf8_decoding_base,
utf8_decoding_byte,
utf16_decoding_base,
utf16_decoding_byte,
sha256_base,
sha256_byte,
keccak256_base,
keccak256_byte,
keccak512_base,
keccak512_byte,
ripemd160_base,
ripemd160_block,
base = 0,
contract_loading_base = 1,
contract_loading_bytes = 2,
read_memory_base = 3,
read_memory_byte = 4,
write_memory_base = 5,
write_memory_byte = 6,
read_register_base = 7,
read_register_byte = 8,
write_register_base = 9,
write_register_byte = 10,
utf8_decoding_base = 11,
utf8_decoding_byte = 12,
utf16_decoding_base = 13,
utf16_decoding_byte = 14,
sha256_base = 15,
sha256_byte = 16,
keccak256_base = 17,
keccak256_byte = 18,
keccak512_base = 19,
keccak512_byte = 20,
ripemd160_base = 21,
ripemd160_block = 22,
ecrecover_base = 23,
log_base = 24,
log_byte = 25,
storage_write_base = 26,
storage_write_key_byte = 27,
storage_write_value_byte = 28,
storage_write_evicted_byte = 29,
storage_read_base = 30,
storage_read_key_byte = 31,
storage_read_value_byte = 32,
storage_remove_base = 33,
storage_remove_key_byte = 34,
storage_remove_ret_value_byte = 35,
storage_has_key_base = 36,
storage_has_key_byte = 37,
storage_iter_create_prefix_base = 38,
storage_iter_create_prefix_byte = 39,
storage_iter_create_range_base = 40,
storage_iter_create_from_byte = 41,
storage_iter_create_to_byte = 42,
storage_iter_next_base = 43,
storage_iter_next_key_byte = 44,
storage_iter_next_value_byte = 45,
touching_trie_node = 46,
read_cached_trie_node = 47,
promise_and_base = 48,
promise_and_per_promise = 49,
promise_return = 50,
validator_stake_base = 51,
validator_total_stake_base = 52,
alt_bn128_g1_multiexp_base = 53,
alt_bn128_g1_multiexp_element = 54,
alt_bn128_pairing_check_base = 55,
alt_bn128_pairing_check_element = 56,
alt_bn128_g1_sum_base = 57,
alt_bn128_g1_sum_element = 58,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_base,
ed25519_verify_base = 59,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_byte,
ecrecover_base,
log_base,
log_byte,
storage_write_base,
storage_write_key_byte,
storage_write_value_byte,
storage_write_evicted_byte,
storage_read_base,
storage_read_key_byte,
storage_read_value_byte,
storage_remove_base,
storage_remove_key_byte,
storage_remove_ret_value_byte,
storage_has_key_base,
storage_has_key_byte,
storage_iter_create_prefix_base,
storage_iter_create_prefix_byte,
storage_iter_create_range_base,
storage_iter_create_from_byte,
storage_iter_create_to_byte,
storage_iter_next_base,
storage_iter_next_key_byte,
storage_iter_next_value_byte,
touching_trie_node,
read_cached_trie_node,
promise_and_base,
promise_and_per_promise,
promise_return,
validator_stake_base,
validator_total_stake_base,
alt_bn128_g1_multiexp_base,
alt_bn128_g1_multiexp_element,
alt_bn128_pairing_check_base,
alt_bn128_pairing_check_element,
alt_bn128_g1_sum_base,
alt_bn128_g1_sum_element,
ed25519_verify_byte = 60,
}

// Type of an action, used in fees logic.
Expand All @@ -455,21 +458,21 @@ pub enum ExtCosts {
)]
#[allow(non_camel_case_types)]
pub enum ActionCosts {
create_account,
delete_account,
deploy_contract_base,
deploy_contract_byte,
function_call_base,
function_call_byte,
transfer,
stake,
add_full_access_key,
add_function_call_key_base,
add_function_call_key_byte,
delete_key,
new_action_receipt,
new_data_receipt_base,
new_data_receipt_byte,
create_account = 0,
delete_account = 1,
deploy_contract_base = 2,
deploy_contract_byte = 3,
function_call_base = 4,
function_call_byte = 5,
transfer = 6,
stake = 7,
add_full_access_key = 8,
add_function_call_key_base = 9,
add_function_call_key_byte = 10,
delete_key = 11,
new_action_receipt = 12,
new_data_receipt_base = 13,
new_data_receipt_byte = 14,
}

impl ExtCosts {
Expand Down
Loading

0 comments on commit b133a43

Please sign in to comment.