Skip to content

Commit

Permalink
make evaluation lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw committed Dec 6, 2024
1 parent e3ccb0e commit 28d7f42
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/eth/storage/temporary/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,38 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
// -------------------------------------------------------------------------

fn read_account(&self, address: Address) -> anyhow::Result<Option<Account>> {
Ok(self
.pending_block
.read()
.unwrap()
.accounts
.get(&address)
.or(self.latest_block.read().unwrap().as_ref().and_then(|latest| latest.accounts.get(&address)))
.map(|account| account.info.clone()))
Ok(match self.pending_block.read().unwrap().accounts.get(&address) {
Some(pending_account) => Some(pending_account.info.clone()),
None => self
.latest_block
.read()
.unwrap()
.as_ref()
.and_then(|latest| latest.accounts.get(&address))
.map(|account| account.info.clone()),
})
}

fn read_slot(&self, address: Address, index: SlotIndex) -> anyhow::Result<Option<Slot>> {
Ok(self
.pending_block
.read()
.unwrap()
.accounts
.get(&address)
.and_then(|account| account.slots.get(&index))
.or(self
.latest_block
Ok(
match self
.pending_block
.read()
.unwrap()
.as_ref()
.and_then(|latest| latest.accounts.get(&address).and_then(|account| account.slots.get(&index))))
.copied())
.accounts
.get(&address)
.and_then(|account| account.slots.get(&index))
{
Some(pending_slot) => Some(*pending_slot),
None => self
.latest_block
.read()
.unwrap()
.as_ref()
.and_then(|latest| latest.accounts.get(&address).and_then(|account| account.slots.get(&index)))
.copied(),
},
)
}

// -------------------------------------------------------------------------
Expand Down

0 comments on commit 28d7f42

Please sign in to comment.