Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jul 28, 2023
1 parent f888f03 commit 7c474b5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 35 deletions.
34 changes: 20 additions & 14 deletions crates/revm/revm-inspectors/src/tracing/builder/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use crate::tracing::{
TracingInspectorConfig,
};
use reth_primitives::{Address, Bytes, H256, U256};
use reth_rpc_types::trace::geth::{DefaultFrame, CallFrame, CallConfig, GethDefaultTracingOptions, StructLog, PreStateConfig, PreStateFrame, DiffMode, PreStateMode, AccountState};
use reth_rpc_types::trace::geth::{
AccountState, CallConfig, CallFrame, DefaultFrame, DiffMode, GethDefaultTracingOptions,
PreStateConfig, PreStateFrame, PreStateMode, StructLog,
};
use revm::{db::DatabaseRef, primitives::ResultAndState};
use std::collections::{BTreeMap, HashMap, VecDeque};
use revm::db::{DatabaseRef};
use revm::primitives::{ResultAndState};

/// A type for creating geth style traces
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -164,20 +166,25 @@ impl GethTraceBuilder {
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();
where
DB: DatabaseRef,
{
let account_diffs: Vec<_> =
state.into_iter().map(|(addr, acc)| (*addr, &acc.info)).collect();

if prestate_config.is_diff_mode(){
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();
prestate.0.insert(addr, AccountState {
balance: Some(db_acc.balance),
nonce: Some(U256::from(db_acc.nonce)),
code: db_acc.code.as_ref().map(|code| Bytes::from(code.original_bytes())),
storage: None,
});
prestate.0.insert(
addr,
AccountState {
balance: Some(db_acc.balance),
nonce: Some(U256::from(db_acc.nonce)),
code: db_acc.code.as_ref().map(|code| Bytes::from(code.original_bytes())),
storage: None,
},
);
}
self.update_storage_from_trace(&mut prestate.0, false);
Ok(PreStateFrame::Default(prestate))
Expand Down Expand Up @@ -216,4 +223,3 @@ impl GethTraceBuilder {
}
}
}

15 changes: 10 additions & 5 deletions crates/revm/revm-inspectors/src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::tracing::{config::TraceStyle, utils::convert_memory};
use reth_primitives::{abi::decode_revert_reason, bytes::Bytes, Address, H256, U256};
use reth_rpc_types::trace::{
geth::{CallFrame, CallLogFrame, GethDefaultTracingOptions, StructLog},
geth::{AccountState, CallFrame, CallLogFrame, GethDefaultTracingOptions, StructLog},
parity::{
Action, ActionType, CallAction, CallOutput, CallType, ChangedType, CreateAction,
CreateOutput, Delta, SelfdestructAction, StateDiff, TraceOutput, TransactionTrace,
Expand All @@ -14,7 +14,6 @@ use revm::interpreter::{
};
use serde::{Deserialize, Serialize};
use std::collections::{btree_map::Entry, BTreeMap, VecDeque};
use reth_rpc_types::trace::geth::AccountState;

/// A unified representation of a call
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -445,11 +444,17 @@ impl CallTraceNode {
call_frame
}

/// Adds storage in-place to account state for all accounts that were touched in the trace [CallTrace] execution.
/// Adds storage in-place to account state for all accounts that were touched in the trace
/// [CallTrace] execution.
///
/// * `account_states` - the account map updated in place.
/// * `post_value` - if true, it adds storage values after trace transaction execution, if false, returns the storage values before trace execution.
pub(crate) fn geth_update_account_storage(&self, account_states: &mut BTreeMap<Address, AccountState>, post_value: bool) {
/// * `post_value` - if true, it adds storage values after trace transaction execution, if
/// false, returns the storage values before trace execution.
pub(crate) fn geth_update_account_storage(
&self,
account_states: &mut BTreeMap<Address, AccountState>,
post_value: bool,
) {
let addr = self.trace.address;
let acc_state = account_states.entry(addr).or_insert_with(AccountState::default);
for change in self.trace.steps.iter().filter_map(|s| s.storage_change) {
Expand Down
6 changes: 4 additions & 2 deletions crates/rpc/rpc-types/src/eth/trace/geth/pre_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use reth_primitives::{serde_helper::num::from_int_or_hex_opt, Address, H256, U256, Bytes};
use reth_primitives::{serde_helper::num::from_int_or_hex_opt, Address, Bytes, H256, U256};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -48,7 +48,9 @@ pub struct PreStateConfig {
}

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

#[cfg(test)]
Expand Down
37 changes: 23 additions & 14 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
eth::{
error::{EthApiError, EthResult},
revm_utils::{
clone_into_empty_db, inspect, replay_transactions_until, result_output, EvmOverrides,
clone_into_empty_db, inspect, inspect_and_return_db, replay_transactions_until,
result_output, EvmOverrides,
},
EthTransactions, TransactionSource,
},
Expand Down Expand Up @@ -42,7 +43,6 @@ 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 @@ -259,17 +259,22 @@ where
let prestate_config = tracer_config
.into_pre_state_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;
let mut inspector = TracingInspector::new(TracingInspectorConfig::from_geth_config(&config));
let mut inspector = TracingInspector::new(
TracingInspectorConfig::from_geth_config(&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.into_geth_builder().geth_prestate_traces(&res, prestate_config, &db)?;
Ok(frame)
})
.await?;
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
.into_geth_builder()
.geth_prestate_traces(&res, prestate_config, &db)?;
Ok(frame)
})
.await?;
return Ok(frame.into())
}
GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()),
Expand Down Expand Up @@ -374,11 +379,15 @@ where
.map_err(|_| EthApiError::InvalidTracerConfig)?;

let mut inspector = TracingInspector::new(
TracingInspectorConfig::from_geth_config(&config)
TracingInspectorConfig::from_geth_config(&config),
);
let (res, _) = inspect(&mut *db, env, &mut inspector)?;

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

return Ok((frame.into(), res.state))
}
Expand Down

0 comments on commit 7c474b5

Please sign in to comment.