Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions crates/revm/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::primitives::alloy_primitives::{BlockNumber, StorageKey, StorageValue};
use core::ops::{Deref, DerefMut};
use reth_primitives::{Account, Address, B256, KECCAK_EMPTY, U256};
use reth_primitives::{Account, Address, B256, U256};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use revm::{
db::DatabaseRef,
Expand Down Expand Up @@ -134,12 +134,7 @@ impl<DB: EvmStateProvider> DatabaseRef for StateProviderDatabase<DB> {
/// 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<Option<AccountInfo>, Self::Error> {
Ok(self.basic_account(address)?.map(|account| AccountInfo {
balance: account.balance,
nonce: account.nonce,
code_hash: account.bytecode_hash.unwrap_or(KECCAK_EMPTY),
code: None,
}))
Ok(self.basic_account(address)?.map(Into::into))
}

/// Retrieves the bytecode associated with a given code hash.
Expand All @@ -160,13 +155,10 @@ impl<DB: EvmStateProvider> DatabaseRef for StateProviderDatabase<DB> {
///
/// Returns `Ok` with the block hash if found, or the default hash otherwise.
fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
// Attempt to convert U256 to u64
let block_number = match number.try_into() {
Ok(value) => value,
Err(_) => return Err(Self::Error::BlockNumberOverflow(number)),
};

// Get the block hash or default hash
Ok(self.0.block_hash(block_number)?.unwrap_or_default())
// Get the block hash or default hash with an attempt to convert U256 block number to u64
Ok(self
.0
.block_hash(number.try_into().map_err(|_| Self::Error::BlockNumberOverflow(number))?)?
.unwrap_or_default())
}
}