Skip to content

Commit f520d39

Browse files
authored
feat: support flush_all_blocks, handle new ipld operations in traces (#512)
* feat: support DumpCache, handle Logs in traces Ref: filecoin-project/ref-fvm#2101 * feat(fvm): add flush_all_blocks option to also write intermediate blocks * feat: add ipld section to execution trace
1 parent a2322d1 commit f520d39

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

cgo/fvm.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package cgo
88
*/
99
import "C"
1010

11-
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
11+
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
1212
resp := (*resultFvmMachine)(C.create_fvm_machine(
1313
(C.FvmRegisteredVersion_t)(fvmVersion),
1414
C.uint64_t(chainEpoch),
@@ -21,6 +21,7 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
2121
C.uint32_t(networkVersion),
2222
(C.slice_ref_uint8_t)(stateRoot),
2323
C.bool(tracing),
24+
C.bool(flushAllBlocks),
2425
C.uint64_t(blockstoreId),
2526
C.uint64_t(externsId),
2627
))
@@ -36,7 +37,7 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
3637
return executor, nil
3738
}
3839

39-
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
40+
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
4041
resp := (*resultFvmMachine)(C.create_fvm_debug_machine(
4142
(C.FvmRegisteredVersion_t)(fvmVersion),
4243
C.uint64_t(chainEpoch),
@@ -50,6 +51,7 @@ func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTim
5051
(C.slice_ref_uint8_t)(stateRoot),
5152
(C.slice_ref_uint8_t)(actorRedirect),
5253
C.bool(tracing),
54+
C.bool(flushAllBlocks),
5355
C.uint64_t(blockstoreId),
5456
C.uint64_t(externsId),
5557
))

fvm.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type FVMOpts struct {
4444
NetworkVersion network.Version
4545
StateBase cid.Cid
4646
Tracing bool
47+
FlushAllBlocks bool
4748

4849
Debug bool
4950
ActorRedirect cid.Cid
@@ -74,6 +75,7 @@ func CreateFVM(opts *FVMOpts) (*FVM, error) {
7475
uint64(opts.NetworkVersion),
7576
cgo.AsSliceRefUint8(opts.StateBase.Bytes()),
7677
opts.Tracing,
78+
opts.FlushAllBlocks,
7779
exHandle, exHandle,
7880
)
7981
} else {
@@ -89,6 +91,7 @@ func CreateFVM(opts *FVMOpts) (*FVM, error) {
8991
cgo.AsSliceRefUint8(opts.StateBase.Bytes()),
9092
cgo.AsSliceRefUint8(opts.ActorRedirect.Bytes()),
9193
true,
94+
opts.FlushAllBlocks,
9295
exHandle, exHandle,
9396
)
9497
}

rust/src/fvm/engine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::blockstore::CgoBlockstore;
1616
use super::externs::CgoExterns;
1717
use super::types::*;
1818

