diff --git a/crates/revm/src/database.rs b/crates/revm/src/database.rs index 3ff3f427e555..3bd922287d6e 100644 --- a/crates/revm/src/database.rs +++ b/crates/revm/src/database.rs @@ -6,6 +6,7 @@ use revm::{ primitives::{AccountInfo, Bytecode}, Database, StateDBBox, }; +use std::ops::{Deref, DerefMut}; /// SubState of database. Uses revm internal cache with binding to reth StateProvider trait. pub type SubState = CacheDB>; @@ -23,19 +24,23 @@ impl StateProviderDatabase { Self(db) } - /// Return inner state reference - pub fn state(&self) -> &DB { - &self.0 + /// Consume State and return inner StateProvider. + pub fn into_inner(self) -> DB { + self.0 } +} - /// Return inner state mutable reference - pub fn state_mut(&mut self) -> &mut DB { - &mut self.0 +impl Deref for StateProviderDatabase { + type Target = DB; + + fn deref(&self) -> &Self::Target { + &self.0 } +} - /// Consume State and return inner StateProvider. - pub fn into_inner(self) -> DB { - self.0 +impl DerefMut for StateProviderDatabase { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 } } @@ -81,7 +86,7 @@ impl DatabaseRef for StateProviderDatabase { /// Returns `Ok` with `Some(AccountInfo)` if the account exists, /// `None` if it doesn't, or an error if encountered. fn basic_ref(&self, address: Address) -> Result, Self::Error> { - Ok(self.0.basic_account(address)?.map(|account| AccountInfo { + Ok(self.basic_account(address)?.map(|account| AccountInfo { balance: account.balance, nonce: account.nonce, code_hash: account.bytecode_hash.unwrap_or(KECCAK_EMPTY), @@ -93,7 +98,7 @@ impl DatabaseRef for StateProviderDatabase { /// /// Returns `Ok` with the bytecode if found, or the default bytecode otherwise. fn code_by_hash_ref(&self, code_hash: B256) -> Result { - Ok(self.0.bytecode_by_hash(code_hash)?.unwrap_or_default().0) + Ok(self.bytecode_by_hash(code_hash)?.unwrap_or_default().0) } /// Retrieves the storage value at a specific index for a given address. diff --git a/crates/rpc/rpc/src/eth/api/call.rs b/crates/rpc/rpc/src/eth/api/call.rs index ee5a2449c443..c91665c3968f 100644 --- a/crates/rpc/rpc/src/eth/api/call.rs +++ b/crates/rpc/rpc/src/eth/api/call.rs @@ -215,7 +215,7 @@ where // if the request is a simple transfer we can optimize if env.tx.data.is_empty() { if let TransactTo::Call(to) = env.tx.transact_to { - if let Ok(code) = db.db.state().account_code(to) { + if let Ok(code) = db.db.account_code(to) { let no_code_callee = code.map(|code| code.is_empty()).unwrap_or(true); if no_code_callee { // simple transfer, check if caller has sufficient funds @@ -427,13 +427,8 @@ where // calculate the gas used using the access list request.access_list = Some(access_list.clone()); - let gas_used = self.estimate_gas_with( - cfg_with_spec_id, - env.block.clone(), - request, - db.db.state(), - None, - )?; + let gas_used = + self.estimate_gas_with(cfg_with_spec_id, env.block.clone(), request, &*db.db, None)?; Ok(AccessListWithGasUsed { access_list, gas_used }) }