-
Notifications
You must be signed in to change notification settings - Fork 153
Description
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
-
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.
-
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(())
}
-
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. -
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.