19-
// Generic executor; uses the current (v3) engine types
19+
// Generic executor; uses the current engine types
2020
pub trait CgoExecutor: Send {
2121
fn execute_message(
2222
&mut self,
@@ -39,6 +39,7 @@ pub struct Config {
3939
pub tracing: bool,
4040
pub actor_debugging: bool,
4141
pub actor_redirect: Vec<(Cid, Cid)>,
42+
pub flush_all_blocks: bool,
4243
}
4344

4445
// The generic engine interface
@@ -178,6 +179,9 @@ mod v4 {
178179
if cfg.tracing {
179180
machine_context.enable_tracing();
180181
}
182+
if cfg.flush_all_blocks {
183+
machine_context.enable_flush_all_blocks();
184+
}
181185
let engine = self.get(&network_config)?;
182186
let machine = CgoMachine4::new(&machine_context, blockstore, externs)?;
183187
Ok(InnerFvmMachine {

rust/src/fvm/machine.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn create_fvm_machine_generic(
9393
actor_redirect: Option<c_slice::Ref<'_, u8>>,
9494
actor_debugging: bool,
9595
tracing: bool,
96+
flush_all_blocks: bool,
9697
blockstore_id: u64,
9798
externs_id: u64,
9899
) -> repr_c::Box<Result<FvmMachine>> {
@@ -137,6 +138,7 @@ fn create_fvm_machine_generic(
137138
tracing,
138139
actor_debugging,
139140
actor_redirect,
141+
flush_all_blocks,
140142
};
141143

142144
let externs = CgoExterns::new(externs_id);
@@ -166,6 +168,7 @@ fn create_fvm_machine(
166168
network_version: u32,
167169
state_root: c_slice::Ref<'_, u8>,
168170
tracing: bool,
171+
flush_all_blocks: bool,
169172
blockstore_id: u64,
170173
externs_id: u64,
171174
) -> repr_c::Box<Result<FvmMachine>> {
@@ -183,6 +186,7 @@ fn create_fvm_machine(
183186
None,
184187
false,
185188
tracing,
189+
flush_all_blocks,
186190
blockstore_id,
187191
externs_id,
188192
)
@@ -202,6 +206,7 @@ fn create_fvm_debug_machine(
202206
state_root: c_slice::Ref<'_, u8>,
203207
actor_redirect: c_slice::Ref<'_, u8>,
204208
tracing: bool,
209+
flush_all_blocks: bool,
205210
blockstore_id: u64,
206211
externs_id: u64,
207212
) -> repr_c::Box<Result<FvmMachine>> {
@@ -223,6 +228,7 @@ fn create_fvm_debug_machine(
223228
},
224229
true,
225230
tracing,
231+
flush_all_blocks,
226232
blockstore_id,
227233
externs_id,
228234
)
@@ -432,13 +438,22 @@ struct LotusGasCharge {
432438
pub duration_nanos: u64,
433439
}
434440

441+
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]
442+
struct TraceIpld {
443+
pub op: u64,
444+
pub cid: Cid,
445+
pub size: usize,
446+
}
447+
435448
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]
436449
struct Trace {
437450
pub msg: TraceMessage,
438451
pub msg_ret: TraceReturn,
439452
pub msg_invoked: Option<TraceActor>,
440453
pub gas_charges: Vec<LotusGasCharge>,
441454
pub subcalls: Vec<Trace>,
455+
pub logs: Vec<String>,
456+
pub ipld: Vec<TraceIpld>,
442457
}
443458

444459
#[derive(Serialize_tuple, Deserialize_tuple, Debug, PartialEq, Eq, Clone)]
@@ -499,6 +514,8 @@ fn build_lotus_trace(
499514
},
500515
gas_charges: vec![],
501516
subcalls: vec![],
517+
logs: vec![],
518+
ipld: vec![],
502519
};
503520

504521
while let Some(trace) = trace_iter.next() {
@@ -568,6 +585,16 @@ fn build_lotus_trace(
568585
.unwrap_or(u64::MAX),
569586
});
570587
}
588+
ExecutionEvent::Log(s) => {
589+
new_trace.logs.push(s);
590+
}
591+
ExecutionEvent::Ipld { op, cid, size } => {
592+
new_trace.ipld.push(TraceIpld {
593+
op: op as u64,
594+
cid,
595+
size,
596+
});
597+
}
571598
_ => (), // ignore unknown events.
572599
};
573600
}
@@ -605,10 +632,12 @@ mod test {
605632
ExecutionEvent::GasCharge(initial_gas_charge.clone()),
606633
call_event.clone(),
607634
return_result.clone(),
635+
ExecutionEvent::Log("something happened".to_string()),
608636
call_event.clone(),
609637
call_event,
610638
return_result.clone(),
611639
return_result.clone(),
640+
ExecutionEvent::Log("something else happened".to_string()),
612641
return_result,
613642
];
614643

@@ -648,5 +677,8 @@ mod test {
648677
assert_eq!(lotus_trace.subcalls[0].subcalls.len(), 0);
649678
assert_eq!(lotus_trace.subcalls[1].subcalls.len(), 1);
650679
assert_eq!(lotus_trace.subcalls[1].subcalls[0].subcalls.len(), 0);
680+
assert_eq!(lotus_trace.logs.len(), 2);
681+
assert_eq!(lotus_trace.logs[0], "something happened");
682+
assert_eq!(lotus_trace.logs[1], "something else happened");
651683
}
652684
}

0 commit comments

Comments
 (0)