@@ -8,9 +8,8 @@ use fvm3::gas::GasCharge;
8
8
use fvm3:: trace:: ExecutionEvent ;
9
9
use fvm3_ipld_encoding:: ipld_block:: IpldBlock ;
10
10
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 } ;
12
12
use fvm3_shared:: address:: Address ;
13
- use fvm3_shared:: MethodNum ;
14
13
15
14
use fvm3_shared:: error:: { ErrorNumber , ExitCode } ;
16
15
use fvm3_shared:: receipt:: Receipt ;
@@ -303,6 +302,7 @@ fn fvm_machine_execute_message(
303
302
304
303
let events_root = events_root. map ( |cid| cid. to_bytes ( ) . into_boxed_slice ( ) . into ( ) ) ;
305
304
305
+ // TODO: Do something with the backtrace.
306
306
Ok ( FvmMachineExecuteResponse {
307
307
exit_code : exit_code. value ( ) as u64 ,
308
308
return_val,
@@ -358,34 +358,22 @@ struct LotusGasCharge {
358
358
pub total_gas : u64 ,
359
359
pub compute_gas : u64 ,
360
360
pub other_gas : u64 ,
361
- pub duration_nanos : u64 ,
362
361
}
363
362
364
363
#[ 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 ,
368
368
pub gas_charges : Vec < LotusGasCharge > ,
369
- pub subcalls : Vec < Trace > ,
369
+ pub subcalls : Vec < LotusTrace > ,
370
370
}
371
371
372
372
#[ 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 {
385
374
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 ,
389
377
}
390
378
391
379
fn build_lotus_trace (
@@ -395,22 +383,26 @@ fn build_lotus_trace(
395
383
params : Option < IpldBlock > ,
396
384
value : TokenAmount ,
397
385
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 ,
402
390
from : Address :: new_id ( from) ,
403
391
to,
404
392
value,
393
+ sequence : 0 ,
405
394
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 ( ) ,
408
399
} ,
409
- msg_ret : TraceReturn {
400
+ msg_receipt : LotusReceipt {
410
401
exit_code : ExitCode :: OK ,
411
- return_data : Vec :: new ( ) ,
412
- codec : 0 ,
402
+ return_data : RawBytes :: default ( ) ,
403
+ gas_used : 0 ,
413
404
} ,
405
+ error : String :: new ( ) ,
414
406
gas_charges : vec ! [ ] ,
415
407
subcalls : vec ! [ ] ,
416
408
} ;
@@ -429,11 +421,10 @@ fn build_lotus_trace(
429
421
) ?) ;
430
422
}
431
423
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 {
434
425
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 ,
437
428
} ;
438
429
return Ok ( new_trace) ;
439
430
}
@@ -447,31 +438,24 @@ fn build_lotus_trace(
447
438
_ => ExitCode :: SYS_ASSERTION_FAILED ,
448
439
} ;
449
440
450
- new_trace. msg_ret = TraceReturn {
441
+ new_trace. msg_receipt = LotusReceipt {
451
442
exit_code,
452
443
return_data : Default :: default ( ) ,
453
- codec : 0 ,
444
+ gas_used : 0 ,
454
445
} ;
455
446
return Ok ( new_trace) ;
456
447
}
457
448
ExecutionEvent :: GasCharge ( GasCharge {
458
449
name,
459
450
compute_gas,
460
451
other_gas,
461
- elapsed,
452
+ elapsed : _ , // TODO: thread timing through to lotus.
462
453
} ) => {
463
454
new_trace. gas_charges . push ( LotusGasCharge {
464
455
name,
465
456
total_gas : ( compute_gas + other_gas) . round_up ( ) ,
466
457
compute_gas : compute_gas. round_up ( ) ,
467
458
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 ) ,
475
459
} ) ;
476
460
}
477
461
_ => ( ) , // ignore unknown events.
@@ -538,12 +522,6 @@ mod test {
538
522
total_gas: initial_gas_charge. total( ) . round_up( ) ,
539
523
compute_gas: initial_gas_charge. compute_gas. round_up( ) ,
540
524
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 ,
547
525
}
548
526
) ;
549
527
assert_eq ! ( lotus_trace. subcalls. len( ) , 2 ) ;
0 commit comments