Skip to content
Closed
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
24 changes: 16 additions & 8 deletions src/db/cow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,15 @@ impl<Db: DatabaseRef> Database for CacheOnWrite<Db> {
}

fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
if let Some(storage) =
self.cache.accounts.get(&address).map(|a| a.storage.get(&index).cloned())
{
return Ok(storage.unwrap_or_default());
// Check if account exists in cache
if let Some(account) = self.cache.accounts.get(&address) {
// If the specific storage slot is in cache, return it
if let Some(value) = account.storage.get(&index) {
return Ok(*value);
}
// Account is in cache but storage slot is not - fall through to query inner DB
}
// Cache miss (no account) or partial cache miss (no storage slot) - query inner DB
self.inner.storage_ref(address, index)
}

Expand Down Expand Up @@ -207,11 +211,15 @@ impl<Db: DatabaseRef> DatabaseRef for CacheOnWrite<Db> {
}

fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
if let Some(storage) =
self.cache.accounts.get(&address).map(|a| a.storage.get(&index).cloned())
{
return Ok(storage.unwrap_or_default());
// Check if account exists in cache
if let Some(account) = self.cache.accounts.get(&address) {
// If the specific storage slot is in cache, return it
if let Some(value) = account.storage.get(&index) {
return Ok(*value);
}
// Account is in cache but storage slot is not - fall through to query inner DB
}
// Cache miss (no account) or partial cache miss (no storage slot) - query inner DB
self.inner.storage_ref(address, index)
}

Expand Down