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
11 changes: 11 additions & 0 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use tokio::sync::RwLock as TokioRwLock;
use yansi::Paint;

pub use foundry_common::version::SHORT_VERSION as VERSION_MESSAGE;
use foundry_evm::traces::{CallTraceDecoderBuilder, identifier::SignaturesIdentifier};

/// Default port the rpc will open
pub const NODE_PORT: u16 = 8545;
Expand Down Expand Up @@ -1102,6 +1103,15 @@ impl NodeConfig {
genesis_init: self.genesis.clone(),
};

let mut decoder_builder = CallTraceDecoderBuilder::new();
if self.print_traces {
// if traces should get printed we configure the decoder with the signatures cache
if let Ok(identifier) = SignaturesIdentifier::new(false) {
debug!(target: "node", "using signature identifier");
decoder_builder = decoder_builder.with_signature_identifier(identifier);
}
}

// only memory based backend for now
let backend = mem::Backend::with_genesis(
db,
Expand All @@ -1112,6 +1122,7 @@ impl NodeConfig {
self.enable_steps_tracing,
self.print_logs,
self.print_traces,
Arc::new(decoder_builder.build()),
self.odyssey,
self.prune_history,
self.max_persisted_states,
Expand Down
9 changes: 7 additions & 2 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use anvil_core::eth::{
DepositReceipt, PendingTransaction, TransactionInfo, TypedReceipt, TypedTransaction,
},
};
use foundry_evm::{backend::DatabaseError, traces::CallTraceNode};
use foundry_evm::{
backend::DatabaseError,
traces::{CallTraceDecoder, CallTraceNode},
};
use foundry_evm_core::either_evm::EitherEvm;
use op_revm::{L1BlockInfo, OpContext, precompiles::OpPrecompiles};
use revm::{
Expand Down Expand Up @@ -119,6 +122,8 @@ pub struct TransactionExecutor<'a, Db: ?Sized, V: TransactionValidator> {
pub optimism: bool,
pub print_logs: bool,
pub print_traces: bool,
/// Recorder used for decoding traces, used together with print_traces
pub call_trace_decoder: Arc<CallTraceDecoder>,
/// Precompiles to inject to the EVM.
pub precompile_factory: Option<Arc<dyn PrecompileFactory>>,
pub blob_params: BlobParams,
Expand Down Expand Up @@ -367,7 +372,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> Iterator for &mut TransactionExec
};

if self.print_traces {
inspector.print_traces();
inspector.print_traces(self.call_trace_decoder.clone());
}
inspector.print_logs();

Expand Down
13 changes: 7 additions & 6 deletions crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use revm::{
interpreter::EthInterpreter,
},
};
use std::sync::Arc;

/// The [`revm::Inspector`] used when transacting in the evm
#[derive(Clone, Debug, Default)]
Expand All @@ -40,17 +41,17 @@ impl AnvilInspector {
}

