From 3a38316d899c1c317c3350a0c123e5a592861464 Mon Sep 17 00:00:00 2001 From: Arturo Beccar-Varela <107512933+arturoBeccar@users.noreply.github.com> Date: Tue, 28 Nov 2023 18:53:13 -0300 Subject: [PATCH] Removed incorrect previous estimate from documentation --- test-cases/gas-left/README.md | 56 +---------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/test-cases/gas-left/README.md b/test-cases/gas-left/README.md index 4c15fbe..82b871a 100644 --- a/test-cases/gas-left/README.md +++ b/test-cases/gas-left/README.md @@ -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.