Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fvm/src/call_manager/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ where
fn log(&mut self, msg: String) {
self.trace(ExecutionEvent::Log(msg))
}

fn trace_ipld(&mut self, op: crate::trace::IpldOperation, cid: Cid, size: usize) {
self.trace(ExecutionEvent::Ipld { op, cid, size })
}
}

impl<M> DefaultCallManager<M>
Expand Down
5 changes: 4 additions & 1 deletion fvm/src/call_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod default;
pub use default::DefaultCallManager;
use fvm_shared::event::StampedEvent;

use crate::trace::ExecutionTrace;
use crate::trace::{ExecutionTrace, IpldOperation};

/// BlockID representing nil parameters or return data.
pub const NO_DATA_BLOCK_ID: u32 = 0;
Expand Down Expand Up @@ -87,6 +87,7 @@ pub trait CallManager: 'static {

/// Returns a reference to the machine.
fn machine(&self) -> &Self::Machine;

/// Returns a mutable reference to the machine.
fn machine_mut(&mut self) -> &mut Self::Machine;

Expand Down Expand Up @@ -177,6 +178,8 @@ pub trait CallManager: 'static {

/// log
fn log(&mut self, msg: String);

fn trace_ipld(&mut self, op: IpldOperation, cid: Cid, size: usize);
}

/// The result of calling actor's entrypoint
Expand Down
12 changes: 12 additions & 0 deletions fvm/src/kernel/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::gas::GasTimer;
use crate::init_actor::INIT_ACTOR_ID;
use crate::machine::{MachineContext, NetworkConfig, BURNT_FUNDS_ACTOR_ID};
use crate::state_tree::ActorState;
use crate::trace::IpldOperation;
use crate::{ipld, syscall_error};

const BLAKE2B_256: u64 = 0xb220;
Expand Down Expand Up @@ -409,6 +410,9 @@ where

t.stop();

self.call_manager
.trace_ipld(IpldOperation::Get, *cid, data.len());

// This can fail because we can run out of gas.
let children = ipld::scan_for_reachable_links(
cid.codec(),
Expand Down Expand Up @@ -483,9 +487,13 @@ where
// TODO: This is really "super fatal". It means we failed to store state, and should
// probably abort the entire block.
.or_fatal()?;
let size = block.data().len();
self.blocks.mark_reachable(&k);

t.stop_with(start);

self.call_manager.trace_ipld(IpldOperation::Put, k, size);

Ok(k)
}

Expand Down Expand Up @@ -880,6 +888,7 @@ where

fn install_actor(&mut self, code_id: Cid) -> Result<()> {
let start = GasTimer::start();

let size = self
.call_manager
.engine()
Expand All @@ -892,6 +901,9 @@ where
.charge_gas(self.call_manager.price_list().on_install_actor(size))?;
t.stop_with(start);

self.call_manager
.trace_ipld(IpldOperation::Get, code_id, size);

Ok(())
}

Expand Down
13 changes: 13 additions & 0 deletions fvm/src/trace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cid::Cid;
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use fvm_ipld_encoding::ipld_block::IpldBlock;
Expand All @@ -13,6 +14,13 @@ use crate::kernel::SyscallError;
/// Execution Trace, only for informational and debugging purposes.
pub type ExecutionTrace = Vec<ExecutionEvent>;

/// The type of operation being performed in an Ipld ExecutionEvent.
#[derive(Clone, Debug, PartialEq)]
pub enum IpldOperation {
Get, // open
Put, // link
}

/// An "event" that happened during execution.
///
/// This is marked as `non_exhaustive` so we can introduce additional event types later.
Expand All @@ -39,4 +47,9 @@ pub enum ExecutionEvent {
state: ActorState,
},
Log(String),
Ipld {
op: IpldOperation,
cid: Cid,
size: usize,
},
}
17 changes: 17 additions & 0 deletions fvm/tests/default_kernel/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod ipld {
use cid::Cid;
use fvm::kernel::{IpldBlockOps, SupportedHashes};
use fvm::machine::Machine;
use fvm::trace::IpldOperation;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{DAG_CBOR, IPLD_RAW};
use multihash_codetable::MultihashDigest;
Expand Down Expand Up @@ -200,6 +201,22 @@ mod ipld {
)
}

assert!(call_manager
.ipld_traces
.iter()
.any(|(op, c, _)| *op == IpldOperation::Put && *c == cid));

let (call_manager1, _) = kern1.into_inner();

assert!(call_manager1
.ipld_traces
.iter()
.any(|(op, c, _)| *op == IpldOperation::Put && *c == cid)); // cid1==cid
assert!(call_manager1
.ipld_traces
.iter()
.any(|(op, c, _)| *op == IpldOperation::Put && *c == other_cid));

Ok(())
}

Expand Down
9 changes: 9 additions & 0 deletions fvm/tests/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use fvm::gas::{Gas, GasCharge, GasTimer, GasTracker};
use fvm::machine::limiter::MemoryLimiter;
use fvm::machine::{Machine, MachineContext, Manifest, NetworkConfig};
use fvm::state_tree::StateTree;
use fvm::trace::IpldOperation;
use fvm::{kernel, Kernel};
use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore};
use fvm_ipld_encoding::{CborStore, DAG_CBOR};
Expand Down Expand Up @@ -191,6 +192,7 @@ pub struct DummyCallManager {
pub origin: ActorID,
pub nonce: u64,
pub test_data: Rc<RefCell<TestData>>,
pub ipld_traces: Vec<(IpldOperation, Cid, usize)>,
limits: DummyLimiter,
}

Expand All @@ -216,6 +218,7 @@ impl DummyCallManager {
test_data: rc,
limits: DummyLimiter::default(),
gas_premium: TokenAmount::zero(),
ipld_traces: vec![],
},
cell_ref,
)
Expand All @@ -235,6 +238,7 @@ impl DummyCallManager {
test_data: rc,
limits: DummyLimiter::default(),
gas_premium: TokenAmount::zero(),
ipld_traces: vec![],
},
cell_ref,
)
Expand Down Expand Up @@ -267,6 +271,7 @@ impl CallManager for DummyCallManager {
nonce,
test_data: rc,
limits,
ipld_traces: vec![],
}
}

Expand Down Expand Up @@ -404,4 +409,8 @@ impl CallManager for DummyCallManager {
fn log(&mut self, _msg: String) {
todo!()
}

fn trace_ipld(&mut self, op: IpldOperation, cid: Cid, size: usize) {
self.ipld_traces.push((op, cid, size));
}
}
Loading