Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose mutable access to tracer config #154

Merged
merged 1 commit into from
Jun 27, 2024
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
33 changes: 29 additions & 4 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,46 @@ impl TracingInspector {
&self.config
}

/// Returns a mutable reference to the config of the inspector.
pub fn config_mut(&mut self) -> &mut TracingInspectorConfig {
&mut self.config
}

/// Updates the config of the inspector.
pub fn update_config(
&mut self,
f: impl FnOnce(TracingInspectorConfig) -> TracingInspectorConfig,
) {
self.config = f(self.config);
}

/// Gets a reference to the recorded call traces.
pub const fn get_traces(&self) -> &CallTraceArena {
pub const fn traces(&self) -> &CallTraceArena {
&self.traces
}

/// Consumes the inspector and returns the recorded call traces.
pub fn into_traces(self) -> CallTraceArena {
self.traces
#[doc(hidden)]
#[deprecated = "use `traces` instead"]
pub const fn get_traces(&self) -> &CallTraceArena {
&self.traces
}

/// Gets a mutable reference to the recorded call traces.
pub fn traces_mut(&mut self) -> &mut CallTraceArena {
&mut self.traces
}

#[doc(hidden)]
#[deprecated = "use `traces_mut` instead"]
pub fn get_traces_mut(&mut self) -> &mut CallTraceArena {
&mut self.traces
}

/// Consumes the inspector and returns the recorded call traces.
pub fn into_traces(self) -> CallTraceArena {
self.traces
}

/// Manually the gas used of the root trace.
///
/// This is useful if the root trace's gasUsed should mirror the actual gas used by the
Expand Down
8 changes: 4 additions & 4 deletions tests/it/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,19 @@ fn test_geth_inspector_reset() {
},
);

assert_eq!(insp.get_traces().nodes().first().unwrap().trace.gas_limit, 0);
assert_eq!(insp.traces().nodes().first().unwrap().trace.gas_limit, 0);

// first run inspector
let (res, _) = inspect(&mut db, env.clone(), &mut insp).unwrap();
assert!(res.result.is_success());
assert_eq!(insp.get_traces().nodes().first().unwrap().trace.gas_limit, 1000000);
assert_eq!(insp.traces().nodes().first().unwrap().trace.gas_limit, 1000000);

// reset the inspector
insp.fuse();
assert_eq!(insp.get_traces().nodes().first().unwrap().trace.gas_limit, 0);
assert_eq!(insp.traces().nodes().first().unwrap().trace.gas_limit, 0);

// second run inspector after reset
let (res, _) = inspect(&mut db, env, &mut insp).unwrap();
assert!(res.result.is_success());
assert_eq!(insp.get_traces().nodes().first().unwrap().trace.gas_limit, 1000000);
assert_eq!(insp.traces().nodes().first().unwrap().trace.gas_limit, 1000000);
}
4 changes: 2 additions & 2 deletions tests/it/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ fn test_parity_selfdestruct(spec_id: SpecId) {
if spec_id < SpecId::CANCUN { (Some(value), Some(deployer)) } else { (None, None) };

{
assert_eq!(insp.get_traces().nodes().len(), 1);
let node = &insp.get_traces().nodes()[0];
assert_eq!(insp.traces().nodes().len(), 1);
let node = &insp.traces().nodes()[0];
assert!(node.is_selfdestruct(), "{node:#?}");
assert_eq!(node.trace.address, contract_address);
assert_eq!(node.trace.selfdestruct_refund_target, expected_target);
Expand Down
2 changes: 1 addition & 1 deletion tests/it/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn write_traces(tracer: &TracingInspector) -> String {

pub fn write_traces_with(tracer: &TracingInspector, color: ColorChoice) -> String {
let mut w = revm_inspectors::tracing::TraceWriter::new(Vec::<u8>::new()).use_colors(color);
w.write_arena(tracer.get_traces()).expect("failed to write traces to Vec<u8>");
w.write_arena(tracer.traces()).expect("failed to write traces to Vec<u8>");
String::from_utf8(w.into_writer()).expect("trace writer wrote invalid UTF-8")
}

Expand Down
Loading