diff --git a/src/eth/executor.rs b/src/eth/executor.rs index 01b25e0ad..f4db016b2 100644 --- a/src/eth/executor.rs +++ b/src/eth/executor.rs @@ -31,7 +31,7 @@ use crate::eth::primitives::Hash; use crate::eth::primitives::LogMined; use crate::eth::primitives::StoragePointInTime; use crate::eth::primitives::TransactionInput; -use crate::eth::storage::EthStorageError; +use crate::eth::storage::StorageError; use crate::eth::storage::StratusStorage; use crate::eth::BlockMiner; @@ -60,13 +60,13 @@ pub struct EthExecutor { impl EthExecutor { /// Creates a new executor. - pub fn new(evms: NonEmpty>, eth_storage: Arc) -> Self { + pub fn new(evms: NonEmpty>, storage: Arc) -> Self { let evm_tx = spawn_background_evms(evms); Self { evm_tx, - miner: Mutex::new(BlockMiner::new(Arc::clone(ð_storage))), - storage: eth_storage, + miner: Mutex::new(BlockMiner::new(Arc::clone(&storage))), + storage, block_notifier: broadcast::channel(NOTIFIER_CAPACITY).0, log_notifier: broadcast::channel(NOTIFIER_CAPACITY).0, } @@ -217,7 +217,7 @@ impl EthExecutor { let block = miner_lock.mine_with_one_transaction(transaction.clone(), execution.clone()).await?; match self.storage.commit_to_perm(block.clone()).await { Ok(()) => {} - Err(EthStorageError::Conflict(conflicts)) => { + Err(StorageError::Conflict(conflicts)) => { tracing::warn!(?conflicts, "storage conflict detected when saving block"); continue; } diff --git a/src/eth/rpc/rpc_server.rs b/src/eth/rpc/rpc_server.rs index c7b3c5a7a..d07a937c7 100644 --- a/src/eth/rpc/rpc_server.rs +++ b/src/eth/rpc/rpc_server.rs @@ -43,7 +43,7 @@ use crate::eth::EthExecutor; // ----------------------------------------------------------------------------- /// Starts JSON-RPC server. -pub async fn serve_rpc(executor: EthExecutor, eth_storage: Arc, config: StratusConfig) -> anyhow::Result<()> { +pub async fn serve_rpc(executor: EthExecutor, storage: Arc, config: StratusConfig) -> anyhow::Result<()> { // configure subscriptions let subs = Arc::new(RpcSubscriptions::default()); let subscriptions_cleaner_handle = Arc::clone(&subs).spawn_subscriptions_cleaner(); @@ -60,7 +60,7 @@ pub async fn serve_rpc(executor: EthExecutor, eth_storage: Arc, // services executor, - storage: eth_storage, + storage, // subscriptions subs, diff --git a/src/eth/storage/eth_storage.rs b/src/eth/storage/eth_storage.rs deleted file mode 100644 index d8081289c..000000000 --- a/src/eth/storage/eth_storage.rs +++ /dev/null @@ -1,5 +0,0 @@ -use async_trait::async_trait; - -/// EVM storage operations. -#[async_trait] -pub trait EthStorage: Send + Sync {} diff --git a/src/eth/storage/inmemory/inmemory.rs b/src/eth/storage/inmemory/inmemory.rs index e58ee5102..1e27b92c9 100644 --- a/src/eth/storage/inmemory/inmemory.rs +++ b/src/eth/storage/inmemory/inmemory.rs @@ -28,8 +28,8 @@ use crate::eth::primitives::StoragePointInTime; use crate::eth::primitives::TransactionMined; use crate::eth::storage::inmemory::InMemoryAccount; use crate::eth::storage::inmemory::InMemoryHistory; -use crate::eth::storage::EthStorageError; use crate::eth::storage::PermanentStorage; +use crate::eth::storage::StorageError; use crate::eth::storage::TemporaryStorage; /// In-memory implementation using maps. @@ -208,7 +208,7 @@ impl PermanentStorage for InMemoryStorage { Ok(logs) } - async fn save_block(&self, block: Block) -> anyhow::Result<(), EthStorageError> { + async fn save_block(&self, block: Block) -> anyhow::Result<(), StorageError> { let mut state = self.lock_write().await; // keep track of current block if we need to rollback @@ -231,7 +231,7 @@ impl PermanentStorage for InMemoryStorage { PermanentStorage::reset_at(self, current_block).await?; // inform error - return Err(EthStorageError::Conflict(conflicts)); + return Err(StorageError::Conflict(conflicts)); } // save transaction diff --git a/src/eth/storage/mod.rs b/src/eth/storage/mod.rs index 423cb184c..f260e630d 100644 --- a/src/eth/storage/mod.rs +++ b/src/eth/storage/mod.rs @@ -1,6 +1,5 @@ //! Ethereum / EVM storage. -mod eth_storage; mod inmemory; mod permanent_storage; mod postgres; @@ -10,6 +9,6 @@ mod temporary_storage; pub use inmemory::InMemoryStorage; pub use permanent_storage::PermanentStorage; -pub use storage_error::EthStorageError; +pub use storage_error::StorageError; pub use stratus_storage::StratusStorage; pub use temporary_storage::TemporaryStorage; diff --git a/src/eth/storage/permanent_storage.rs b/src/eth/storage/permanent_storage.rs index 3b60e730e..1e5812652 100644 --- a/src/eth/storage/permanent_storage.rs +++ b/src/eth/storage/permanent_storage.rs @@ -14,7 +14,7 @@ use crate::eth::primitives::Slot; use crate::eth::primitives::SlotIndex; use crate::eth::primitives::StoragePointInTime; use crate::eth::primitives::TransactionMined; -use crate::eth::storage::EthStorageError; +use crate::eth::storage::StorageError; /// Permanent (committed) storage operations #[async_trait] @@ -44,7 +44,7 @@ pub trait PermanentStorage: Send + Sync { async fn read_logs(&self, filter: &LogFilter) -> anyhow::Result>; /// Persists atomically all changes from a block. - async fn save_block(&self, block: Block) -> anyhow::Result<(), EthStorageError>; + async fn save_block(&self, block: Block) -> anyhow::Result<(), StorageError>; /// Persists initial accounts (test accounts or genesis accounts). async fn save_accounts(&self, accounts: Vec) -> anyhow::Result<()>; diff --git a/src/eth/storage/postgres/postgres.rs b/src/eth/storage/postgres/postgres.rs index be8087b0d..c5a065d3c 100644 --- a/src/eth/storage/postgres/postgres.rs +++ b/src/eth/storage/postgres/postgres.rs @@ -31,8 +31,8 @@ use crate::eth::primitives::TransactionMined; use crate::eth::storage::postgres::types::PostgresLog; use crate::eth::storage::postgres::types::PostgresTopic; use crate::eth::storage::postgres::types::PostgresTransaction; -use crate::eth::storage::EthStorageError; use crate::eth::storage::PermanentStorage; +use crate::eth::storage::StorageError; use crate::infra::postgres::Postgres; #[async_trait] @@ -427,7 +427,7 @@ impl PermanentStorage for Postgres { // byte arrays for numbers. Implementing the trait sqlx::Encode for the eth primitives would make // this much easier to work with (note: I tried implementing Encode for both Hash and Nonce and // neither worked for some reason I was not able to determine at this time) - async fn save_block(&self, block: Block) -> anyhow::Result<(), EthStorageError> { + async fn save_block(&self, block: Block) -> anyhow::Result<(), StorageError> { let mut tx = self.connection_pool.begin().await.context("failed to init save_block transaction")?; tracing::debug!(block = ?block, "saving block"); @@ -521,7 +521,7 @@ impl PermanentStorage for Postgres { // A successful insert/update with no conflicts will have one affected row if account_result.rows_affected() != 1 { tx.rollback().await.context("failed to rollback transaction")?; - let error: EthStorageError = EthStorageError::Conflict(ExecutionConflicts(nonempty![ExecutionConflict::Account { + let error: StorageError = StorageError::Conflict(ExecutionConflicts(nonempty![ExecutionConflict::Account { address: change.address, expected_balance: original_balance, expected_nonce: original_nonce, @@ -576,7 +576,7 @@ impl PermanentStorage for Postgres { // A successful insert/update with no conflicts will have one affected row if slot_result.rows_affected() != 1 { tx.rollback().await.context("failed to rollback transaction")?; - let error: EthStorageError = EthStorageError::Conflict(ExecutionConflicts(nonempty![ExecutionConflict::PgSlot { + let error: StorageError = StorageError::Conflict(ExecutionConflicts(nonempty![ExecutionConflict::PgSlot { address: change.address, slot: idx, expected: original_value, diff --git a/src/eth/storage/storage_error.rs b/src/eth/storage/storage_error.rs index 48654d0c4..155f27c67 100644 --- a/src/eth/storage/storage_error.rs +++ b/src/eth/storage/storage_error.rs @@ -1,7 +1,7 @@ use crate::eth::primitives::ExecutionConflicts; #[derive(Debug, thiserror::Error, derive_new::new)] -pub enum EthStorageError { +pub enum StorageError { /// Generic error interacting with the storage. #[error("Storage error: {0}")] Generic(#[from] anyhow::Error), diff --git a/src/eth/storage/stratus_storage.rs b/src/eth/storage/stratus_storage.rs index 510135e0b..f324ca6cc 100644 --- a/src/eth/storage/stratus_storage.rs +++ b/src/eth/storage/stratus_storage.rs @@ -17,8 +17,8 @@ use crate::eth::primitives::Slot; use crate::eth::primitives::SlotIndex; use crate::eth::primitives::StoragePointInTime; use crate::eth::primitives::TransactionMined; -use crate::eth::storage::EthStorageError; use crate::eth::storage::PermanentStorage; +use crate::eth::storage::StorageError; use crate::eth::storage::TemporaryStorage; use crate::infra::metrics; @@ -143,7 +143,7 @@ impl StratusStorage { } /// Commits changes to permanent storage and prepares temporary storage to a new block to be produced. - pub async fn commit_to_perm(&self, block: Block) -> anyhow::Result<(), EthStorageError> { + pub async fn commit_to_perm(&self, block: Block) -> anyhow::Result<(), StorageError> { let start = Instant::now(); let result = self.perm.save_block(block).await;