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

fix (Runtime): Pass code_hash to ContractCode::new when available #3102

Merged
merged 2 commits into from
Aug 9, 2020

Conversation

evgenykuzyakov
Copy link
Collaborator

@evgenykuzyakov evgenykuzyakov commented Aug 7, 2020

Don't re-hash a contract code after a read if the code_hash is already available in the account ID. The only place to rehash is when apply_genesis_records is called.

Ref: #3094

Test plan:

  • CI
  • Run fee estimator again.

@gitpod-io
Copy link

gitpod-io bot commented Aug 7, 2020

Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Epic

@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #3102 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3102   +/-   ##
=======================================
  Coverage   87.55%   87.55%           
=======================================
  Files         212      212           
  Lines       41470    41470           
=======================================
  Hits        36307    36307           
  Misses       5163     5163           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b26a0da...9d38f23. Read the comment docs.

@evgenykuzyakov
Copy link
Collaborator Author

18963ko vs 40367ko originally. So it's 2.1X improvement just for hashing.

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@evgenykuzyakov
Copy link
Collaborator Author

RuntimeConfig {
    storage_amount_per_byte: 90900000000000000000,
    transaction_costs: RuntimeFeesConfig {
        action_receipt_creation_config: Fee {
            send_sir: 148280187500,
            send_not_sir: 148280187500,
            execution: 148280187500,
        },
        data_receipt_creation_config: DataReceiptCreationConfig {
            base_cost: Fee {
                send_sir: 1035057529250,
                send_not_sir: 1035057529250,
                execution: 1035057529250,
            },
            cost_per_byte: Fee {
                send_sir: 23636040,
                send_not_sir: 23636040,
                execution: 23636040,
            },
        },
        action_creation_config: ActionCreationConfig {
            create_account_cost: Fee {
                send_sir: 130586437500,
                send_not_sir: 130586437500,
                execution: 130586437500,
            },
            deploy_contract_cost: Fee {
                send_sir: 221007875000,
                send_not_sir: 221007875000,
                execution: 221007875000,
            },
            deploy_contract_cost_per_byte: Fee {
                send_sir: 6842788,
                send_not_sir: 6842788,
                execution: 6842788,
            },
            function_call_cost: Fee {
                send_sir: 1185240500000,
                send_not_sir: 1185240500000,
                execution: 1185240500000,
            },
            function_call_cost_per_byte: Fee {
                send_sir: 1158368,
                send_not_sir: 1158368,
                execution: 1158368,
            },
            transfer_cost: Fee {
                send_sir: 160114875000,
                send_not_sir: 160114875000,
                execution: 160114875000,
            },
            stake_cost: Fee {
                send_sir: 168325562500,
                send_not_sir: 168325562500,
                execution: 168325562500,
            },
            add_key_cost: AccessKeyCreationConfig {
                full_access_cost: Fee {
                    send_sir: 135544625000,
                    send_not_sir: 135544625000,
                    execution: 135544625000,
                },
                function_call_cost: Fee {
                    send_sir: 134122562500,
                    send_not_sir: 134122562500,
                    execution: 134122562500,
                },
                function_call_cost_per_byte: Fee {
                    send_sir: 22561456,
                    send_not_sir: 22561456,
                    execution: 22561456,
                },
            },
            delete_key_cost: Fee {
                send_sir: 121852562500,
                send_not_sir: 121852562500,
                execution: 121852562500,
            },
            delete_account_cost: Fee {
                send_sir: 202611250000,
                send_not_sir: 202611250000,
                execution: 202611250000,
            },
        },
        storage_usage_config: StorageUsageConfig {
            num_bytes_account: 100,
            num_extra_bytes_record: 40,
        },
        burnt_gas_reward: Ratio {
            numer: 3,
            denom: 10,
        },
        pessimistic_gas_price_inflation_ratio: Ratio {
            numer: 103,
            denom: 100,
        },
    },
    wasm_config: VMConfig {
        ext_costs: ExtCostsConfig {
            base: 84199966,
            contract_compile_base: 15148452,
            contract_compile_bytes: 309875,
            read_memory_base: 464481200,
            read_memory_byte: 1267107,
            write_memory_base: 529139450,
            write_memory_byte: 907796,
            read_register_base: 434091512,
            read_register_byte: 32470,
            write_register_base: 549892212,
            write_register_byte: 1267188,
            utf8_decoding_base: 632914062,
            utf8_decoding_byte: 97179071,
            utf16_decoding_base: 776542512,
            utf16_decoding_byte: 54515503,
            sha256_base: 1104558212,
            sha256_byte: 7999234,
            keccak256_base: 1546923325,
            keccak256_byte: 7109448,
            keccak512_base: 1520917275,
            keccak512_byte: 12169095,
            log_base: 776542512,
            log_byte: 4372491,
            storage_write_base: 17091999000,
            storage_write_key_byte: 23142772,
            storage_write_value_byte: 17877362,
            storage_write_evicted_byte: 10286151,
            storage_read_base: 14974770750,
            storage_read_key_byte: 9926614,
            storage_read_value_byte: 1489149,
            storage_remove_base: 14378844125,
            storage_remove_key_byte: 12374859,
            storage_remove_ret_value_byte: 2998309,
            storage_has_key_base: 14058882500,
            storage_has_key_byte: 9820436,
            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: 4278505928,
            promise_and_base: 448183042,
            promise_and_per_promise: 1828082,
            promise_return: 146372272,
            validator_stake_base: 303944908800,
            validator_total_stake_base: 303944908800,
        },
        grow_mem_cost: 1,
        regular_op_cost: 1147826,
        limit_config: VMLimitConfig {
            max_gas_burnt: 200000000000000,
            max_gas_burnt_view: 200000000000000,
            max_stack_height: 16384,
            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_length_storage_key: 4194304,
            max_length_storage_value: 4194304,
            max_promises_per_function_call_action: 1024,
            max_number_input_data_dependencies: 128,
        },
    },
    account_creation_config: AccountCreationConfig {
        min_allowed_top_level_account_length: 0,
        registrar_account_id: "registrar",
    },
}

