Skip to content

Commit ca72a82

Browse files
authored
Merge pull request #395 from filecoin-project/steb/revert-trace-changes
Revert "feat: plumb codec through lotus trace (#379)"
2 parents 41a1e40 + 96cfa1a commit ca72a82

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

rust/src/fvm/machine.rs

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use fvm3::gas::GasCharge;
88
use fvm3::trace::ExecutionEvent;
99
use fvm3_ipld_encoding::ipld_block::IpldBlock;
1010
use fvm3_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple};
11-
use fvm3_ipld_encoding::{strict_bytes, to_vec, CborStore};
11+
use fvm3_ipld_encoding::{to_vec, CborStore, RawBytes};
1212
use fvm3_shared::address::Address;
13-
use fvm3_shared::MethodNum;
1413

1514
use fvm3_shared::error::{ErrorNumber, ExitCode};
1615
use fvm3_shared::receipt::Receipt;
@@ -303,6 +302,7 @@ fn fvm_machine_execute_message(
303302

304303
let events_root = events_root.map(|cid| cid.to_bytes().into_boxed_slice().into());
305304

305+
// TODO: Do something with the backtrace.
306306
Ok(FvmMachineExecuteResponse {
307307
exit_code: exit_code.value() as u64,
308308
return_val,
@@ -358,34 +358,22 @@ struct LotusGasCharge {
358358
pub total_gas: u64,
359359
pub compute_gas: u64,
360360
pub other_gas: u64,
361-
pub duration_nanos: u64,
362361
}
363362

364363
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]
365-
struct Trace {
366-
pub msg: TraceMessage,
367-
pub msg_ret: TraceReturn,
364+
struct LotusTrace {
365+
pub msg: Message,
366+
pub msg_receipt: LotusReceipt,
367+
pub error: String,
368368
pub gas_charges: Vec<LotusGasCharge>,
369-
pub subcalls: Vec<Trace>,
369+
pub subcalls: Vec<LotusTrace>,
370370
}
371371

372372
#[derive(Serialize_tuple, Deserialize_tuple, Debug, PartialEq, Eq, Clone)]
373-
pub struct TraceMessage {
374-
pub from: Address,
375-
pub to: Address,
376-
pub value: TokenAmount,
377-
pub method_num: MethodNum,
378-
#[serde(with = "strict_bytes")]
379-
pub params: Vec<u8>,
380-
pub codec: u64,
381-
}
382-
383-
#[derive(Serialize_tuple, Deserialize_tuple, Debug, PartialEq, Eq, Clone)]
384-
pub struct TraceReturn {
373+
pub struct LotusReceipt {
385374
pub exit_code: ExitCode,
386-
#[serde(with = "strict_bytes")]
387-
pub return_data: Vec<u8>,
388-
pub codec: u64,
375+
pub return_data: RawBytes,
376+
pub gas_used: i64,
389377
}
390378

391379
fn build_lotus_trace(
@@ -395,22 +383,26 @@ fn build_lotus_trace(
395383
params: Option<IpldBlock>,
396384
value: TokenAmount,
397385
trace_iter: &mut impl Iterator<Item = ExecutionEvent>,
398-
) -> anyhow::Result<Trace> {
399-
let params = params.unwrap_or_default();
400-
let mut new_trace = Trace {
401-
msg: TraceMessage {
386+
) -> anyhow::Result<LotusTrace> {
387+
let mut new_trace = LotusTrace {
388+
msg: Message {
389+
version: 0,
402390
from: Address::new_id(from),
403391
to,
404392
value,
393+
sequence: 0,
405394
method_num: method,
406-
params: params.data,
407-
codec: params.codec,
395+
params: params.map(|b| b.data).unwrap_or_default().into(),
396+
gas_limit: 0,
397+
gas_fee_cap: TokenAmount::default(),
398+
gas_premium: TokenAmount::default(),
408399
},
409-
msg_ret: TraceReturn {
400+
msg_receipt: LotusReceipt {
410401
exit_code: ExitCode::OK,
411-
return_data: Vec::new(),
412-
codec: 0,
402+
return_data: RawBytes::default(),
403+
gas_used: 0,
413404
},
405+
error: String::new(),
414406
gas_charges: vec![],
415407
subcalls: vec![],
416408
};
@@ -429,11 +421,10 @@ fn build_lotus_trace(
429421
)?);
430422
}
431423
ExecutionEvent::CallReturn(exit_code, return_data) => {
432-
let return_data = return_data.unwrap_or_default();
433-
new_trace.msg_ret = TraceReturn {
424+
new_trace.msg_receipt = LotusReceipt {
434425
exit_code,
435-
return_data: return_data.data,
436-
codec: return_data.codec,
426+
return_data: return_data.map(|b| b.data).unwrap_or_default().into(),
427+
gas_used: 0,
437428
};
438429
return Ok(new_trace);
439430
}
@@ -447,31 +438,24 @@ fn build_lotus_trace(
447438
_ => ExitCode::SYS_ASSERTION_FAILED,
448439
};
449440

450-
new_trace.msg_ret = TraceReturn {
441+
new_trace.msg_receipt = LotusReceipt {
451442
exit_code,
452443
return_data: Default::default(),
453-
codec: 0,
444+
gas_used: 0,
454445
};
455446
return Ok(new_trace);
456447
}
457448
ExecutionEvent::GasCharge(GasCharge {
458449
name,
459450
compute_gas,
460451
other_gas,
461-
elapsed,
452+
elapsed: _, // TODO: thread timing through to lotus.
462453
}) => {
463454
new_trace.gas_charges.push(LotusGasCharge {
464455
name,
465456
total_gas: (compute_gas + other_gas).round_up(),
466457
compute_gas: compute_gas.round_up(),
467458
other_gas: other_gas.round_up(),
468-
duration_nanos: elapsed
469-
.get()
470-
.copied()
471-
.unwrap_or_default()
472-
.as_nanos()
473-
.try_into()
474-
.unwrap_or(u64::MAX),
475459
});
476460
}
477461
_ => (), // ignore unknown events.
@@ -538,12 +522,6 @@ mod test {
538522
total_gas: initial_gas_charge.total().round_up(),
539523
compute_gas: initial_gas_charge.compute_gas.round_up(),
540524
other_gas: initial_gas_charge.other_gas.round_up(),
541-
duration_nanos: initial_gas_charge
542-
.elapsed
543-
.get()
544-
.copied()
545-
.unwrap_or_default()
546-
.as_nanos() as u64,
547525
}
548526
);
549527
assert_eq!(lotus_trace.subcalls.len(), 2);

0 commit comments

Comments
 (0)