-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix smart-contracts gas payments (#4505)
* Update packages * Pay VM creation and compilations correctly * Use max_instance_cost for default compilation * Update module costs * Minor metrics * Tmp module metrics and high max_instance value for testing * Calibrated costs for compilation and instance + compilation metrics cleanup * Change costs and use runtime branch * Add SC gas doc & improve CL compilation payments * Update gas costs & other minor changes * Clippy fixes * Cargo.toml & cfg fixes * Remove context payments and update ABI costs * Update documentation * Impl get_tmp_module * Update doc * Review updates * Doc * Loader documentation * Fmt * Remove compilation timers * Add gas to base operation (tx, roll buy & sell) Signed-off-by: Jean-François <[email protected]> * Fix majority of tests * Fix remaining tests * Update unit test SC src tag * Move SP compilation payment to OP and ABI costs * Update gas documentation * Update RuntimeModule usage, fix from_op, add sp compil to pool config, fix tests * Update gas table doc * Fix tests * Add an important little bit of doc * saturating_add on sp cost --------- Signed-off-by: Jean-François <[email protected]> Co-authored-by: Jean-François <[email protected]>
- Loading branch information
Showing
21 changed files
with
436 additions
and
335 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Overview | ||
|
||
This document keeps track of where and how gas costs are handled for SC executions. | ||
|
||
It contains: | ||
* the gas table | ||
* the list of functions that effectively pay the costs | ||
|
||
# Gas table | ||
|
||
| TYPE | PAYMENT | | ||
| ------------------------ | ---------------- | | ||
| **CallSC (OP)** | | | ||
| compilation | NOT PAID | | ||
| VM instantiation | PAID IN MAX_GAS | | ||
| module instantiation | PAID IN MAX_GAS | | ||
| execution | PAID IN MAX_GAS | | ||
| **ExecuteSC (OP)** | | | ||
| compilation | PAID IN OP GAS | | ||
| VM instantiation | PAID IN MAX_GAS | | ||
| module instantiation | PAID IN MAX_GAS | | ||
| execution | PAID IN MAX_GAS | | ||
| **Call (ABI)** | | | ||
| compilation | NOT PAID | | ||
| VM instantiation | PAID IN CALL GAS | | ||
| module instantiation | PAID IN CALL GAS | | ||
| execution | PAID IN CALL GAS | | ||
| base gas cost of the ABI | PAID IN ABI GAS | | ||
| **LocalExecution (ABI)** | | | ||
| compilation | PAID IN ABI GAS | | ||
| VM instantiation | PAID IN CALL GAS | | ||
| module instantiation | PAID IN CALL GAS | | ||
| execution | PAID IN CALL GAS | | ||
| base gas cost of the ABI | PAID IN ABI GAS | | ||
| **CreateSC (ABI)** | | | ||
| compilation | PAID IN ABI GAS | | ||
| **SetBytecode (ABI)** | | | ||
| compilation | PAID IN ABI GAS | | ||
|
||
# Functions | ||
|
||
### Singlepass compilation | ||
|
||
1. Paid for ExecuteSC operations as OP cost in `massa-execution-worker` > `execution.rs` > `execute_operation` by `get_gas_usage` | ||
2. Paid for ReadOnly requests in `massa-execution-worker` > `execution.rs` > `execute_readonly_request` | ||
3. Paid in `massa-sc-runtime` ABI cost by `assembly_script_local_execution`. This ABI gives rise to Singlepass compilations and must have according costs to pay for it. | ||
|
||
### Cranelift compilation | ||
|
||
Paid in `massa-sc-runtime` ABI costs by `assembly_script_create_sc`, `assembly_script_set_bytecode` & `assembly_script_set_bytecode_for`. These ABIs give rise to Cranelift compilations and must have according costs to pay for it. | ||
|
||
### VM & Module instantiation | ||
|
||
1. Threshold checked in `massa-module-cache` > `controller.rs` > `load_module` & `load_tmp_module` | ||
2. `load_module` is used in every function calling SCs stored on the chain | ||
3. `load_tmp_module` is used in every function calling arbitrary code | ||
4. Actual cost paid in `massa-sc-runtime` | ||
|
||
### Execution | ||
|
||
Paid in `massa-sc-runtime`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.