Skip to content

Commit

Permalink
Removed incorrect previous estimate from documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoBeccar authored Nov 28, 2023
1 parent 8037807 commit 3a38316
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions test-cases/gas-left/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,5 @@ Further testing can be performed in order to check gas calculation and address e

## Result

Updated estimate: Because integration tests are performed on native code rather than WASM code, and because gas cost is based on number of WASM instructions executed, implementing this function is impractically complex.
Because integration tests are performed on native code rather than WASM code, and because gas cost is based on number of WASM instructions executed, implementing this function is impractically complex.

Previous estimate:

E2E implementation:

```rust
//https://github.com/paritytech/substrate.git:28e906dffcaa91e85f59aff628d953ebeb036ae2
//frame/contracts/src/wasm/runtime.rs:1968
/// Stores the weight left into the supplied buffer.
///
/// Equivalent to the newer [`seal1`][`super::api_doc::Version2::gas_left`] version but
/// works with *ref_time* Weight only. It is recommended to switch to the latest version, once
/// it's stabilized.
#[prefixed_alias]
fn gas_left(ctx: _, memory: _, out_ptr: u32, out_len_ptr: u32) -> Result<(), TrapReason> {
/*
* Charges to ctx the appropriate cost for calling this function. See:
* * frame/contracts/src/wasm/runtime.rs:366-375
* * frame/contracts/src/wasm/runtime.rs:289
* * frame/contracts/src/schedule.rs:216
* * frame/contracts/src/schedule.rs:367-371
* * frame/contracts/src/schedule.rs:355-359
* * frame/contracts/src/weights.rs:688-699
*/
ctx.charge_gas(RuntimeCosts::GasLeft)?;
/*
* Gets the actual gas left value from ctx. See:
* * frame/contracts/src/exec.rs:1436-1438
* * frame/contracts/src/exec.rs:609-613
* * frame/contracts/src/exec.rs:447
* * frame/contracts/src/lib.rs:269
* * frame/contracts/src/exec.rs:480
*/
let gas_left = &ctx.ext.gas_meter().gas_left().ref_time().encode();
/*
* Writes the value to the output pointer. See
* * frame/contracts/src/wasm/runtime.rs:638-683
* Note that it would appear that this function does not charge the
* context. The most relevant call in this function appears to be
* write_sandbox_memory(), defined in
* * frame/contracts/src/wasm/runtime.rs:685-701
*/
Ok(ctx.write_sandbox_output(
memory,
out_ptr,
out_len_ptr,
gas_left,
false,
already_charged,
)?)
}
```

The main implementation cost on integration is a missing stack structure to keep track of the {functions|contracts} (unsure which one, probably the latter) that have been executed in the current context. This stack structure also keeps track of the remaining gas for the current call. Other than that, the function merely updates a value on that stack and then serializes an integer into a buffer.
As a rough estimate. A programmer already familiar with the Substrate codebase could implement the feature in 1-2 days. One who's unfamiliar could take 5-8 days.

0 comments on commit 3a38316

Please sign in to comment.