Skip to content
Open
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
29 changes: 14 additions & 15 deletions crates/evm/core/src/fork/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,18 @@ pub struct ForkDbStateSnapshot<N: Network> {
}

impl<N: Network> ForkDbStateSnapshot<N> {
fn get_storage(&self, address: Address, index: U256) -> Option<U256> {
self.local
.cache
.accounts
.get(&address)
.and_then(|account| account.storage.get(&index))
.copied()
/// Lookup storage in `state_snapshot`, then fall back to the backend (remote RPC).
fn storage_from_snapshot_or_backend(
&self,
address: Address,
index: U256,
) -> Result<U256, DatabaseError> {
// Check state_snapshot.storage first (data fetched by SharedBackend / disk cache).
if let Some(val) = self.state_snapshot.storage.get(&address).and_then(|s| s.get(&index)) {
return Ok(*val);
}
// Fall back to the underlying backend (SharedBackend → remote RPC).
DatabaseRef::storage_ref(&self.local, address, index)
}
}

Expand Down Expand Up @@ -249,15 +254,9 @@ impl<N: Network> DatabaseRef for ForkDbStateSnapshot<N> {
match self.local.cache.accounts.get(&address) {
Some(account) => match account.storage.get(&index) {
Some(entry) => Ok(*entry),
None => match self.get_storage(address, index) {
None => DatabaseRef::storage_ref(&self.local, address, index),
Some(storage) => Ok(storage),
},
},
None => match self.get_storage(address, index) {
None => DatabaseRef::storage_ref(&self.local, address, index),
Some(storage) => Ok(storage),
None => self.storage_from_snapshot_or_backend(address, index),
},
None => self.storage_from_snapshot_or_backend(address, index),
}
}

Expand Down
Loading