Skip to content

Commit

Permalink
Merge pull request #411 from filecoin-project/traceapi-new-fields
Browse files Browse the repository at this point in the history
feat: add new fields to message trace for supporting new trace api
  • Loading branch information
fridrik01 authored Aug 28, 2023
2 parents 8c2147f + abd0595 commit bf5edd5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ anyhow = "1.0.23"
serde_json = "1.0.46"
rust-gpu-tools = { version = "0.7", optional = true, default-features = false }
fr32 = { version = "~7.0", default-features = false }
fvm3 = { package = "fvm", version = "~3.6.0", default-features = false, features = ["nv21-dev"] }
fvm3 = { package = "fvm", version = "~3.7.0", default-features = false, features = ["nv21-dev"] }
fvm3_shared = { package = "fvm_shared", version = "~3.5.0" }
fvm2 = { package = "fvm", version = "~2.6", default-features = false }
fvm2_shared = { package = "fvm_shared", version = "~2.5" }
Expand Down
2 changes: 2 additions & 0 deletions rust/src/fvm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ mod v2 {
method,
params: bytes_to_block(params),
value: TokenAmount::from_atto(value.atto().clone()),
gas_limit: msg.gas_limit,
read_only: false,
}),
ExecutionEvent2::CallReturn(ret) => Some(ExecutionEvent::CallReturn(
ExitCode::OK,
Expand Down
24 changes: 23 additions & 1 deletion rust/src/fvm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,17 @@ fn fvm_machine_execute_message(
method,
params,
value,
gas_limit,
read_only,
}) => {
break build_lotus_trace(
from,
to,
method,
params,
value,
gas_limit,
read_only,
&mut initial_gas_charges.into_iter().chain(&mut trace_iter),
)
.ok()
Expand Down Expand Up @@ -378,6 +382,9 @@ pub struct TraceMessage {
#[serde(with = "strict_bytes")]
pub params: Vec<u8>,
pub codec: u64,
pub gas_limit: u64,
pub read_only: bool,
pub code_cid: Cid,
}

#[derive(Serialize_tuple, Deserialize_tuple, Debug, PartialEq, Eq, Clone)]
Expand All @@ -388,12 +395,15 @@ pub struct TraceReturn {
pub codec: u64,
}

#[allow(clippy::too_many_arguments)]
fn build_lotus_trace(
from: u64,
to: Address,
method: u64,
params: Option<IpldBlock>,
value: TokenAmount,
gas_limit: u64,
read_only: bool,
trace_iter: &mut impl Iterator<Item = ExecutionEvent>,
) -> anyhow::Result<Trace> {
let params = params.unwrap_or_default();
Expand All @@ -405,6 +415,9 @@ fn build_lotus_trace(
method_num: method,
params: params.data,
codec: params.codec,
gas_limit,
read_only,
code_cid: Cid::default(),
},
msg_ret: TraceReturn {
exit_code: ExitCode::OK,
Expand All @@ -423,11 +436,16 @@ fn build_lotus_trace(
method,
params,
value,
gas_limit,
read_only,
} => {
new_trace.subcalls.push(build_lotus_trace(
from, to, method, params, value, trace_iter,
from, to, method, params, value, gas_limit, read_only, trace_iter,
)?);
}
ExecutionEvent::InvokeActor(cid) => {
new_trace.msg.code_cid = cid;
}
ExecutionEvent::CallReturn(exit_code, return_data) => {
let return_data = return_data.unwrap_or_default();
new_trace.msg_ret = TraceReturn {
Expand Down Expand Up @@ -501,6 +519,8 @@ mod test {
params: None,
to: Address::new_id(0),
value: TokenAmount::default(),
gas_limit: u64::MAX,
read_only: false,
};
let return_result =
ExecutionEvent::CallError(SyscallError::new(IllegalArgument, "illegal"));
Expand All @@ -524,6 +544,8 @@ mod test {
0,
None,
TokenAmount::default(),
u64::MAX,
false,
&mut trace_iter,
)
.unwrap();
Expand Down

0 comments on commit bf5edd5

Please sign in to comment.