WIP: Implement prestateTracer (#3923)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Plamen Hristov
2023-07-28 13:05:38 +02:00
committed by GitHub
parent 703d5c705a
commit c04f3e443f
4 changed files with 160 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
use reth_primitives::{serde_helper::num::from_int_or_hex_opt, Address, H256, U256};
use reth_primitives::{serde_helper::num::from_int_or_hex_opt, Address, Bytes, H256, U256};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@@ -29,7 +29,7 @@ pub struct AccountState {
)]
pub balance: Option<U256>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
pub code: Option<Bytes>,
#[serde(
default,
deserialize_with = "from_int_or_hex_opt",
@@ -47,6 +47,12 @@ 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::*;
@@ -86,4 +92,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());
}
}

View File

@@ -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,
},
@@ -255,7 +256,26 @@ where
return Ok(frame)
}
GethDebugBuiltInTracerType::PreStateTracer => {
Err(EthApiError::Unsupported("pre state tracer currently unsupported."))
let prestate_config = tracer_config
.into_pre_state_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;
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?;
return Ok(frame.into())
}
GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()),
},
@@ -354,7 +374,22 @@ where
return Ok((frame.into(), res.state))
}
GethDebugBuiltInTracerType::PreStateTracer => {
Err(EthApiError::Unsupported("prestate tracer is unimplemented yet."))
let prestate_config = tracer_config
.into_pre_state_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;
let mut inspector = TracingInspector::new(
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,
)?;
return Ok((frame.into(), res.state))
}
GethDebugBuiltInTracerType::NoopTracer => {
Ok((NoopFrame::default().into(), Default::default()))