Skip to content

Commit

Permalink
feat: temporarily re-introduce custom trace printer (#7716)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Apr 18, 2024
1 parent 18e0d03 commit e97a35a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 3 additions & 7 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ pub struct RunArgs {
debug: bool,

/// Print out opcode traces.
#[deprecated]
#[arg(long, short, hide = true)]
#[arg(long, short)]
trace_printer: bool,

/// Executes the transaction only with the state from the previous block.
Expand Down Expand Up @@ -83,11 +82,6 @@ impl RunArgs {
///
/// Note: This executes the transaction(s) as is: Cheatcodes are disabled
pub async fn run(self) -> Result<()> {
#[allow(deprecated)]
if self.trace_printer {
eprintln!("WARNING: --trace-printer is deprecated and has no effect\n");
}

let figment =
Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc);
let evm_opts = figment.extract::<EvmOpts>()?;
Expand Down Expand Up @@ -214,6 +208,8 @@ impl RunArgs {

// Execute our transaction
let result = {
executor.set_trace_printer(self.trace_printer);

configure_tx_env(&mut env, &tx);

if let Some(to) = tx.to {
Expand Down
6 changes: 6 additions & 0 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ impl Executor {
self
}

#[inline]
pub fn set_trace_printer(&mut self, trace_printer: bool) -> &mut Self {
self.inspector.print(trace_printer);
self
}

#[inline]
pub fn set_gas_limit(&mut self, gas_limit: U256) -> &mut Self {
self.gas_limit = gas_limit;
Expand Down
19 changes: 19 additions & 0 deletions crates/evm/evm/src/inspectors/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use foundry_evm_core::{
use foundry_evm_coverage::HitMaps;
use foundry_evm_traces::CallTraceArena;
use revm::{
inspectors::CustomPrintTracer,
interpreter::{
CallInputs, CallOutcome, CallScheme, CreateInputs, CreateOutcome, Gas, InstructionResult,
Interpreter, InterpreterResult,
Expand Down Expand Up @@ -45,6 +46,8 @@ pub struct InspectorStackBuilder {
pub logs: Option<bool>,
/// Whether coverage info should be collected.
pub coverage: Option<bool>,
/// Whether to print all opcode traces into the console. Useful for debugging the EVM.
pub print: Option<bool>,
/// The chisel state inspector.
pub chisel_state: Option<usize>,
/// Whether to enable call isolation.
Expand Down Expand Up @@ -116,6 +119,13 @@ impl InspectorStackBuilder {
self
}

/// Set whether to enable the trace printer.
#[inline]
pub fn print(mut self, yes: bool) -> Self {
self.print = Some(yes);
self
}

/// Set whether to enable the tracer.
#[inline]
pub fn trace(mut self, yes: bool) -> Self {
Expand Down Expand Up @@ -144,6 +154,7 @@ impl InspectorStackBuilder {
debug,
logs,
coverage,
print,
chisel_state,
enable_isolation,
} = self;
Expand All @@ -162,6 +173,7 @@ impl InspectorStackBuilder {
stack.collect_coverage(coverage.unwrap_or(false));
stack.collect_logs(logs.unwrap_or(true));
stack.enable_debugger(debug.unwrap_or(false));
stack.print(print.unwrap_or(false));
stack.tracing(trace.unwrap_or(false));

stack.enable_isolation(enable_isolation);
Expand Down Expand Up @@ -273,6 +285,7 @@ pub struct InspectorStack {
pub debugger: Option<Debugger>,
pub fuzzer: Option<Fuzzer>,
pub log_collector: Option<LogCollector>,
pub printer: Option<CustomPrintTracer>,
pub tracer: Option<TracingInspector>,
pub enable_isolation: bool,

Expand Down Expand Up @@ -357,6 +370,12 @@ impl InspectorStack {
self.log_collector = yes.then(Default::default);
}

/// Set whether to enable the trace printer.
#[inline]
pub fn print(&mut self, yes: bool) {
self.printer = yes.then(Default::default);
}

/// Set whether to enable the tracer.
#[inline]
pub fn tracing(&mut self, yes: bool) {
Expand Down

0 comments on commit e97a35a

Please sign in to comment.