Skip to content

Commit

Permalink
Addressed some more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PlamenHristov committed Jul 27, 2023
1 parent 6804e6e commit 87cee89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 4 additions & 8 deletions crates/revm/revm-inspectors/src/tracing/builder/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ impl GethTraceBuilder {
pub fn geth_prestate_traces<DB>(
&self,
ResultAndState { state, .. }: &ResultAndState,
PreStateConfig { diff_mode }: PreStateConfig,
prestate_config: PreStateConfig,
db: DB,
) -> Result<PreStateFrame, DB::Error>
where DB: DatabaseRef {

let account_diffs: Vec<_> = state.into_iter().map(|(addr, acc)| (*addr, &acc.info)).collect();

if diff_mode.unwrap_or_default() {
if prestate_config.is_diff_mode(){
let mut prestate = PreStateMode::default();
for (addr, _) in account_diffs {
let db_acc = db.basic(addr)?.unwrap_or_default();
Expand Down Expand Up @@ -209,15 +209,11 @@ impl GethTraceBuilder {
fn update_storage_from_trace(
&self,
account_states: &mut BTreeMap<Address, AccountState>,
post_value: bool
post_value: bool,
) {
for node in self.iter_traceable_nodes() {
for node in self.nodes.iter() {
node.geth_update_account_storage(account_states, post_value);
}
}

fn iter_traceable_nodes(&self) -> impl Iterator<Item = &CallTraceNode> {
self.nodes.iter().filter(|node| !node.is_precompile())
}
}

11 changes: 11 additions & 0 deletions crates/rpc/rpc-types/src/eth/trace/geth/pre_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub struct PreStateConfig {
pub diff_mode: Option<bool>,
}

impl PreStateConfig {
pub fn is_diff_mode(&self) -> bool { self.diff_mode.unwrap_or_default() }
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -86,4 +90,11 @@ mod tests {
_ => unreachable!(),
}
}

#[test]
fn test_is_diff_mode() {
assert!(PreStateConfig { diff_mode: Some(true) }.is_diff_mode());
assert!(!PreStateConfig { diff_mode: Some(false) }.is_diff_mode());
assert!(!PreStateConfig { diff_mode: None }.is_diff_mode());
}
}
11 changes: 7 additions & 4 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use revm_primitives::{
use std::sync::Arc;
use tokio::sync::{mpsc, AcquireError, OwnedSemaphorePermit};
use tokio_stream::{wrappers::ReceiverStream, StreamExt};
use crate::eth::revm_utils::inspect_and_return_db;

/// `debug` API implementation.
///
Expand Down Expand Up @@ -262,13 +263,15 @@ where
.map_err(|_| EthApiError::InvalidTracerConfig)?;
let mut inspector = TracingInspector::new(TracingInspectorConfig::from_geth_config(&config));

let (res, _, db) = self
let frame = self
.inner
.eth_api
.inspect_call_at_and_return_state(call, at, overrides, &mut inspector)
.spawn_with_call_at(call, at, overrides, move |db, env| {
let (res, _, db) = inspect_and_return_db(db, env, &mut inspector)?;
let frame = inspector.into_geth_builder().geth_prestate_traces(&res, prestate_config, &db)?;
Ok(frame)
})
.await?;

let frame = inspector.into_geth_builder().geth_prestate_traces(&res, prestate_config, &db)?;
return Ok(frame.into())
}
GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()),
Expand Down

0 comments on commit 87cee89

Please sign in to comment.