Skip to content

Commit

Permalink
narrow down
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Jul 31, 2024
1 parent 3589c76 commit f0fea88
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ pub struct CacheDB<ExtDB> {
/// `code` is always `None`, and bytecode can be found in `contracts`.
pub accounts: DbMap<Address, DbAccount>,
/// Tracks all contracts by their code hash.
pub contracts: DbMap<B256, Bytecode>,
pub contracts: HashMap<B256, Bytecode>,
/// All logs that were committed via [DatabaseCommit::commit].
pub logs: Vec<Log>,
/// All cached block hashes from the [DatabaseRef].
pub block_hashes: DbMap<U256, B256>,
pub block_hashes: HashMap<U256, B256>,
/// The underlying database ([DatabaseRef]) that is used to load data.
///
/// Note: this is read-only, data is never written to this database.
Expand All @@ -55,7 +55,7 @@ impl<ExtDB: Default> Default for CacheDB<ExtDB> {

impl<ExtDB> CacheDB<ExtDB> {
pub fn new(db: ExtDB) -> Self {
let mut contracts = DbMap::new();
let mut contracts = HashMap::new();
cfg_if::cfg_if! {
if #[cfg(not(feature = "scroll"))] {
contracts.insert(KECCAK_EMPTY, Bytecode::default());
Expand All @@ -68,7 +68,7 @@ impl<ExtDB> CacheDB<ExtDB> {
accounts: DbMap::new(),
contracts,
logs: Vec::default(),
block_hashes: DbMap::new(),
block_hashes: HashMap::new(),
db,
}
}
Expand Down Expand Up @@ -216,8 +216,8 @@ impl<ExtDB: DatabaseRef> Database for CacheDB<ExtDB> {

fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error> {
match self.contracts.entry(code_hash) {
DbMapEntry::Occupied(entry) => Ok(entry.get().clone()),
DbMapEntry::Vacant(entry) => {
Entry::Occupied(entry) => Ok(entry.get().clone()),
Entry::Vacant(entry) => {
// if you return code bytes when basic fn is called this function is not needed.
Ok(entry.insert(self.db.code_by_hash_ref(code_hash)?).clone())
}
Expand Down Expand Up @@ -266,8 +266,8 @@ impl<ExtDB: DatabaseRef> Database for CacheDB<ExtDB> {

fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
match self.block_hashes.entry(U256::from(number)) {
DbMapEntry::Occupied(entry) => Ok(*entry.get()),
DbMapEntry::Vacant(entry) => {
Entry::Occupied(entry) => Ok(*entry.get()),
Entry::Vacant(entry) => {
let hash = self.db.block_hash_ref(number)?;
entry.insert(hash);
Ok(hash)
Expand Down

0 comments on commit f0fea88

Please sign in to comment.