Skip to content

Commit

Permalink
refactor: reorder InMemoryTemporaryStorage methods to match trait ord…
Browse files Browse the repository at this point in the history
…er (#1238)
  • Loading branch information
dinhani-cw authored Jun 25, 2024
1 parent 161e710 commit 2f0c6d3
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/eth/storage/inmemory/inmemory_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ impl InMemoryTemporaryAccount {
}

impl TemporaryStorage for InMemoryTemporaryStorage {
// -------------------------------------------------------------------------
// Accounts and Slots
// -------------------------------------------------------------------------

fn read_account(&self, address: &Address) -> anyhow::Result<Option<Account>> {
let states = self.lock_read();
Ok(read_account(&states, address))
}

fn read_slot(&self, address: &Address, index: &SlotIndex) -> anyhow::Result<Option<Slot>> {
let states = self.lock_read();
Ok(read_slot(&states, address, index))
}

// -------------------------------------------------------------------------
// Block number
// -------------------------------------------------------------------------
Expand All @@ -151,7 +137,7 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
}

// -------------------------------------------------------------------------
// External block
// Block and executions
// -------------------------------------------------------------------------

fn set_active_external_block(&self, block: ExternalBlock) -> anyhow::Result<()> {
Expand All @@ -160,10 +146,6 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
Ok(())
}

// -------------------------------------------------------------------------
// Executions
// -------------------------------------------------------------------------

fn save_execution(&self, tx: TransactionExecution) -> anyhow::Result<()> {
// check conflicts
let mut states = self.lock_write();
Expand Down Expand Up @@ -207,15 +189,6 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
Ok(())
}

// -------------------------------------------------------------------------
// General state
// -------------------------------------------------------------------------

fn check_conflicts(&self, execution: &EvmExecution) -> anyhow::Result<Option<ExecutionConflicts>> {
let states = self.lock_read();
Ok(check_conflicts(&states, execution))
}

/// TODO: we cannot allow more than one pending block. Where to put this check?
fn finish_block(&self) -> anyhow::Result<PendingBlock> {
let mut states = self.lock_write();
Expand All @@ -233,6 +206,28 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
Ok(finished_block)
}

// -------------------------------------------------------------------------
// Accounts and Slots
// -------------------------------------------------------------------------

fn check_conflicts(&self, execution: &EvmExecution) -> anyhow::Result<Option<ExecutionConflicts>> {
let states = self.lock_read();
Ok(check_conflicts(&states, execution))
}

fn read_account(&self, address: &Address) -> anyhow::Result<Option<Account>> {
let states = self.lock_read();
Ok(read_account(&states, address))
}

fn read_slot(&self, address: &Address, index: &SlotIndex) -> anyhow::Result<Option<Slot>> {
let states = self.lock_read();
Ok(read_slot(&states, address, index))
}

// -------------------------------------------------------------------------
// Global state
// -------------------------------------------------------------------------
fn reset(&self) -> anyhow::Result<()> {
let mut state = self.lock_write();
state.tail.clear();
Expand Down

0 comments on commit 2f0c6d3

Please sign in to comment.