Skip to content

Commit

Permalink
chore: phase out reth-primitives from inspectors (#5552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 23, 2023
1 parent 5ab2cf6 commit 337fb31
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/revm/revm-inspectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = "revm inspector implementations used by reth"

[dependencies]
# reth
reth-primitives.workspace = true
reth-rpc-types.workspace = true

# eth
Expand Down
17 changes: 5 additions & 12 deletions crates/revm/revm-inspectors/src/tracing/js/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ use boa_engine::{
Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsValue,
};
use boa_gc::{empty_trace, Finalize, Trace};
use reth_primitives::Account;
use revm::{
interpreter::{
opcode::{PUSH0, PUSH32},
OpCode, SharedMemory, Stack,
},
primitives::{State, KECCAK_EMPTY},
primitives::{AccountInfo, State, KECCAK_EMPTY},
};
use std::{cell::RefCell, rc::Rc, sync::mpsc::channel};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -298,14 +297,8 @@ impl StateRef {
(StateRef(inner), guard)
}

fn get_account(&self, address: &Address) -> Option<Account> {
self.0.with_inner(|state| {
state.get(address).map(|acc| Account {
nonce: acc.info.nonce,
balance: acc.info.balance,
bytecode_hash: Some(acc.info.code_hash),
})
})?
fn get_account(&self, address: &Address) -> Option<AccountInfo> {
self.0.with_inner(|state| state.get(address).map(|acc| acc.info.clone()))?
}
}

Expand Down Expand Up @@ -708,7 +701,7 @@ impl EvmDbRef {
(this, guard)
}

fn read_basic(&self, address: JsValue, ctx: &mut Context<'_>) -> JsResult<Option<Account>> {
fn read_basic(&self, address: JsValue, ctx: &mut Context<'_>) -> JsResult<Option<AccountInfo>> {
let buf = from_buf(address, ctx)?;
let address = bytes_to_address(buf);
if let acc @ Some(_) = self.state.get_account(&address) {
Expand All @@ -733,7 +726,7 @@ impl EvmDbRef {

fn read_code(&self, address: JsValue, ctx: &mut Context<'_>) -> JsResult<JsArrayBuffer> {
let acc = self.read_basic(address, ctx)?;
let code_hash = acc.and_then(|acc| acc.bytecode_hash).unwrap_or(KECCAK_EMPTY);
let code_hash = acc.map(|acc| acc.code_hash).unwrap_or(KECCAK_EMPTY);
if code_hash == KECCAK_EMPTY {
return JsArrayBuffer::new(0, ctx)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/revm/revm-inspectors/src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ use crate::tracing::{
};
use alloy_primitives::{Address, Bytes, B256, U256};
use boa_engine::{Context, JsError, JsObject, JsResult, JsValue, Source};
use reth_primitives::Account;
use revm::{
interpreter::{
return_revert, CallInputs, CallScheme, CreateInputs, Gas, InstructionResult, Interpreter,
},
precompile::Precompiles,
primitives::{Env, ExecutionResult, Output, ResultAndState, TransactTo},
primitives::{AccountInfo, Env, ExecutionResult, Output, ResultAndState, TransactTo},
Database, EVMData, Inspector,
};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -484,7 +483,7 @@ pub enum JsDbRequest {
/// The address of the account to be loaded
address: Address,
/// The response channel
resp: std::sync::mpsc::Sender<Result<Option<Account>, String>>,
resp: std::sync::mpsc::Sender<Result<Option<AccountInfo>, String>>,
},
/// Bindings for [Database::code_by_hash]
Code {
Expand Down
13 changes: 2 additions & 11 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_primitives::{
db::{DatabaseCommit, DatabaseRef},
BlockEnv, CfgEnv,
},
Account, Address, Block, BlockId, BlockNumberOrTag, Bytes, TransactionSigned, B256,
Address, Block, BlockId, BlockNumberOrTag, Bytes, TransactionSigned, B256,
};
use reth_provider::{BlockReaderIdExt, HeaderProvider, StateProviderBox};
use reth_revm::{
Expand Down Expand Up @@ -610,16 +610,7 @@ where
while let Some(req) = stream.next().await {
match req {
JsDbRequest::Basic { address, resp } => {
let acc = db
.basic_ref(address)
.map(|maybe_acc| {
maybe_acc.map(|acc| Account {
nonce: acc.nonce,
balance: acc.balance,
bytecode_hash: Some(acc.code_hash),
})
})
.map_err(|err| err.to_string());
let acc = db.basic_ref(address).map_err(|err| err.to_string());
let _ = resp.send(acc);
}
JsDbRequest::Code { code_hash, resp } => {
Expand Down

0 comments on commit 337fb31

Please sign in to comment.