@evgenykuzyakov
Copy link
Collaborator Author

To compare.
this PR

data_receipt_creation_config: DataReceiptCreationConfig {
            base_cost: Fee {
                send_sir: 1035057529250,
                send_not_sir: 1035057529250,
                execution: 1035057529250,
            },
            cost_per_byte: Fee {
                send_sir: 23636040,
                send_not_sir: 23636040,
                execution: 23636040,
            },
        },

vs

data_receipt_creation_config: DataReceiptCreationConfig {
                base_cost: Fee {
                    send_sir: 4697339419375,
                    send_not_sir: 4697339419375,
                    execution: 4697339419375,
                },
                cost_per_byte: Fee {
                    send_sir: 59357464,
                    send_not_sir: 59357464,
                    execution: 59357464,
                },
            },

this PR

function_call_cost: Fee {
                send_sir: 1185240500000,
                send_not_sir: 1185240500000,
                execution: 1185240500000,
            },
            function_call_cost_per_byte: Fee {
                send_sir: 1158368,
                send_not_sir: 1158368,
                execution: 1158368,
            },

vs

function_call_cost: Fee {
                    send_sir: 2319861500000,
                    send_not_sir: 2319861500000,
                    execution: 2319861500000,
                },
                function_call_cost_per_byte: Fee {
                    send_sir: 2235934,
                    send_not_sir: 2235934,
                    execution: 2235934,
                },

Copy link
Contributor

@MaksymZavershynskyi MaksymZavershynskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what cases it is not available?

@evgenykuzyakov
Copy link
Collaborator Author

evgenykuzyakov commented Aug 7, 2020

In what cases it is not available?

Deploying a new code mostly. And tests

@bowenwang1996
Copy link
Collaborator

@evgenykuzyakov 1185240500000 is still more than 1T. Why is it the case?

@evgenykuzyakov
Copy link
Collaborator Author

1185240500000 is still more than 1T. Why is it the case?

I don't know. So need to investigate further. For sure there is a code read. But the fee estimator should be done against 10Kb contract, so it doesn't affect as much.

@evgenykuzyakov evgenykuzyakov merged commit 7ee16b5 into master Aug 9, 2020
@evgenykuzyakov evgenykuzyakov deleted the disable-contract-code-re-hashing branch August 9, 2020 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants