Skip to content

Commit

Permalink
feat: remove check_conflicts from TemporaryStorage because it is not …
Browse files Browse the repository at this point in the history
…working (#262)
  • Loading branch information
dinhani-cw authored Feb 22, 2024
1 parent 394a247 commit a80f61c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 61 deletions.
4 changes: 0 additions & 4 deletions src/eth/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ impl EthExecutor {
// execute and check conflicts before mining block
let evm_input = EvmInput::from_eth_transaction(transaction.clone());
let execution = self.execute_in_evm(evm_input).await?;
if let Some(conflicts) = self.storage.check_conflicts(&execution).await? {
tracing::warn!(?conflicts, "storage conflict detected before mining block");
continue;
}

// mine and commit block
let mut miner_lock = self.miner.lock().await;
Expand Down
44 changes: 0 additions & 44 deletions src/eth/storage/inmemory/inmemory_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use crate::eth::primitives::Account;
use crate::eth::primitives::Address;
use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::Execution;
use crate::eth::primitives::ExecutionConflicts;
use crate::eth::primitives::ExecutionConflictsBuilder;
use crate::eth::primitives::Slot;
use crate::eth::primitives::SlotIndex;
use crate::eth::primitives::StoragePointInTime;
Expand Down Expand Up @@ -44,48 +42,6 @@ impl InMemoryStorageTemporary {

#[async_trait]
impl TemporaryStorage for InMemoryStorageTemporary {
// -------------------------------------------------------------------------
// State operations
// ------------------------------------------------------------------------

async fn check_conflicts(&self, execution: &Execution) -> anyhow::Result<Option<ExecutionConflicts>> {
let state = self.lock_read().await;
let mut conflicts = ExecutionConflictsBuilder::default();

for change in &execution.changes {
let address = &change.address;

if let Some(account) = state.accounts.get(address) {
// check account info conflicts
if let Some(touched_nonce) = change.nonce.take_original_ref() {
let nonce = account.get_current_nonce();
if touched_nonce != nonce {
conflicts.add_nonce(address.clone(), nonce.clone(), touched_nonce.clone());
}
}
if let Some(touched_balance) = change.balance.take_original_ref() {
let balance = account.get_current_balance();
if touched_balance != balance {
conflicts.add_balance(address.clone(), balance.clone(), touched_balance.clone());
}
}

// check slots conflicts
for (touched_slot_index, touched_slot) in &change.slots {
if let Some(slot) = account.get_current_slot(touched_slot_index) {
if let Some(touched_slot) = touched_slot.take_original_ref() {
let slot_value = slot.value.clone();
if touched_slot.value != slot_value {
conflicts.add_slot(address.clone(), touched_slot_index.clone(), slot_value, touched_slot.value.clone());
}
}
}
}
}
}
Ok(conflicts.build())
}

async fn maybe_read_account(&self, address: &Address, _point_in_time: &StoragePointInTime) -> anyhow::Result<Option<Account>> {
tracing::debug!(%address, "reading account");

Expand Down
9 changes: 0 additions & 9 deletions src/eth/storage/stratus_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::eth::primitives::Block;
use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::BlockSelection;
use crate::eth::primitives::Execution;
use crate::eth::primitives::ExecutionConflicts;
use crate::eth::primitives::Hash;
use crate::eth::primitives::LogFilter;
use crate::eth::primitives::LogMined;
Expand Down Expand Up @@ -68,14 +67,6 @@ impl StratusStorage {
// State queries
// -------------------------------------------------------------------------

/// Checks if the transaction execution conflicts with the current storage state.
pub async fn check_conflicts(&self, execution: &Execution) -> anyhow::Result<Option<ExecutionConflicts>> {
let start = Instant::now();
let result = self.temp.check_conflicts(execution).await;
metrics::inc_storage_check_conflicts(start.elapsed(), result.as_ref().is_ok_and(|v| v.is_some()), result.is_ok());
result
}

/// Retrieves an account from the storage. Returns default value when not found.
pub async fn read_account(&self, address: &Address, point_in_time: &StoragePointInTime) -> anyhow::Result<Account> {
let start = Instant::now();
Expand Down
4 changes: 0 additions & 4 deletions src/eth/storage/temporary_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ use crate::eth::primitives::Account;
use crate::eth::primitives::Address;
use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::Execution;
use crate::eth::primitives::ExecutionConflicts;
use crate::eth::primitives::Slot;
use crate::eth::primitives::SlotIndex;
use crate::eth::primitives::StoragePointInTime;

/// Temporary storage (in-between blocks) operations
#[async_trait]
pub trait TemporaryStorage: Send + Sync {
/// Checks if the transaction execution conflicts with the current storage state.
async fn check_conflicts(&self, execution: &Execution) -> anyhow::Result<Option<ExecutionConflicts>>;

/// Retrieves an account from the storage. Returns Option when not found.
async fn maybe_read_account(&self, address: &Address, point_in_time: &StoragePointInTime) -> anyhow::Result<Option<Account>>;

Expand Down

0 comments on commit a80f61c

Please sign in to comment.