/// Consumes the type and prints the traces.
pub fn into_print_traces(mut self) {
pub fn into_print_traces(mut self, decoder: Arc<CallTraceDecoder>) {
if let Some(a) = self.tracer.take() {
print_traces(a)
print_traces(a, decoder);
}
}

/// Called after the inspecting the evm
/// This will log all traces
pub fn print_traces(&self) {
pub fn print_traces(&self, decoder: Arc<CallTraceDecoder>) {
if let Some(a) = self.tracer.clone() {
print_traces(a)
print_traces(a, decoder);
}
}

Expand All @@ -60,6 +61,7 @@ impl AnvilInspector {
self
}

/// Configures the `TracingInspector` [`revm::Inspector`]
pub fn with_tracing_config(mut self, config: TracingInspectorConfig) -> Self {
self.tracer = Some(TracingInspector::new(config));
self
Expand Down Expand Up @@ -91,11 +93,10 @@ impl AnvilInspector {
/// # Panics
///
/// If called outside tokio runtime
fn print_traces(tracer: TracingInspector) {
fn print_traces(tracer: TracingInspector, decoder: Arc<CallTraceDecoder>) {
let arena = tokio::task::block_in_place(move || {
tokio::runtime::Handle::current().block_on(async move {
let mut arena = tracer.into_traces();
let decoder = CallTraceDecoder::new();
decoder.populate_traces(arena.nodes_mut()).await;
arena
})
Expand Down
15 changes: 10 additions & 5 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! In-memory blockchain backend.

use self::state::trie_storage;
use super::executor::new_evm_with_inspector_ref;
use crate::{
ForkChoice, NodeConfig, PrecompileFactory,
config::PruneStateHistoryConfig,
Expand Down Expand Up @@ -89,7 +90,7 @@ use foundry_evm::{
constants::DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE,
decode::RevertDecoder,
inspectors::AccessListInspector,
traces::TracingInspectorConfig,
traces::{CallTraceDecoder, TracingInspectorConfig},
utils::{get_blob_base_fee_update_fraction, get_blob_base_fee_update_fraction_by_spec_id},
};
use foundry_evm_core::either_evm::EitherEvm;
Expand Down Expand Up @@ -125,8 +126,6 @@ use std::{
use storage::{Blockchain, DEFAULT_HISTORY_LIMIT, MinedTransaction};
use tokio::sync::RwLock as AsyncRwLock;

use super::executor::new_evm_with_inspector_ref;

pub mod cache;
pub mod fork_db;
pub mod in_memory_db;
Expand Down Expand Up @@ -226,6 +225,8 @@ pub struct Backend {
enable_steps_tracing: bool,
print_logs: bool,
print_traces: bool,
/// Recorder used for decoding traces, used together with print_traces
call_trace_decoder: Arc<CallTraceDecoder>,
odyssey: bool,
/// How to keep history state
prune_state_history_config: PruneStateHistoryConfig,
Expand Down Expand Up @@ -255,6 +256,7 @@ impl Backend {
enable_steps_tracing: bool,
print_logs: bool,
print_traces: bool,
call_trace_decoder: Arc<CallTraceDecoder>,
odyssey: bool,
prune_state_history_config: PruneStateHistoryConfig,
max_persisted_states: Option<usize>,
Expand Down Expand Up @@ -360,6 +362,7 @@ impl Backend {
enable_steps_tracing,
print_logs,
print_traces,
call_trace_decoder,
odyssey,
prune_state_history_config,
transaction_block_keeper,
Expand Down Expand Up @@ -1211,7 +1214,7 @@ impl Backend {
inspector.print_logs();

if self.print_traces {
inspector.print_traces();
inspector.print_traces(self.call_trace_decoder.clone());
}

Ok((exit_reason, out, gas_used, state, logs.unwrap_or_default()))
Expand Down Expand Up @@ -1254,6 +1257,7 @@ impl Backend {
enable_steps_tracing: self.enable_steps_tracing,
print_logs: self.print_logs,
print_traces: self.print_traces,
call_trace_decoder: self.call_trace_decoder.clone(),
precompile_factory: self.precompile_factory.clone(),
odyssey: self.odyssey,
optimism: self.is_optimism(),
Expand Down Expand Up @@ -1340,6 +1344,7 @@ impl Backend {
enable_steps_tracing: self.enable_steps_tracing,
print_logs: self.print_logs,
print_traces: self.print_traces,
call_trace_decoder: self.call_trace_decoder.clone(),
odyssey: self.odyssey,
precompile_factory: self.precompile_factory.clone(),
optimism: self.is_optimism(),
Expand Down Expand Up @@ -1862,7 +1867,7 @@ impl Backend {
inspector.print_logs();

if self.print_traces {
inspector.into_print_traces();
inspector.into_print_traces(self.call_trace_decoder.clone());
}

Ok((exit_reason, out, gas_used as u128, state))
Expand Down
10 changes: 5 additions & 5 deletions crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,18 @@ impl CallTraceDecoder {
None
};

if let Some(func) = functions.first() {
return DecodedCallTrace {
return if let Some(func) = functions.first() {
DecodedCallTrace {
label,
call_data: Some(self.decode_function_input(trace, func)),
return_data,
};
}
} else {
return DecodedCallTrace {
DecodedCallTrace {
label,
call_data: self.fallback_call_data(trace),
return_data,
};
}
};
}

Expand Down
Loading