Skip to content

Commit

Permalink
feat(rpc): add support for muxTracer (#7053)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialPB authored Mar 8, 2024
1 parent bf948d1 commit 486945f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ reth-trie-parallel = { path = "crates/trie-parallel" }
# revm
revm = { version = "6.1.0", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { version = "2.1.0", features = ["std"], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "7cdbe2e" }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "f0551cb" }

# eth
alloy-chains = { version = "0.1", feature = ["serde", "rlp", "arbitrary"] }
Expand All @@ -197,12 +197,12 @@ alloy-dyn-abi = "0.6"
alloy-sol-types = "0.6"
alloy-rlp = "0.3"
alloy-trie = "0.3"
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "975a52a" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }
alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }
alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "64d0352" }

# TODO: Remove
ethers-core = { version = "2.0.14", default-features = false }
Expand Down
35 changes: 32 additions & 3 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use revm::{
};
use revm_inspectors::tracing::{
js::{JsInspector, TransactionContext},
FourByteInspector, TracingInspector, TracingInspectorConfig,
FourByteInspector, MuxInspector, TracingInspector, TracingInspectorConfig,
};
use std::sync::Arc;
use tokio::sync::{AcquireError, OwnedSemaphorePermit};
Expand Down Expand Up @@ -339,6 +339,24 @@ where
return Ok(frame.into())
}
GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()),
GethDebugBuiltInTracerType::MuxTracer => {
let mux_config = tracer_config
.into_mux_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;

let mut inspector = MuxInspector::try_from_config(mux_config)?;

let frame = self
.inner
.eth_api
.spawn_with_call_at(call, at, overrides, move |db, env| {
let (res, _, db) = inspect_and_return_db(db, env, &mut inspector)?;
let frame = inspector.try_into_mux_frame(&res, &db)?;
Ok(frame.into())
})
.await?;
return Ok(frame)
}
},
GethDebugTracerType::JsTracer(code) => {
let config = tracer_config.into_json();
Expand Down Expand Up @@ -545,19 +563,30 @@ where
// which we need to record steps and statediff
.set_steps_and_state_diffs(prestate_config.is_default_mode()),
);
let (res, _) = inspect(&mut *db, env, &mut inspector)?;
let (res, _, db) = inspect_and_return_db(db, env, &mut inspector)?;

let frame = inspector.into_geth_builder().geth_prestate_traces(
&res,
prestate_config,
&*db,
db,
)?;

return Ok((frame.into(), res.state))
}
GethDebugBuiltInTracerType::NoopTracer => {
Ok((NoopFrame::default().into(), Default::default()))
}
GethDebugBuiltInTracerType::MuxTracer => {
let mux_config = tracer_config
.into_mux_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;

let mut inspector = MuxInspector::try_from_config(mux_config)?;

let (res, _, db) = inspect_and_return_db(db, env, &mut inspector)?;
let frame = inspector.try_into_mux_frame(&res, db)?;
return Ok((frame.into(), res.state))
}
},
GethDebugTracerType::JsTracer(code) => {
let config = tracer_config.into_json();
Expand Down
6 changes: 5 additions & 1 deletion crates/rpc/rpc/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpsee::{
};
use reth_interfaces::RethError;
use reth_primitives::{revm_primitives::InvalidHeader, Address, Bytes, U256};
use reth_revm::tracing::js::JsInspectorError;
use reth_revm::tracing::{js::JsInspectorError, MuxError};
use reth_rpc_types::{error::EthRpcErrorCode, request::TransactionInputError, BlockError};
use reth_transaction_pool::error::{
Eip4844PoolTransactionError, InvalidPoolTransactionError, PoolError, PoolErrorKind,
Expand Down Expand Up @@ -116,6 +116,9 @@ pub enum EthApiError {
/// Error encountered when converting a transaction type
#[error("Transaction conversion error")]
TransactionConversionError,
/// Error thrown when tracing with a muxTracer fails
#[error(transparent)]
MuxTracerError(#[from] MuxError),
}

/// Eth Optimism Api Error
Expand Down Expand Up @@ -183,6 +186,7 @@ impl From<EthApiError> for ErrorObject<'static> {
OptimismEthApiError::L1BlockFeeError |
OptimismEthApiError::L1BlockGasError => internal_rpc_err(err.to_string()),
},
EthApiError::MuxTracerError(msg) => internal_rpc_err(msg.to_string()),
}
}
}
Expand Down

0 comments on commit 486945f

Please sign in to comment.