Skip to content

feature request: Add a mechanism for debugging gas costs. #1498

@hunjixin

Description

@hunjixin

Motivation

We found that some miners' SubmitWindowsPost message gas was always higher than others (with more sectors, containing only one proof), and after searching for gastrace, we found that the individual wasm_exec was very different, but now we can't tell what code was executed in this wasm_exec.

Solution

  1. Is there any debugging mechanism in wasmtime that can output the previously run part of the code during the program run so that it can be used to speculate which part of the contract code is the problem. I have tried this and have not found a way. I wonder if others have other ideas.

  2. add a gastrace to the existing debug.log

pub fn log(context: Context<'_, impl Kernel>, msg_off: u32, msg_len: u32) -> Result<()> {
    // No-op if disabled.
    if !context.kernel.debug_enabled() {
        return Ok(());
    }

    let msg = context.memory.try_slice(msg_off, msg_len)?;
    let msg = String::from_utf8(msg.to_owned()).or_illegal_argument()?;


    let gas_prefix = if msg.len() > 20 {
        msg[..20]
    } else{
        msg
    };
    context.kernel.charge_gas(format!("wasm_exec {}", gas_prefix).as_str(), Gas::zero())?;

    context.kernel.log(msg);
    Ok(())
}
  1. add just add a new sys call debug.trace_gas" for hitting the gas marker, developement can add mark in contract, its easy to see which code used much gas.

  2. may be possible to make some changes in fvm-wasm-instruction, debug mode consumes gas via system calls, which has the side effect of causing a lot of system calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions