diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index f7c79504c..3b8511868 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -514,7 +514,10 @@ impl Command { Ok(handle) } - fn lookup_head(&self, db: Arc>) -> Result { + fn lookup_head( + &self, + db: Arc>, + ) -> Result { db.view(|tx| { let head = FINISH.get_progress(tx)?.unwrap_or_default(); let header = tx @@ -526,7 +529,7 @@ impl Command { let hash = tx .get::(head)? .expect("the hash for the latest block is missing, database is corrupt"); - Ok::(Head { + Ok::(Head { number: head, hash, difficulty: header.difficulty, @@ -567,7 +570,7 @@ impl Command { DB: Database, Client: HeadersClient, { - let header = db.view(|tx| -> Result, reth_db::Error> { + let header = db.view(|tx| -> Result, reth_db::DatabaseError> { let number = match tip { BlockHashOrNumber::Hash(hash) => tx.get::(hash)?, BlockHashOrNumber::Number(number) => Some(number), diff --git a/bin/reth/src/test_eth_chain/runner.rs b/bin/reth/src/test_eth_chain/runner.rs index 3351ecf43..17ff1802b 100644 --- a/bin/reth/src/test_eth_chain/runner.rs +++ b/bin/reth/src/test_eth_chain/runner.rs @@ -7,7 +7,7 @@ use reth_db::{ mdbx::test_utils::create_test_rw_db, tables, transaction::{DbTx, DbTxMut}, - Error as DbError, + DatabaseError as DbError, }; use reth_primitives::{ keccak256, Account as RethAccount, Address, Bytecode, ChainSpec, JsonU256, SealedBlock, diff --git a/crates/consensus/beacon/src/engine/error.rs b/crates/consensus/beacon/src/engine/error.rs index 89280cbf2..ecbb9b164 100644 --- a/crates/consensus/beacon/src/engine/error.rs +++ b/crates/consensus/beacon/src/engine/error.rs @@ -29,8 +29,8 @@ impl From for BeaconConsensusEngineError { } // for convenience in the beacon engine -impl From for BeaconConsensusEngineError { - fn from(e: reth_interfaces::db::Error) -> Self { +impl From for BeaconConsensusEngineError { + fn from(e: reth_interfaces::db::DatabaseError) -> Self { Self::Common(e.into()) } } @@ -57,8 +57,8 @@ impl From for BeaconForkChoiceUpdateError { Self::Internal(Box::new(e)) } } -impl From for BeaconForkChoiceUpdateError { - fn from(e: reth_interfaces::db::Error) -> Self { +impl From for BeaconForkChoiceUpdateError { + fn from(e: reth_interfaces::db::DatabaseError) -> Self { Self::Internal(Box::new(e.into())) } } diff --git a/crates/interfaces/src/db.rs b/crates/interfaces/src/db.rs index 3beb93f2e..0607b91b6 100644 --- a/crates/interfaces/src/db.rs +++ b/crates/interfaces/src/db.rs @@ -1,6 +1,6 @@ /// Database error type. They are using u32 to represent error code. #[derive(Debug, thiserror::Error, PartialEq, Eq, Clone)] -pub enum Error { +pub enum DatabaseError { /// Failed to open database. #[error("Failed to open database: {0:?}")] FailedToOpen(i32), diff --git a/crates/interfaces/src/error.rs b/crates/interfaces/src/error.rs index 4d54bfeb2..7e6e2d618 100644 --- a/crates/interfaces/src/error.rs +++ b/crates/interfaces/src/error.rs @@ -12,7 +12,7 @@ pub enum Error { Consensus(#[from] crate::consensus::ConsensusError), #[error(transparent)] - Database(#[from] crate::db::Error), + Database(#[from] crate::db::DatabaseError), #[error(transparent)] Provider(#[from] crate::provider::ProviderError), diff --git a/crates/interfaces/src/p2p/error.rs b/crates/interfaces/src/p2p/error.rs index 658bbc99f..5d5963ace 100644 --- a/crates/interfaces/src/p2p/error.rs +++ b/crates/interfaces/src/p2p/error.rs @@ -214,7 +214,7 @@ pub enum DownloadError { RequestError(#[from] RequestError), /// Error while reading data from database. #[error(transparent)] - DatabaseError(#[from] db::Error), + DatabaseError(#[from] db::DatabaseError), } #[cfg(test)] diff --git a/crates/net/downloaders/src/bodies/test_utils.rs b/crates/net/downloaders/src/bodies/test_utils.rs index 67d0801e6..1a77745e4 100644 --- a/crates/net/downloaders/src/bodies/test_utils.rs +++ b/crates/net/downloaders/src/bodies/test_utils.rs @@ -47,7 +47,7 @@ pub(crate) fn create_raw_bodies<'a>( #[inline] pub(crate) fn insert_headers(db: &Env, headers: &[SealedHeader]) { - db.update(|tx| -> Result<(), db::Error> { + db.update(|tx| -> Result<(), db::DatabaseError> { for header in headers { tx.put::(header.number, header.hash())?; tx.put::(header.number, header.clone().unseal())?; diff --git a/crates/staged-sync/src/utils/init.rs b/crates/staged-sync/src/utils/init.rs index a5d8b5c4e..3f5331e86 100644 --- a/crates/staged-sync/src/utils/init.rs +++ b/crates/staged-sync/src/utils/init.rs @@ -38,7 +38,7 @@ pub enum InitDatabaseError { /// Low-level database error. #[error(transparent)] - DBError(#[from] reth_db::Error), + DBError(#[from] reth_db::DatabaseError), } /// Write the genesis block if it has not already been written diff --git a/crates/stages/benches/setup/account_hashing.rs b/crates/stages/benches/setup/account_hashing.rs index f4b2d86f1..3d2993405 100644 --- a/crates/stages/benches/setup/account_hashing.rs +++ b/crates/stages/benches/setup/account_hashing.rs @@ -1,6 +1,6 @@ use super::{constants, StageRange}; use reth_db::{ - cursor::DbCursorRO, database::Database, tables, transaction::DbTx, Error as DbError, + cursor::DbCursorRO, database::Database, tables, transaction::DbTx, DatabaseError as DbError, }; use reth_stages::{ stages::{AccountHashingStage, SeedOpts}, diff --git a/crates/stages/src/error.rs b/crates/stages/src/error.rs index 2531ad114..c12ecada7 100644 --- a/crates/stages/src/error.rs +++ b/crates/stages/src/error.rs @@ -1,6 +1,7 @@ use crate::pipeline::PipelineEvent; use reth_interfaces::{ - consensus, db::Error as DbError, executor, p2p::error::DownloadError, provider::ProviderError, + consensus, db::DatabaseError as DbError, executor, p2p::error::DownloadError, + provider::ProviderError, }; use reth_primitives::BlockNumber; use reth_provider::TransactionError; diff --git a/crates/stages/src/id.rs b/crates/stages/src/id.rs index 5fbc53ba3..60f43758b 100644 --- a/crates/stages/src/id.rs +++ b/crates/stages/src/id.rs @@ -6,7 +6,7 @@ use crate::stages::{ use reth_db::{ tables::SyncStage, transaction::{DbTx, DbTxMut}, - Error as DbError, + DatabaseError as DbError, }; use reth_primitives::BlockNumber; use std::fmt::Display; diff --git a/crates/stages/src/stages/hashing_storage.rs b/crates/stages/src/stages/hashing_storage.rs index 19e637b7a..1d8df0881 100644 --- a/crates/stages/src/stages/hashing_storage.rs +++ b/crates/stages/src/stages/hashing_storage.rs @@ -420,7 +420,7 @@ mod tests { let block_number = progress.number; self.tx.commit(|tx| { progress.body.iter().try_for_each( - |transaction| -> Result<(), reth_db::Error> { + |transaction| -> Result<(), reth_db::DatabaseError> { tx.put::(transaction.hash(), next_tx_num)?; tx.put::( next_tx_num, @@ -543,7 +543,7 @@ mod tests { tid_address: BlockNumberAddress, entry: StorageEntry, hash: bool, - ) -> Result<(), reth_db::Error> { + ) -> Result<(), reth_db::DatabaseError> { let mut storage_cursor = tx.cursor_dup_write::()?; let prev_entry = match storage_cursor.seek_by_key_subkey(tid_address.address(), entry.key)? { diff --git a/crates/stages/src/stages/sender_recovery.rs b/crates/stages/src/stages/sender_recovery.rs index 127b64d51..84fae4d73 100644 --- a/crates/stages/src/stages/sender_recovery.rs +++ b/crates/stages/src/stages/sender_recovery.rs @@ -101,7 +101,7 @@ impl Stage for SenderRecoveryStage { // closure that would recover signer. Used as utility to wrap result let recover = |entry: Result< (RawKey, RawValue), - reth_db::Error, + reth_db::DatabaseError, >, rlp_buf: &mut Vec| -> Result<(u64, H160), Box> { diff --git a/crates/stages/src/stages/tx_lookup.rs b/crates/stages/src/stages/tx_lookup.rs index e7a102d4d..93891036c 100644 --- a/crates/stages/src/stages/tx_lookup.rs +++ b/crates/stages/src/stages/tx_lookup.rs @@ -89,7 +89,7 @@ impl Stage for TransactionLookupStage { // closure that will calculate the TxHash let calculate_hash = - |entry: Result<(TxNumber, TransactionSignedNoHash), reth_db::Error>, + |entry: Result<(TxNumber, TransactionSignedNoHash), reth_db::DatabaseError>, rlp_buf: &mut Vec| -> Result<(H256, u64), Box> { let (tx_id, tx) = entry.map_err(|e| Box::new(e.into()))?; diff --git a/crates/stages/src/test_utils/runner.rs b/crates/stages/src/test_utils/runner.rs index 7e4d6f7ed..de1b96fea 100644 --- a/crates/stages/src/test_utils/runner.rs +++ b/crates/stages/src/test_utils/runner.rs @@ -8,7 +8,7 @@ use tokio::sync::oneshot; #[derive(thiserror::Error, Debug)] pub(crate) enum TestRunnerError { #[error("Database error occurred.")] - Database(#[from] reth_interfaces::db::Error), + Database(#[from] reth_interfaces::db::DatabaseError), #[error("Internal runner error occurred.")] Internal(#[from] Box), } diff --git a/crates/stages/src/test_utils/test_db.rs b/crates/stages/src/test_utils/test_db.rs index 20e0cf772..eee758cc9 100644 --- a/crates/stages/src/test_utils/test_db.rs +++ b/crates/stages/src/test_utils/test_db.rs @@ -10,7 +10,7 @@ use reth_db::{ table::Table, tables, transaction::{DbTx, DbTxMut}, - Error as DbError, + DatabaseError as DbError, }; use reth_primitives::{ keccak256, Account, Address, BlockNumber, SealedBlock, SealedHeader, StorageEntry, H256, U256, diff --git a/crates/storage/db/src/abstraction/common.rs b/crates/storage/db/src/abstraction/common.rs index 52832562c..73d253ee2 100644 --- a/crates/storage/db/src/abstraction/common.rs +++ b/crates/storage/db/src/abstraction/common.rs @@ -5,18 +5,18 @@ pub type KeyValue = (::Key, ::Value); /// /// The `Result` represents that the operation might fail, while the `Option` represents whether or /// not the entry exists. -pub type PairResult = Result>, Error>; +pub type PairResult = Result>, DatabaseError>; /// A key-value pair coming from an iterator. /// /// The `Result` represents that the operation might fail, while the `Option` represents whether or /// not there is another entry. -pub type IterPairResult = Option, Error>>; +pub type IterPairResult = Option, DatabaseError>>; /// A value only result for table `T`. -pub type ValueOnlyResult = Result::Value>, Error>; +pub type ValueOnlyResult = Result::Value>, DatabaseError>; -use crate::{abstraction::table::*, Error}; +use crate::{abstraction::table::*, DatabaseError}; // Sealed trait helper to prevent misuse of the API. mod sealed { diff --git a/crates/storage/db/src/abstraction/cursor.rs b/crates/storage/db/src/abstraction/cursor.rs index e9a5c5c0c..af54eb087 100644 --- a/crates/storage/db/src/abstraction/cursor.rs +++ b/crates/storage/db/src/abstraction/cursor.rs @@ -6,7 +6,7 @@ use std::{ use crate::{ common::{IterPairResult, PairResult, ValueOnlyResult}, table::{DupSort, Table}, - Error, + DatabaseError, }; /// A read-only cursor over table `T`. @@ -40,7 +40,7 @@ pub trait DbCursorRO<'tx, T: Table> { fn walk<'cursor>( &'cursor mut self, start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized; @@ -48,7 +48,7 @@ pub trait DbCursorRO<'tx, T: Table> { fn walk_range<'cursor>( &'cursor mut self, range: impl RangeBounds, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized; @@ -59,7 +59,7 @@ pub trait DbCursorRO<'tx, T: Table> { fn walk_back<'cursor>( &'cursor mut self, start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized; } @@ -98,7 +98,7 @@ pub trait DbDupCursorRO<'tx, T: DupSort> { &'cursor mut self, key: Option, subkey: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized; } @@ -107,31 +107,31 @@ pub trait DbDupCursorRO<'tx, T: DupSort> { pub trait DbCursorRW<'tx, T: Table> { /// Database operation that will update an existing row if a specified value already /// exists in a table, and insert a new row if the specified value doesn't already exist - fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), Error>; + fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>; /// Database operation that will insert a row at a given key. If the key is already /// present, the operation will result in an error. - fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), Error>; + fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>; /// Append value to next cursor item. /// /// This is efficient for pre-sorted data. If the data is not pre-sorted, use /// [`DbCursorRW::insert`]. - fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), Error>; + fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>; /// Delete current value that cursor points to - fn delete_current(&mut self) -> Result<(), Error>; + fn delete_current(&mut self) -> Result<(), DatabaseError>; } /// Read Write Cursor over DupSorted table. pub trait DbDupCursorRW<'tx, T: DupSort> { /// Delete all duplicate entries for current key. - fn delete_current_duplicates(&mut self) -> Result<(), Error>; + fn delete_current_duplicates(&mut self) -> Result<(), DatabaseError>; /// Append duplicate value. /// /// This is efficient for pre-sorted data. If the data is not pre-sorted, use `insert`. - fn append_dup(&mut self, key: T::Key, value: T::Value) -> Result<(), Error>; + fn append_dup(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>; } /// Provides an iterator to `Cursor` when handling `Table`. @@ -151,7 +151,7 @@ pub struct Walker<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> { impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> std::iter::Iterator for Walker<'cursor, 'tx, T, CURSOR> { - type Item = Result<(T::Key, T::Value), Error>; + type Item = Result<(T::Key, T::Value), DatabaseError>; fn next(&mut self) -> Option { let start = self.start.take(); if start.is_some() { @@ -179,7 +179,7 @@ impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRW<'tx, T> + DbCursorRO<'tx, T>> Walker<'cursor, 'tx, T, CURSOR> { /// Delete current item that walker points to. - pub fn delete_current(&mut self) -> Result<(), Error> { + pub fn delete_current(&mut self) -> Result<(), DatabaseError> { self.cursor.delete_current() } } @@ -212,7 +212,7 @@ impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRW<'tx, T> + DbCursorRO<'tx, T>> ReverseWalker<'cursor, 'tx, T, CURSOR> { /// Delete current item that walker points to. - pub fn delete_current(&mut self) -> Result<(), Error> { + pub fn delete_current(&mut self) -> Result<(), DatabaseError> { self.cursor.delete_current() } } @@ -220,7 +220,7 @@ impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRW<'tx, T> + DbCursorRO<'tx, T>> impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> std::iter::Iterator for ReverseWalker<'cursor, 'tx, T, CURSOR> { - type Item = Result<(T::Key, T::Value), Error>; + type Item = Result<(T::Key, T::Value), DatabaseError>; fn next(&mut self) -> Option { let start = self.start.take(); @@ -250,7 +250,7 @@ pub struct RangeWalker<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> { impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> std::iter::Iterator for RangeWalker<'cursor, 'tx, T, CURSOR> { - type Item = Result<(T::Key, T::Value), Error>; + type Item = Result<(T::Key, T::Value), DatabaseError>; fn next(&mut self) -> Option { if self.is_done { return None @@ -303,7 +303,7 @@ impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRW<'tx, T> + DbCursorRO<'tx, T>> RangeWalker<'cursor, 'tx, T, CURSOR> { /// Delete current item that walker points to. - pub fn delete_current(&mut self) -> Result<(), Error> { + pub fn delete_current(&mut self) -> Result<(), DatabaseError> { self.cursor.delete_current() } } @@ -326,7 +326,7 @@ impl<'cursor, 'tx, T: DupSort, CURSOR: DbCursorRW<'tx, T> + DbDupCursorRO<'tx, T DupWalker<'cursor, 'tx, T, CURSOR> { /// Delete current item that walker points to. - pub fn delete_current(&mut self) -> Result<(), Error> { + pub fn delete_current(&mut self) -> Result<(), DatabaseError> { self.cursor.delete_current() } } @@ -334,7 +334,7 @@ impl<'cursor, 'tx, T: DupSort, CURSOR: DbCursorRW<'tx, T> + DbDupCursorRO<'tx, T impl<'cursor, 'tx, T: DupSort, CURSOR: DbDupCursorRO<'tx, T>> std::iter::Iterator for DupWalker<'cursor, 'tx, T, CURSOR> { - type Item = Result<(T::Key, T::Value), Error>; + type Item = Result<(T::Key, T::Value), DatabaseError>; fn next(&mut self) -> Option { let start = self.start.take(); if start.is_some() { diff --git a/crates/storage/db/src/abstraction/database.rs b/crates/storage/db/src/abstraction/database.rs index f6559ac24..a2071b80b 100644 --- a/crates/storage/db/src/abstraction/database.rs +++ b/crates/storage/db/src/abstraction/database.rs @@ -2,7 +2,7 @@ use crate::{ common::{Bounds, Sealed}, table::TableImporter, transaction::{DbTx, DbTxMut}, - Error, + DatabaseError, }; use std::sync::Arc; @@ -20,14 +20,14 @@ pub trait DatabaseGAT<'a, __ImplicitBounds: Sealed = Bounds<&'a Self>>: Send + S /// Main Database trait that spawns transactions to be executed. pub trait Database: for<'a> DatabaseGAT<'a> { /// Create read only transaction. - fn tx(&self) -> Result<>::TX, Error>; + fn tx(&self) -> Result<>::TX, DatabaseError>; /// Create read write transaction only possible if database is open with write access. - fn tx_mut(&self) -> Result<>::TXMut, Error>; + fn tx_mut(&self) -> Result<>::TXMut, DatabaseError>; /// Takes a function and passes a read-only transaction into it, making sure it's closed in the /// end of the execution. - fn view(&self, f: F) -> Result + fn view(&self, f: F) -> Result where F: FnOnce(&>::TX) -> T, { @@ -41,7 +41,7 @@ pub trait Database: for<'a> DatabaseGAT<'a> { /// Takes a function and passes a write-read transaction into it, making sure it's committed in /// the end of the execution. - fn update(&self, f: F) -> Result + fn update(&self, f: F) -> Result where F: FnOnce(&>::TXMut) -> T, { @@ -61,11 +61,11 @@ impl<'a, DB: Database> DatabaseGAT<'a> for Arc { } impl Database for Arc { - fn tx(&self) -> Result<>::TX, Error> { + fn tx(&self) -> Result<>::TX, DatabaseError> { ::tx(self) } - fn tx_mut(&self) -> Result<>::TXMut, Error> { + fn tx_mut(&self) -> Result<>::TXMut, DatabaseError> { ::tx_mut(self) } } @@ -77,11 +77,11 @@ impl<'a, DB: Database> DatabaseGAT<'a> for &DB { } impl Database for &DB { - fn tx(&self) -> Result<>::TX, Error> { + fn tx(&self) -> Result<>::TX, DatabaseError> { ::tx(self) } - fn tx_mut(&self) -> Result<>::TXMut, Error> { + fn tx_mut(&self) -> Result<>::TXMut, DatabaseError> { ::tx_mut(self) } } diff --git a/crates/storage/db/src/abstraction/mock.rs b/crates/storage/db/src/abstraction/mock.rs index 599178fcb..a647a9cfa 100644 --- a/crates/storage/db/src/abstraction/mock.rs +++ b/crates/storage/db/src/abstraction/mock.rs @@ -10,7 +10,7 @@ use crate::{ database::{Database, DatabaseGAT}, table::{DupSort, Table, TableImporter}, transaction::{DbTx, DbTxGAT, DbTxMut, DbTxMutGAT}, - Error, + DatabaseError, }; /// Mock database used for testing with inner BTreeMap structure @@ -22,11 +22,11 @@ pub struct DatabaseMock { } impl Database for DatabaseMock { - fn tx(&self) -> Result<>::TX, Error> { + fn tx(&self) -> Result<>::TX, DatabaseError> { Ok(TxMock::default()) } - fn tx_mut(&self) -> Result<>::TXMut, Error> { + fn tx_mut(&self) -> Result<>::TXMut, DatabaseError> { Ok(TxMock::default()) } } @@ -55,11 +55,11 @@ impl<'a> DbTxMutGAT<'a> for TxMock { } impl<'a> DbTx<'a> for TxMock { - fn get(&self, _key: T::Key) -> Result, Error> { + fn get(&self, _key: T::Key) -> Result, DatabaseError> { todo!() } - fn commit(self) -> Result { + fn commit(self) -> Result { todo!() } @@ -67,35 +67,43 @@ impl<'a> DbTx<'a> for TxMock { todo!() } - fn cursor_read(&self) -> Result<>::Cursor, Error> { + fn cursor_read(&self) -> Result<>::Cursor, DatabaseError> { todo!() } - fn cursor_dup_read(&self) -> Result<>::DupCursor, Error> { + fn cursor_dup_read( + &self, + ) -> Result<>::DupCursor, DatabaseError> { todo!() } } impl<'a> DbTxMut<'a> for TxMock { - fn put(&self, _key: T::Key, _value: T::Value) -> Result<(), Error> { + fn put(&self, _key: T::Key, _value: T::Value) -> Result<(), DatabaseError> { todo!() } - fn delete(&self, _key: T::Key, _value: Option) -> Result { + fn delete( + &self, + _key: T::Key, + _value: Option, + ) -> Result { todo!() } - fn cursor_write(&self) -> Result<>::CursorMut, Error> { + fn cursor_write( + &self, + ) -> Result<>::CursorMut, DatabaseError> { todo!() } fn cursor_dup_write( &self, - ) -> Result<>::DupCursorMut, Error> { + ) -> Result<>::DupCursorMut, DatabaseError> { todo!() } - fn clear(&self) -> Result<(), Error> { + fn clear(&self) -> Result<(), DatabaseError> { todo!() } } @@ -139,7 +147,7 @@ impl<'tx, T: Table> DbCursorRO<'tx, T> for CursorMock { fn walk<'cursor>( &'cursor mut self, _start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -149,7 +157,7 @@ impl<'tx, T: Table> DbCursorRO<'tx, T> for CursorMock { fn walk_range<'cursor>( &'cursor mut self, _range: impl RangeBounds, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -159,7 +167,7 @@ impl<'tx, T: Table> DbCursorRO<'tx, T> for CursorMock { fn walk_back<'cursor>( &'cursor mut self, _start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -192,7 +200,7 @@ impl<'tx, T: DupSort> DbDupCursorRO<'tx, T> for CursorMock { &'cursor mut self, _key: Option<::Key>, _subkey: Option<::SubKey>, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -205,7 +213,7 @@ impl<'tx, T: Table> DbCursorRW<'tx, T> for CursorMock { &mut self, _key: ::Key, _value: ::Value, - ) -> Result<(), Error> { + ) -> Result<(), DatabaseError> { todo!() } @@ -213,7 +221,7 @@ impl<'tx, T: Table> DbCursorRW<'tx, T> for CursorMock { &mut self, _key: ::Key, _value: ::Value, - ) -> Result<(), Error> { + ) -> Result<(), DatabaseError> { todo!() } @@ -221,21 +229,21 @@ impl<'tx, T: Table> DbCursorRW<'tx, T> for CursorMock { &mut self, _key: ::Key, _value: ::Value, - ) -> Result<(), Error> { + ) -> Result<(), DatabaseError> { todo!() } - fn delete_current(&mut self) -> Result<(), Error> { + fn delete_current(&mut self) -> Result<(), DatabaseError> { todo!() } } impl<'tx, T: DupSort> DbDupCursorRW<'tx, T> for CursorMock { - fn delete_current_duplicates(&mut self) -> Result<(), Error> { + fn delete_current_duplicates(&mut self) -> Result<(), DatabaseError> { todo!() } - fn append_dup(&mut self, _key: ::Key, _value: ::Value) -> Result<(), Error> { + fn append_dup(&mut self, _key: ::Key, _value: ::Value) -> Result<(), DatabaseError> { todo!() } } diff --git a/crates/storage/db/src/abstraction/table.rs b/crates/storage/db/src/abstraction/table.rs index a7ba6a386..be8af0a83 100644 --- a/crates/storage/db/src/abstraction/table.rs +++ b/crates/storage/db/src/abstraction/table.rs @@ -1,7 +1,7 @@ use crate::{ abstraction::cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW}, transaction::{DbTx, DbTxMut}, - Error, + DatabaseError, }; use serde::Serialize; @@ -34,7 +34,7 @@ pub trait Compress: Send + Sync + Sized + Debug { /// Trait that will transform the data to be read from the DB. pub trait Decompress: Send + Sync + Sized + Debug { /// Decompresses data coming from the database. - fn decompress>(value: B) -> Result; + fn decompress>(value: B) -> Result; } /// Trait that will transform the data to be saved in the DB. @@ -49,7 +49,7 @@ pub trait Encode: Send + Sync + Sized + Debug { /// Trait that will transform the data to be read from the DB. pub trait Decode: Send + Sync + Sized + Debug { /// Decodes data coming from the database. - fn decode>(key: B) -> Result; + fn decode>(key: B) -> Result; } /// Generic trait that enforces the database key to implement [`Encode`] and [`Decode`]. @@ -96,7 +96,7 @@ pub trait DupSort: Table { /// Allows duplicating tables across databases pub trait TableImporter<'tx>: for<'a> DbTxMut<'a> { /// Imports all table data from another transaction. - fn import_table>(&self, source_tx: &R) -> Result<(), Error> { + fn import_table>(&self, source_tx: &R) -> Result<(), DatabaseError> { let mut destination_cursor = self.cursor_write::()?; for kv in source_tx.cursor_read::()?.walk(None)? { @@ -113,7 +113,7 @@ pub trait TableImporter<'tx>: for<'a> DbTxMut<'a> { source_tx: &R, from: Option<::Key>, to: ::Key, - ) -> Result<(), Error> + ) -> Result<(), DatabaseError> where T::Key: Default, { @@ -133,7 +133,7 @@ pub trait TableImporter<'tx>: for<'a> DbTxMut<'a> { } /// Imports all dupsort data from another transaction. - fn import_dupsort>(&self, source_tx: &R) -> Result<(), Error> { + fn import_dupsort>(&self, source_tx: &R) -> Result<(), DatabaseError> { let mut destination_cursor = self.cursor_dup_write::()?; let mut cursor = source_tx.cursor_dup_read::()?; diff --git a/crates/storage/db/src/abstraction/transaction.rs b/crates/storage/db/src/abstraction/transaction.rs index 832a5e926..9b6e12665 100644 --- a/crates/storage/db/src/abstraction/transaction.rs +++ b/crates/storage/db/src/abstraction/transaction.rs @@ -2,7 +2,7 @@ use crate::{ common::{Bounds, Sealed}, cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW}, table::{DupSort, Table}, - Error, + DatabaseError, }; /// Implements the GAT method from: @@ -35,30 +35,35 @@ pub trait DbTxMutGAT<'a, __ImplicitBounds: Sealed = Bounds<&'a Self>>: Send + Sy /// Read only transaction pub trait DbTx<'tx>: for<'a> DbTxGAT<'a> { /// Get value - fn get(&self, key: T::Key) -> Result, Error>; + fn get(&self, key: T::Key) -> Result, DatabaseError>; /// Commit for read only transaction will consume and free transaction and allows /// freeing of memory pages - fn commit(self) -> Result; + fn commit(self) -> Result; /// Drops transaction fn drop(self); /// Iterate over read only values in table. - fn cursor_read(&self) -> Result<>::Cursor, Error>; + fn cursor_read(&self) -> Result<>::Cursor, DatabaseError>; /// Iterate over read only values in dup sorted table. - fn cursor_dup_read(&self) -> Result<>::DupCursor, Error>; + fn cursor_dup_read( + &self, + ) -> Result<>::DupCursor, DatabaseError>; } /// Read write transaction that allows writing to database pub trait DbTxMut<'tx>: for<'a> DbTxMutGAT<'a> { /// Put value to database - fn put(&self, key: T::Key, value: T::Value) -> Result<(), Error>; + fn put(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>; /// Delete value from database - fn delete(&self, key: T::Key, value: Option) -> Result; + fn delete(&self, key: T::Key, value: Option) + -> Result; /// Clears database. - fn clear(&self) -> Result<(), Error>; + fn clear(&self) -> Result<(), DatabaseError>; /// Cursor mut - fn cursor_write(&self) -> Result<>::CursorMut, Error>; + fn cursor_write( + &self, + ) -> Result<>::CursorMut, DatabaseError>; /// DupCursor mut. fn cursor_dup_write( &self, - ) -> Result<>::DupCursorMut, Error>; + ) -> Result<>::DupCursorMut, DatabaseError>; } diff --git a/crates/storage/db/src/implementation/mdbx/cursor.rs b/crates/storage/db/src/implementation/mdbx/cursor.rs index 12ce619d5..ea7cfe430 100644 --- a/crates/storage/db/src/implementation/mdbx/cursor.rs +++ b/crates/storage/db/src/implementation/mdbx/cursor.rs @@ -10,7 +10,7 @@ use crate::{ }, table::{Compress, DupSort, Encode, Table}, tables::utils::*, - Error, + DatabaseError, }; use reth_libmdbx::{self, Error as MDBXError, TransactionKind, WriteFlags, RO, RW}; @@ -36,7 +36,7 @@ pub struct Cursor<'tx, K: TransactionKind, T: Table> { #[macro_export] macro_rules! decode { ($v:expr) => { - $v.map_err(|e| Error::Read(e.into()))?.map(decoder::).transpose() + $v.map_err(|e| $crate::DatabaseError::Read(e.into()))?.map(decoder::).transpose() }; } @@ -86,14 +86,14 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T> fn walk<'cursor>( &'cursor mut self, start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { let start = if let Some(start_key) = start_key { self.inner .set_range(start_key.encode().as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(decoder::) } else { self.first().transpose() @@ -105,7 +105,7 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T> fn walk_range<'cursor>( &'cursor mut self, range: impl RangeBounds, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -116,7 +116,7 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T> } Bound::Unbounded => self.inner.first(), } - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(decoder::); Ok(RangeWalker::new(self, start, range.end_bound().cloned())) @@ -125,7 +125,7 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T> fn walk_back<'cursor>( &'cursor mut self, start_key: Option, - ) -> Result, Error> + ) -> Result, DatabaseError> where Self: Sized, { @@ -153,7 +153,11 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, /// Returns the next `value` of a duplicate `key`. fn next_dup_val(&mut self) -> ValueOnlyResult { - self.inner.next_dup().map_err(|e| Error::Read(e.into()))?.map(decode_value::).transpose() + self.inner + .next_dup() + .map_err(|e| DatabaseError::Read(e.into()))? + .map(decode_value::) + .transpose() } fn seek_by_key_subkey( @@ -163,7 +167,7 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, ) -> ValueOnlyResult { self.inner .get_both_range(key.encode().as_ref(), subkey.encode().as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(decode_one::) .transpose() } @@ -178,7 +182,7 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, &'cursor mut self, key: Option, subkey: Option, - ) -> Result, Error> { + ) -> Result, DatabaseError> { let start = match (key, subkey) { (Some(key), Some(subkey)) => { // encode key and decode it after. @@ -186,7 +190,7 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, self.inner .get_both_range(key.as_ref(), subkey.encode().as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(|val| decoder::((Cow::Owned(key), val))) } (Some(key), None) => { @@ -194,7 +198,7 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, self.inner .set(key.as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(|val| decoder::((Cow::Owned(key), val))) } (None, Some(subkey)) => { @@ -203,11 +207,11 @@ impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, self.inner .get_both_range(key.as_ref(), subkey.encode().as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(|val| decoder::((Cow::Owned(key), val))) } else { let err_code = MDBXError::to_err_code(&MDBXError::NotFound); - Some(Err(Error::Read(err_code))) + Some(Err(DatabaseError::Read(err_code))) } } (None, None) => self.first().transpose(), @@ -225,40 +229,40 @@ impl<'tx, T: Table> DbCursorRW<'tx, T> for Cursor<'tx, RW, T> { /// it will append the value to the subkey, even if the subkeys are the same. So if you want /// to properly upsert, you'll need to `seek_exact` & `delete_current` if the key+subkey was /// found, before calling `upsert`. - fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), Error> { + fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> { // Default `WriteFlags` is UPSERT self.inner .put(key.encode().as_ref(), compress_or_ref!(self, value), WriteFlags::UPSERT) - .map_err(|e| Error::Write(e.into())) + .map_err(|e| DatabaseError::Write(e.into())) } - fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), Error> { + fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> { self.inner .put(key.encode().as_ref(), compress_or_ref!(self, value), WriteFlags::NO_OVERWRITE) - .map_err(|e| Error::Write(e.into())) + .map_err(|e| DatabaseError::Write(e.into())) } /// Appends the data to the end of the table. Consequently, the append operation /// will fail if the inserted key is less than the last table key - fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), Error> { + fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> { self.inner .put(key.encode().as_ref(), compress_or_ref!(self, value), WriteFlags::APPEND) - .map_err(|e| Error::Write(e.into())) + .map_err(|e| DatabaseError::Write(e.into())) } - fn delete_current(&mut self) -> Result<(), Error> { - self.inner.del(WriteFlags::CURRENT).map_err(|e| Error::Delete(e.into())) + fn delete_current(&mut self) -> Result<(), DatabaseError> { + self.inner.del(WriteFlags::CURRENT).map_err(|e| DatabaseError::Delete(e.into())) } } impl<'tx, T: DupSort> DbDupCursorRW<'tx, T> for Cursor<'tx, RW, T> { - fn delete_current_duplicates(&mut self) -> Result<(), Error> { - self.inner.del(WriteFlags::NO_DUP_DATA).map_err(|e| Error::Delete(e.into())) + fn delete_current_duplicates(&mut self) -> Result<(), DatabaseError> { + self.inner.del(WriteFlags::NO_DUP_DATA).map_err(|e| DatabaseError::Delete(e.into())) } - fn append_dup(&mut self, key: T::Key, value: T::Value) -> Result<(), Error> { + fn append_dup(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> { self.inner .put(key.encode().as_ref(), compress_or_ref!(self, value), WriteFlags::APPEND_DUP) - .map_err(|e| Error::Write(e.into())) + .map_err(|e| DatabaseError::Write(e.into())) } } diff --git a/crates/storage/db/src/implementation/mdbx/mod.rs b/crates/storage/db/src/implementation/mdbx/mod.rs index 19a95ca6a..68f60b554 100644 --- a/crates/storage/db/src/implementation/mdbx/mod.rs +++ b/crates/storage/db/src/implementation/mdbx/mod.rs @@ -4,7 +4,7 @@ use crate::{ database::{Database, DatabaseGAT}, tables::{TableType, TABLES}, utils::default_page_size, - Error, + DatabaseError, }; use reth_libmdbx::{ DatabaseFlags, Environment, EnvironmentFlags, EnvironmentKind, Geometry, Mode, PageSize, @@ -39,12 +39,16 @@ impl<'a, E: EnvironmentKind> DatabaseGAT<'a> for Env { } impl Database for Env { - fn tx(&self) -> Result<>::TX, Error> { - Ok(Tx::new(self.inner.begin_ro_txn().map_err(|e| Error::InitTransaction(e.into()))?)) + fn tx(&self) -> Result<>::TX, DatabaseError> { + Ok(Tx::new( + self.inner.begin_ro_txn().map_err(|e| DatabaseError::InitTransaction(e.into()))?, + )) } - fn tx_mut(&self) -> Result<>::TXMut, Error> { - Ok(Tx::new(self.inner.begin_rw_txn().map_err(|e| Error::InitTransaction(e.into()))?)) + fn tx_mut(&self) -> Result<>::TXMut, DatabaseError> { + Ok(Tx::new( + self.inner.begin_rw_txn().map_err(|e| DatabaseError::InitTransaction(e.into()))?, + )) } } @@ -55,7 +59,7 @@ impl Env { /// Opens the database at the specified path with the given `EnvKind`. /// /// It does not create the tables, for that call [`Env::create_tables`]. - pub fn open(path: &Path, kind: EnvKind) -> Result, Error> { + pub fn open(path: &Path, kind: EnvKind) -> Result, DatabaseError> { let mode = match kind { EnvKind::RO => Mode::ReadOnly, EnvKind::RW => Mode::ReadWrite { sync_mode: SyncMode::Durable }, @@ -82,15 +86,15 @@ impl Env { ..Default::default() }) .open(path) - .map_err(|e| Error::FailedToOpen(e.into()))?, + .map_err(|e| DatabaseError::FailedToOpen(e.into()))?, }; Ok(env) } /// Creates all the defined tables, if necessary. - pub fn create_tables(&self) -> Result<(), Error> { - let tx = self.inner.begin_rw_txn().map_err(|e| Error::InitTransaction(e.into()))?; + pub fn create_tables(&self) -> Result<(), DatabaseError> { + let tx = self.inner.begin_rw_txn().map_err(|e| DatabaseError::InitTransaction(e.into()))?; for (table_type, table) in TABLES { let flags = match table_type { @@ -98,10 +102,10 @@ impl Env { TableType::DupSort => DatabaseFlags::DUP_SORT, }; - tx.create_db(Some(table), flags).map_err(|e| Error::TableCreation(e.into()))?; + tx.create_db(Some(table), flags).map_err(|e| DatabaseError::TableCreation(e.into()))?; } - tx.commit().map_err(|e| Error::Commit(e.into()))?; + tx.commit().map_err(|e| DatabaseError::Commit(e.into()))?; Ok(()) } @@ -158,7 +162,7 @@ mod tests { models::{AccountBeforeTx, ShardedKey}, tables::{AccountHistory, CanonicalHeaders, Headers, PlainAccountState, PlainStorageState}, transaction::{DbTx, DbTxMut}, - AccountChangeSet, Error, + AccountChangeSet, DatabaseError, }; use reth_libmdbx::{NoWriteMap, WriteMap}; use reth_primitives::{Account, Address, Header, IntegerList, StorageEntry, H160, H256, U256}; @@ -504,7 +508,7 @@ mod tests { assert_eq!(cursor.current(), Ok(Some((key_to_insert, H256::zero())))); // INSERT (failure) - assert_eq!(cursor.insert(key_to_insert, H256::zero()), Err(Error::Write(-30799))); + assert_eq!(cursor.insert(key_to_insert, H256::zero()), Err(DatabaseError::Write(-30799))); assert_eq!(cursor.current(), Ok(Some((key_to_insert, H256::zero())))); tx.commit().expect(ERROR_COMMIT); @@ -639,7 +643,7 @@ mod tests { let key_to_append = 2; let tx = db.tx_mut().expect(ERROR_INIT_TX); let mut cursor = tx.cursor_write::().unwrap(); - assert_eq!(cursor.append(key_to_append, H256::zero()), Err(Error::Write(-30418))); + assert_eq!(cursor.append(key_to_append, H256::zero()), Err(DatabaseError::Write(-30418))); assert_eq!(cursor.current(), Ok(Some((5, H256::zero())))); // the end of table tx.commit().expect(ERROR_COMMIT); @@ -714,14 +718,14 @@ mod tests { transition_id, AccountBeforeTx { address: Address::from_low_u64_be(subkey_to_append), info: None } ), - Err(Error::Write(-30418)) + Err(DatabaseError::Write(-30418)) ); assert_eq!( cursor.append( transition_id - 1, AccountBeforeTx { address: Address::from_low_u64_be(subkey_to_append), info: None } ), - Err(Error::Write(-30418)) + Err(DatabaseError::Write(-30418)) ); assert_eq!( cursor.append( diff --git a/crates/storage/db/src/implementation/mdbx/tx.rs b/crates/storage/db/src/implementation/mdbx/tx.rs index d2cdb46bf..aeafd4668 100644 --- a/crates/storage/db/src/implementation/mdbx/tx.rs +++ b/crates/storage/db/src/implementation/mdbx/tx.rs @@ -5,7 +5,7 @@ use crate::{ table::{Compress, DupSort, Encode, Table, TableImporter}, tables::{utils::decode_one, NUM_TABLES, TABLES}, transaction::{DbTx, DbTxGAT, DbTxMut, DbTxMutGAT}, - Error, + DatabaseError, }; use metrics::histogram; use parking_lot::RwLock; @@ -36,7 +36,7 @@ impl<'env, K: TransactionKind, E: EnvironmentKind> Tx<'env, K, E> { } /// Gets a table database handle if it exists, otherwise creates it. - pub fn get_dbi(&self) -> Result { + pub fn get_dbi(&self) -> Result { let mut handles = self.db_handles.write(); let table_index = TABLES @@ -48,7 +48,10 @@ impl<'env, K: TransactionKind, E: EnvironmentKind> Tx<'env, K, E> { let dbi_handle = handles.get_mut(table_index).expect("should exist"); if dbi_handle.is_none() { *dbi_handle = Some( - self.inner.open_db(Some(T::NAME)).map_err(|e| Error::InitCursor(e.into()))?.dbi(), + self.inner + .open_db(Some(T::NAME)) + .map_err(|e| DatabaseError::InitCursor(e.into()))? + .dbi(), ); } @@ -56,12 +59,12 @@ impl<'env, K: TransactionKind, E: EnvironmentKind> Tx<'env, K, E> { } /// Create db Cursor - pub fn new_cursor(&self) -> Result, Error> { + pub fn new_cursor(&self) -> Result, DatabaseError> { Ok(Cursor { inner: self .inner .cursor_with_dbi(self.get_dbi::()?) - .map_err(|e| Error::InitCursor(e.into()))?, + .map_err(|e| DatabaseError::InitCursor(e.into()))?, table: T::NAME, _dbi: PhantomData, buf: vec![], @@ -83,18 +86,20 @@ impl<'a, E: EnvironmentKind> TableImporter<'a> for Tx<'_, RW, E> {} impl<'tx, K: TransactionKind, E: EnvironmentKind> DbTx<'tx> for Tx<'tx, K, E> { // Iterate over read only values in database. - fn cursor_read(&self) -> Result<>::Cursor, Error> { + fn cursor_read(&self) -> Result<>::Cursor, DatabaseError> { self.new_cursor() } /// Iterate over read only values in database. - fn cursor_dup_read(&self) -> Result<>::DupCursor, Error> { + fn cursor_dup_read( + &self, + ) -> Result<>::DupCursor, DatabaseError> { self.new_cursor() } - fn commit(self) -> Result { + fn commit(self) -> Result { let start = Instant::now(); - let result = self.inner.commit().map_err(|e| Error::Commit(e.into())); + let result = self.inner.commit().map_err(|e| DatabaseError::Commit(e.into())); histogram!("tx.commit", start.elapsed()); result } @@ -103,23 +108,27 @@ impl<'tx, K: TransactionKind, E: EnvironmentKind> DbTx<'tx> for Tx<'tx, K, E> { drop(self.inner) } - fn get(&self, key: T::Key) -> Result::Value>, Error> { + fn get(&self, key: T::Key) -> Result::Value>, DatabaseError> { self.inner .get(self.get_dbi::()?, key.encode().as_ref()) - .map_err(|e| Error::Read(e.into()))? + .map_err(|e| DatabaseError::Read(e.into()))? .map(decode_one::) .transpose() } } impl DbTxMut<'_> for Tx<'_, RW, E> { - fn put(&self, key: T::Key, value: T::Value) -> Result<(), Error> { + fn put(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> { self.inner .put(self.get_dbi::()?, &key.encode(), &value.compress(), WriteFlags::UPSERT) - .map_err(|e| Error::Write(e.into())) + .map_err(|e| DatabaseError::Write(e.into())) } - fn delete(&self, key: T::Key, value: Option) -> Result { + fn delete( + &self, + key: T::Key, + value: Option, + ) -> Result { let mut data = None; let value = value.map(Compress::compress); @@ -129,22 +138,24 @@ impl DbTxMut<'_> for Tx<'_, RW, E> { self.inner .del(self.get_dbi::()?, key.encode(), data) - .map_err(|e| Error::Delete(e.into())) + .map_err(|e| DatabaseError::Delete(e.into())) } - fn clear(&self) -> Result<(), Error> { - self.inner.clear_db(self.get_dbi::()?).map_err(|e| Error::Delete(e.into()))?; + fn clear(&self) -> Result<(), DatabaseError> { + self.inner.clear_db(self.get_dbi::()?).map_err(|e| DatabaseError::Delete(e.into()))?; Ok(()) } - fn cursor_write(&self) -> Result<>::CursorMut, Error> { + fn cursor_write( + &self, + ) -> Result<>::CursorMut, DatabaseError> { self.new_cursor() } fn cursor_dup_write( &self, - ) -> Result<>::DupCursorMut, Error> { + ) -> Result<>::DupCursorMut, DatabaseError> { self.new_cursor() } } diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index a8c7405fc..e0d7326f2 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -77,5 +77,5 @@ pub mod mdbx { } pub use abstraction::*; -pub use reth_interfaces::db::Error; +pub use reth_interfaces::db::DatabaseError; pub use tables::*; diff --git a/crates/storage/db/src/tables/codecs/compact.rs b/crates/storage/db/src/tables/codecs/compact.rs index de9eeb447..d95196356 100644 --- a/crates/storage/db/src/tables/codecs/compact.rs +++ b/crates/storage/db/src/tables/codecs/compact.rs @@ -1,7 +1,6 @@ use crate::{ table::{Compress, Decompress}, tables::models::*, - Error, }; use reth_codecs::{main_codec, Compact}; use reth_primitives::{trie::*, *}; @@ -21,7 +20,7 @@ macro_rules! impl_compression_for_compact { impl Decompress for $name { - fn decompress>(value: B) -> Result<$name, Error> { + fn decompress>(value: B) -> Result<$name, $crate::DatabaseError> { let value = value.as_ref(); let (obj, _) = Compact::from_compact(&value, value.len()); Ok(obj) @@ -68,7 +67,7 @@ macro_rules! impl_compression_fixed_compact { impl Decompress for $name { - fn decompress>(value: B) -> Result<$name, Error> { + fn decompress>(value: B) -> Result<$name, $crate::DatabaseError> { let value = value.as_ref(); let (obj, _) = Compact::from_compact(&value, value.len()); Ok(obj) diff --git a/crates/storage/db/src/tables/codecs/postcard.rs b/crates/storage/db/src/tables/codecs/postcard.rs index 8800bdc12..13bd506de 100644 --- a/crates/storage/db/src/tables/codecs/postcard.rs +++ b/crates/storage/db/src/tables/codecs/postcard.rs @@ -2,7 +2,7 @@ use crate::{ table::{Decode, Encode}, - Error, + DatabaseError, }; use postcard::{from_bytes, to_allocvec, to_vec}; use reth_primitives::*; diff --git a/crates/storage/db/src/tables/codecs/scale.rs b/crates/storage/db/src/tables/codecs/scale.rs index 022d1d98b..60bca6fa1 100644 --- a/crates/storage/db/src/tables/codecs/scale.rs +++ b/crates/storage/db/src/tables/codecs/scale.rs @@ -1,6 +1,6 @@ use crate::{ table::{Compress, Decompress}, - Error, + DatabaseError, }; use reth_primitives::*; @@ -30,8 +30,9 @@ impl Decompress for T where T: ScaleValue + parity_scale_codec::Decode + Sync + Send + std::fmt::Debug, { - fn decompress>(value: B) -> Result { - parity_scale_codec::Decode::decode(&mut value.as_ref()).map_err(|_| Error::DecodeError) + fn decompress>(value: B) -> Result { + parity_scale_codec::Decode::decode(&mut value.as_ref()) + .map_err(|_| DatabaseError::DecodeError) } } diff --git a/crates/storage/db/src/tables/models/accounts.rs b/crates/storage/db/src/tables/models/accounts.rs index 8389c9725..c1a50e95b 100644 --- a/crates/storage/db/src/tables/models/accounts.rs +++ b/crates/storage/db/src/tables/models/accounts.rs @@ -5,7 +5,7 @@ use std::ops::{Range, RangeInclusive}; use crate::{ impl_fixed_arbitrary, table::{Decode, Encode}, - Error, + DatabaseError, }; use bytes::Buf; use reth_codecs::{derive_arbitrary, Compact}; @@ -113,9 +113,10 @@ impl Encode for BlockNumberAddress { } impl Decode for BlockNumberAddress { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { let value = value.as_ref(); - let num = u64::from_be_bytes(value[..8].try_into().map_err(|_| Error::DecodeError)?); + let num = + u64::from_be_bytes(value[..8].try_into().map_err(|_| DatabaseError::DecodeError)?); let hash = Address::from_slice(&value[8..]); Ok(BlockNumberAddress((num, hash))) diff --git a/crates/storage/db/src/tables/models/integer_list.rs b/crates/storage/db/src/tables/models/integer_list.rs index 3da435308..203957e78 100644 --- a/crates/storage/db/src/tables/models/integer_list.rs +++ b/crates/storage/db/src/tables/models/integer_list.rs @@ -2,7 +2,7 @@ use crate::{ table::{Compress, Decompress}, - Error, + DatabaseError, }; use reth_primitives::IntegerList; @@ -18,7 +18,7 @@ impl Compress for IntegerList { } impl Decompress for IntegerList { - fn decompress>(value: B) -> Result { - IntegerList::from_bytes(value.as_ref()).map_err(|_| Error::DecodeError) + fn decompress>(value: B) -> Result { + IntegerList::from_bytes(value.as_ref()).map_err(|_| DatabaseError::DecodeError) } } diff --git a/crates/storage/db/src/tables/models/mod.rs b/crates/storage/db/src/tables/models/mod.rs index d16172592..ddd2c6b1c 100644 --- a/crates/storage/db/src/tables/models/mod.rs +++ b/crates/storage/db/src/tables/models/mod.rs @@ -1,7 +1,7 @@ //! Implements data structures specific to the database use crate::{ table::{Decode, Encode}, - Error, + DatabaseError, }; use reth_codecs::Compact; use reth_primitives::{ @@ -34,10 +34,10 @@ macro_rules! impl_uints { impl Decode for $name { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { Ok( $name::from_be_bytes( - value.as_ref().try_into().map_err(|_| Error::DecodeError)? + value.as_ref().try_into().map_err(|_| $crate::DatabaseError::DecodeError)? ) ) } @@ -56,7 +56,7 @@ impl Encode for Vec { } impl Decode for Vec { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { Ok(value.as_ref().to_vec()) } } @@ -69,7 +69,7 @@ impl Encode for Address { } impl Decode for Address { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { Ok(Address::from_slice(value.as_ref())) } } @@ -81,7 +81,7 @@ impl Encode for H256 { } impl Decode for H256 { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { Ok(H256::from_slice(value.as_ref())) } } @@ -94,8 +94,8 @@ impl Encode for String { } impl Decode for String { - fn decode>(value: B) -> Result { - String::from_utf8(value.as_ref().to_vec()).map_err(|_| Error::DecodeError) + fn decode>(value: B) -> Result { + String::from_utf8(value.as_ref().to_vec()).map_err(|_| DatabaseError::DecodeError) } } @@ -111,7 +111,7 @@ impl Encode for StoredNibbles { } impl Decode for StoredNibbles { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { let buf = value.as_ref(); Ok(Self::from_compact(buf, buf.len()).0) } @@ -129,7 +129,7 @@ impl Encode for StoredNibblesSubKey { } impl Decode for StoredNibblesSubKey { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { let buf = value.as_ref(); Ok(Self::from_compact(buf, buf.len()).0) } diff --git a/crates/storage/db/src/tables/models/sharded_key.rs b/crates/storage/db/src/tables/models/sharded_key.rs index 61a2a1856..b66f761b4 100644 --- a/crates/storage/db/src/tables/models/sharded_key.rs +++ b/crates/storage/db/src/tables/models/sharded_key.rs @@ -2,7 +2,7 @@ use crate::{ table::{Decode, Encode}, - Error, + DatabaseError, }; use reth_primitives::BlockNumber; use serde::Serialize; @@ -49,13 +49,14 @@ impl Decode for ShardedKey where T: Decode, { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { let value = value.as_ref(); let tx_num_index = value.len() - 8; - let highest_tx_number = - u64::from_be_bytes(value[tx_num_index..].try_into().map_err(|_| Error::DecodeError)?); + let highest_tx_number = u64::from_be_bytes( + value[tx_num_index..].try_into().map_err(|_| DatabaseError::DecodeError)?, + ); let key = T::decode(&value[..tx_num_index])?; Ok(ShardedKey::new(key, highest_tx_number)) diff --git a/crates/storage/db/src/tables/models/storage_sharded_key.rs b/crates/storage/db/src/tables/models/storage_sharded_key.rs index 0070c2212..fe2adbb35 100644 --- a/crates/storage/db/src/tables/models/storage_sharded_key.rs +++ b/crates/storage/db/src/tables/models/storage_sharded_key.rs @@ -2,7 +2,7 @@ use crate::{ table::{Decode, Encode}, - Error, + DatabaseError, }; use reth_primitives::{BlockNumber, H160, H256}; @@ -46,12 +46,13 @@ impl Encode for StorageShardedKey { } impl Decode for StorageShardedKey { - fn decode>(value: B) -> Result { + fn decode>(value: B) -> Result { let value = value.as_ref(); let tx_num_index = value.len() - 8; - let highest_tx_number = - u64::from_be_bytes(value[tx_num_index..].try_into().map_err(|_| Error::DecodeError)?); + let highest_tx_number = u64::from_be_bytes( + value[tx_num_index..].try_into().map_err(|_| DatabaseError::DecodeError)?, + ); let address = H160::decode(&value[..20])?; let storage_key = H256::decode(&value[20..52])?; diff --git a/crates/storage/db/src/tables/raw.rs b/crates/storage/db/src/tables/raw.rs index e7e262e6a..c9cc0cc1e 100644 --- a/crates/storage/db/src/tables/raw.rs +++ b/crates/storage/db/src/tables/raw.rs @@ -1,6 +1,6 @@ use crate::{ table::{Compress, Decode, Decompress, DupSort, Encode, Key, Table, Value}, - Error, + DatabaseError, }; use serde::Serialize; @@ -51,7 +51,7 @@ impl RawKey { Self { key: K::encode(key).as_ref().to_vec(), _phantom: std::marker::PhantomData } } /// Returns the raw key. - pub fn key(&self) -> Result { + pub fn key(&self) -> Result { K::decode(&self.key) } } @@ -79,7 +79,7 @@ impl Encode for RawKey { // Decode impl Decode for RawKey { - fn decode>(key: B) -> Result { + fn decode>(key: B) -> Result { Ok(Self { key: key.as_ref().to_vec(), _phantom: std::marker::PhantomData }) } } @@ -97,7 +97,7 @@ impl RawValue { Self { value: V::compress(value).as_ref().to_vec(), _phantom: std::marker::PhantomData } } /// Returns the raw value. - pub fn value(&self) -> Result { + pub fn value(&self) -> Result { V::decompress(&self.value) } } @@ -126,7 +126,7 @@ impl Compress for RawValue { } impl Decompress for RawValue { - fn decompress>(value: B) -> Result { + fn decompress>(value: B) -> Result { Ok(Self { value: value.as_ref().to_vec(), _phantom: std::marker::PhantomData }) } } diff --git a/crates/storage/db/src/tables/utils.rs b/crates/storage/db/src/tables/utils.rs index a2e50f8d8..6a6d22412 100644 --- a/crates/storage/db/src/tables/utils.rs +++ b/crates/storage/db/src/tables/utils.rs @@ -1,7 +1,7 @@ //! Small database table utilities and helper functions use crate::{ table::{Decode, Decompress, Table}, - Error, + DatabaseError, }; use std::borrow::Cow; @@ -43,7 +43,7 @@ macro_rules! impl_fixed_arbitrary { /// Helper function to decode a `(key, value)` pair. pub(crate) fn decoder<'a, T>( kv: (Cow<'a, [u8]>, Cow<'a, [u8]>), -) -> Result<(T::Key, T::Value), Error> +) -> Result<(T::Key, T::Value), DatabaseError> where T: Table, T::Key: Decode, @@ -61,7 +61,9 @@ where } /// Helper function to decode only a value from a `(key, value)` pair. -pub(crate) fn decode_value<'a, T>(kv: (Cow<'a, [u8]>, Cow<'a, [u8]>)) -> Result +pub(crate) fn decode_value<'a, T>( + kv: (Cow<'a, [u8]>, Cow<'a, [u8]>), +) -> Result where T: Table, { @@ -72,7 +74,7 @@ where } /// Helper function to decode a value. It can be a key or subkey. -pub(crate) fn decode_one(value: Cow<'_, [u8]>) -> Result +pub(crate) fn decode_one(value: Cow<'_, [u8]>) -> Result where T: Table, { diff --git a/crates/storage/provider/src/post_state/mod.rs b/crates/storage/provider/src/post_state/mod.rs index cf164bd3a..e5a686aaf 100644 --- a/crates/storage/provider/src/post_state/mod.rs +++ b/crates/storage/provider/src/post_state/mod.rs @@ -4,7 +4,7 @@ use reth_db::{ models::{AccountBeforeTx, BlockNumberAddress}, tables, transaction::{DbTx, DbTxMut}, - Error as DbError, + DatabaseError as DbError, }; use reth_primitives::{ bloom::logs_bloom, keccak256, proofs::calculate_receipt_root_ref, Account, Address, diff --git a/crates/storage/provider/src/providers/database.rs b/crates/storage/provider/src/providers/database.rs index 2aca06848..5383b571a 100644 --- a/crates/storage/provider/src/providers/database.rs +++ b/crates/storage/provider/src/providers/database.rs @@ -486,7 +486,7 @@ impl EvmEnvProvider for ShareableDatabase { fn read_sealed_header<'a, TX>( tx: &TX, block_number: u64, -) -> std::result::Result, reth_interfaces::db::Error> +) -> std::result::Result, reth_interfaces::db::DatabaseError> where TX: DbTx<'a> + Send + Sync, { @@ -505,7 +505,7 @@ where fn is_latest_block_number<'a, TX>( tx: &TX, block_number: BlockNumber, -) -> std::result::Result +) -> std::result::Result where TX: DbTx<'a> + Send + Sync, { @@ -520,7 +520,7 @@ where #[inline] fn best_block_number<'a, TX>( tx: &TX, -) -> std::result::Result, reth_interfaces::db::Error> +) -> std::result::Result, reth_interfaces::db::DatabaseError> where TX: DbTx<'a> + Send + Sync, { @@ -531,7 +531,7 @@ where #[inline] fn last_canonical_header<'a, TX>( tx: &TX, -) -> std::result::Result, reth_interfaces::db::Error> +) -> std::result::Result, reth_interfaces::db::DatabaseError> where TX: DbTx<'a> + Send + Sync, { diff --git a/crates/storage/provider/src/transaction.rs b/crates/storage/provider/src/transaction.rs index ac1d8ee7d..528adc164 100644 --- a/crates/storage/provider/src/transaction.rs +++ b/crates/storage/provider/src/transaction.rs @@ -17,7 +17,7 @@ use reth_db::{ transaction::{DbTx, DbTxMut, DbTxMutGAT}, BlockNumberList, }; -use reth_interfaces::{db::Error as DbError, provider::ProviderError}; +use reth_interfaces::{db::DatabaseError as DbError, provider::ProviderError}; use reth_primitives::{ keccak256, Account, Address, BlockHash, BlockNumber, ChainSpec, Hardfork, Header, SealedBlock, SealedBlockWithSenders, StorageEntry, TransactionSigned, TransactionSignedEcRecovered, diff --git a/crates/trie/src/errors.rs b/crates/trie/src/errors.rs index 4743e9f74..6b742318a 100644 --- a/crates/trie/src/errors.rs +++ b/crates/trie/src/errors.rs @@ -5,13 +5,13 @@ use thiserror::Error; pub enum StateRootError { /// Internal database error. #[error(transparent)] - DB(#[from] reth_db::Error), + DB(#[from] reth_db::DatabaseError), /// Storage root error. #[error(transparent)] StorageRootError(#[from] StorageRootError), } -impl From for reth_db::Error { +impl From for reth_db::DatabaseError { fn from(err: StateRootError) -> Self { match err { StateRootError::DB(err) => err, @@ -25,5 +25,5 @@ impl From for reth_db::Error { pub enum StorageRootError { /// Internal database error. #[error(transparent)] - DB(#[from] reth_db::Error), + DB(#[from] reth_db::DatabaseError), } diff --git a/crates/trie/src/hashed_cursor/default.rs b/crates/trie/src/hashed_cursor/default.rs index e90ac1021..0a7e04873 100644 --- a/crates/trie/src/hashed_cursor/default.rs +++ b/crates/trie/src/hashed_cursor/default.rs @@ -10,11 +10,11 @@ impl<'a, 'tx, TX: DbTx<'tx>> HashedCursorFactory<'a> for TX { type AccountCursor = >::Cursor where Self: 'a; type StorageCursor = >::DupCursor where Self: 'a; - fn hashed_account_cursor(&'a self) -> Result { + fn hashed_account_cursor(&'a self) -> Result { self.cursor_read::() } - fn hashed_storage_cursor(&'a self) -> Result { + fn hashed_storage_cursor(&'a self) -> Result { self.cursor_dup_read::() } } @@ -23,11 +23,11 @@ impl<'tx, C> HashedAccountCursor for C where C: DbCursorRO<'tx, tables::HashedAccount>, { - fn seek(&mut self, key: H256) -> Result, reth_db::Error> { + fn seek(&mut self, key: H256) -> Result, reth_db::DatabaseError> { self.seek(key) } - fn next(&mut self) -> Result, reth_db::Error> { + fn next(&mut self) -> Result, reth_db::DatabaseError> { self.next() } } @@ -36,15 +36,19 @@ impl<'tx, C> HashedStorageCursor for C where C: DbCursorRO<'tx, tables::HashedStorage> + DbDupCursorRO<'tx, tables::HashedStorage>, { - fn is_empty(&mut self, key: H256) -> Result { + fn is_empty(&mut self, key: H256) -> Result { Ok(self.seek_exact(key)?.is_none()) } - fn seek(&mut self, key: H256, subkey: H256) -> Result, reth_db::Error> { + fn seek( + &mut self, + key: H256, + subkey: H256, + ) -> Result, reth_db::DatabaseError> { self.seek_by_key_subkey(key, subkey) } - fn next(&mut self) -> Result, reth_db::Error> { + fn next(&mut self) -> Result, reth_db::DatabaseError> { self.next_dup_val() } } diff --git a/crates/trie/src/hashed_cursor/mod.rs b/crates/trie/src/hashed_cursor/mod.rs index 7f1592f1b..7659862d8 100644 --- a/crates/trie/src/hashed_cursor/mod.rs +++ b/crates/trie/src/hashed_cursor/mod.rs @@ -19,29 +19,33 @@ pub trait HashedCursorFactory<'a> { Self: 'a; /// Returns a cursor for iterating over all hashed accounts in the state. - fn hashed_account_cursor(&'a self) -> Result; + fn hashed_account_cursor(&'a self) -> Result; /// Returns a cursor for iterating over all hashed storage entries in the state. - fn hashed_storage_cursor(&'a self) -> Result; + fn hashed_storage_cursor(&'a self) -> Result; } /// The cursor for iterating over hashed accounts. pub trait HashedAccountCursor { /// Seek an entry greater or equal to the given key and position the cursor there. - fn seek(&mut self, key: H256) -> Result, reth_db::Error>; + fn seek(&mut self, key: H256) -> Result, reth_db::DatabaseError>; /// Move the cursor to the next entry and return it. - fn next(&mut self) -> Result, reth_db::Error>; + fn next(&mut self) -> Result, reth_db::DatabaseError>; } /// The cursor for iterating over hashed storage entries. pub trait HashedStorageCursor { /// Returns `true` if there are no entries for a given key. - fn is_empty(&mut self, key: H256) -> Result; + fn is_empty(&mut self, key: H256) -> Result; /// Seek an entry greater or equal to the given key/subkey and position the cursor there. - fn seek(&mut self, key: H256, subkey: H256) -> Result, reth_db::Error>; + fn seek( + &mut self, + key: H256, + subkey: H256, + ) -> Result, reth_db::DatabaseError>; /// Move the cursor to the next entry and return it. - fn next(&mut self) -> Result, reth_db::Error>; + fn next(&mut self) -> Result, reth_db::DatabaseError>; } diff --git a/crates/trie/src/hashed_cursor/post_state.rs b/crates/trie/src/hashed_cursor/post_state.rs index f43ab20a1..e46927351 100644 --- a/crates/trie/src/hashed_cursor/post_state.rs +++ b/crates/trie/src/hashed_cursor/post_state.rs @@ -72,12 +72,12 @@ where type AccountCursor = HashedPostStateAccountCursor<'b, >::Cursor> where Self: 'a ; type StorageCursor = HashedPostStateStorageCursor<'b, >::DupCursor> where Self: 'a; - fn hashed_account_cursor(&'a self) -> Result { + fn hashed_account_cursor(&'a self) -> Result { let cursor = self.tx.cursor_read::()?; Ok(HashedPostStateAccountCursor { post_state: self.post_state, cursor, last_account: None }) } - fn hashed_storage_cursor(&'a self) -> Result { + fn hashed_storage_cursor(&'a self) -> Result { let cursor = self.tx.cursor_dup_read::()?; Ok(HashedPostStateStorageCursor { post_state: self.post_state, @@ -109,7 +109,7 @@ where &self, post_state_item: Option<(H256, Account)>, db_item: Option<(H256, Account)>, - ) -> Result, reth_db::Error> { + ) -> Result, reth_db::DatabaseError> { let result = match (post_state_item, db_item) { // If both are not empty, return the smallest of the two // Post state is given precedence if keys are equal @@ -137,7 +137,7 @@ impl<'b, 'tx, C> HashedAccountCursor for HashedPostStateAccountCursor<'b, C> where C: DbCursorRO<'tx, tables::HashedAccount>, { - fn seek(&mut self, key: H256) -> Result, reth_db::Error> { + fn seek(&mut self, key: H256) -> Result, reth_db::DatabaseError> { self.last_account = None; // Attempt to find the account in poststate. @@ -171,7 +171,7 @@ where Ok(result) } - fn next(&mut self) -> Result, reth_db::Error> { + fn next(&mut self) -> Result, reth_db::DatabaseError> { let last_account = match self.last_account.as_ref() { Some(account) => account, None => return Ok(None), // no previous entry was found @@ -221,7 +221,7 @@ impl<'b, C> HashedPostStateStorageCursor<'b, C> { &self, post_state_item: Option<(&H256, &U256)>, db_item: Option, - ) -> Result, reth_db::Error> { + ) -> Result, reth_db::DatabaseError> { let result = match (post_state_item, db_item) { // If both are not empty, return the smallest of the two // Post state is given precedence if keys are equal @@ -249,7 +249,7 @@ impl<'b, 'tx, C> HashedStorageCursor for HashedPostStateStorageCursor<'b, C> where C: DbCursorRO<'tx, tables::HashedStorage> + DbDupCursorRO<'tx, tables::HashedStorage>, { - fn is_empty(&mut self, key: H256) -> Result { + fn is_empty(&mut self, key: H256) -> Result { let is_empty = match self.post_state.storages.get(&key) { Some(storage) => storage.wiped && storage.storage.is_empty(), None => self.cursor.seek_exact(key)?.is_none(), @@ -257,7 +257,11 @@ where Ok(is_empty) } - fn seek(&mut self, key: H256, subkey: H256) -> Result, reth_db::Error> { + fn seek( + &mut self, + key: H256, + subkey: H256, + ) -> Result, reth_db::DatabaseError> { self.last_slot = None; self.account = Some(key); @@ -289,7 +293,7 @@ where Ok(result) } - fn next(&mut self) -> Result, reth_db::Error> { + fn next(&mut self) -> Result, reth_db::DatabaseError> { let account = self.account.expect("`seek` must be called first"); let last_slot = match self.last_slot.as_ref() { diff --git a/crates/trie/src/prefix_set/loader.rs b/crates/trie/src/prefix_set/loader.rs index 6d46e871f..dc9e807f3 100644 --- a/crates/trie/src/prefix_set/loader.rs +++ b/crates/trie/src/prefix_set/loader.rs @@ -5,7 +5,7 @@ use reth_db::{ models::{AccountBeforeTx, BlockNumberAddress}, tables, transaction::DbTx, - Error, + DatabaseError, }; use reth_primitives::{keccak256, trie::Nibbles, BlockNumber, StorageEntry, H256}; use std::{collections::HashMap, ops::RangeInclusive}; @@ -29,7 +29,7 @@ where pub fn load( self, range: RangeInclusive, - ) -> Result<(PrefixSet, HashMap), Error> { + ) -> Result<(PrefixSet, HashMap), DatabaseError> { // Initialize prefix sets. let mut account_prefix_set = PrefixSet::default(); let mut storage_prefix_set: HashMap = HashMap::default(); diff --git a/crates/trie/src/trie_cursor/account_cursor.rs b/crates/trie/src/trie_cursor/account_cursor.rs index 82639d075..cb2db71d8 100644 --- a/crates/trie/src/trie_cursor/account_cursor.rs +++ b/crates/trie/src/trie_cursor/account_cursor.rs @@ -1,6 +1,6 @@ use super::TrieCursor; use crate::updates::TrieKey; -use reth_db::{cursor::DbCursorRO, tables, Error}; +use reth_db::{cursor::DbCursorRO, tables, DatabaseError}; use reth_primitives::trie::{BranchNodeCompact, StoredNibbles}; /// A cursor over the account trie. @@ -20,15 +20,18 @@ where fn seek_exact( &mut self, key: StoredNibbles, - ) -> Result, BranchNodeCompact)>, Error> { + ) -> Result, BranchNodeCompact)>, DatabaseError> { Ok(self.0.seek_exact(key)?.map(|value| (value.0.inner.to_vec(), value.1))) } - fn seek(&mut self, key: StoredNibbles) -> Result, BranchNodeCompact)>, Error> { + fn seek( + &mut self, + key: StoredNibbles, + ) -> Result, BranchNodeCompact)>, DatabaseError> { Ok(self.0.seek(key)?.map(|value| (value.0.inner.to_vec(), value.1))) } - fn current(&mut self) -> Result, Error> { + fn current(&mut self) -> Result, DatabaseError> { Ok(self.0.current()?.map(|(k, _)| TrieKey::AccountNode(k))) } } diff --git a/crates/trie/src/trie_cursor/mod.rs b/crates/trie/src/trie_cursor/mod.rs index aae524e8f..85de68875 100644 --- a/crates/trie/src/trie_cursor/mod.rs +++ b/crates/trie/src/trie_cursor/mod.rs @@ -1,5 +1,5 @@ use crate::updates::TrieKey; -use reth_db::{table::Key, Error}; +use reth_db::{table::Key, DatabaseError}; use reth_primitives::trie::BranchNodeCompact; mod account_cursor; @@ -13,11 +13,12 @@ pub use self::{ /// A cursor for navigating a trie that works with both Tables and DupSort tables. pub trait TrieCursor { /// Move the cursor to the key and return if it is an exact match. - fn seek_exact(&mut self, key: K) -> Result, BranchNodeCompact)>, Error>; + fn seek_exact(&mut self, key: K) + -> Result, BranchNodeCompact)>, DatabaseError>; /// Move the cursor to the key and return a value matching of greater than the key. - fn seek(&mut self, key: K) -> Result, BranchNodeCompact)>, Error>; + fn seek(&mut self, key: K) -> Result, BranchNodeCompact)>, DatabaseError>; /// Get the current entry. - fn current(&mut self) -> Result, Error>; + fn current(&mut self) -> Result, DatabaseError>; } diff --git a/crates/trie/src/trie_cursor/storage_cursor.rs b/crates/trie/src/trie_cursor/storage_cursor.rs index ae0362b4c..317bf690d 100644 --- a/crates/trie/src/trie_cursor/storage_cursor.rs +++ b/crates/trie/src/trie_cursor/storage_cursor.rs @@ -2,7 +2,7 @@ use super::TrieCursor; use crate::updates::TrieKey; use reth_db::{ cursor::{DbCursorRO, DbDupCursorRO}, - tables, Error, + tables, DatabaseError, }; use reth_primitives::{ trie::{BranchNodeCompact, StoredNibblesSubKey}, @@ -30,7 +30,7 @@ where fn seek_exact( &mut self, key: StoredNibblesSubKey, - ) -> Result, BranchNodeCompact)>, Error> { + ) -> Result, BranchNodeCompact)>, DatabaseError> { Ok(self .cursor .seek_by_key_subkey(self.hashed_address, key.clone())? @@ -41,14 +41,14 @@ where fn seek( &mut self, key: StoredNibblesSubKey, - ) -> Result, BranchNodeCompact)>, Error> { + ) -> Result, BranchNodeCompact)>, DatabaseError> { Ok(self .cursor .seek_by_key_subkey(self.hashed_address, key)? .map(|value| (value.nibbles.inner.to_vec(), value.node))) } - fn current(&mut self) -> Result, Error> { + fn current(&mut self) -> Result, DatabaseError> { Ok(self.cursor.current()?.map(|(k, v)| TrieKey::StorageNode(k, v.nibbles))) } } diff --git a/crates/trie/src/updates.rs b/crates/trie/src/updates.rs index 0b666915c..e3fe3e311 100644 --- a/crates/trie/src/updates.rs +++ b/crates/trie/src/updates.rs @@ -95,7 +95,7 @@ impl TrieUpdates { } /// Flush updates all aggregated updates to the database. - pub fn flush<'a, 'tx, TX>(self, tx: &'a TX) -> Result<(), reth_db::Error> + pub fn flush<'a, 'tx, TX>(self, tx: &'a TX) -> Result<(), reth_db::DatabaseError> where TX: DbTx<'tx> + DbTxMut<'tx>, { diff --git a/crates/trie/src/walker.rs b/crates/trie/src/walker.rs index 3245ab097..3f6c86196 100644 --- a/crates/trie/src/walker.rs +++ b/crates/trie/src/walker.rs @@ -3,7 +3,7 @@ use crate::{ trie_cursor::{CursorSubNode, TrieCursor}, updates::TrieUpdates, }; -use reth_db::{table::Key, Error}; +use reth_db::{table::Key, DatabaseError}; use reth_primitives::{ trie::{BranchNodeCompact, Nibbles}, H256, @@ -103,7 +103,7 @@ impl<'a, K: Key + From>, C: TrieCursor> TrieWalker<'a, K, C> { /// # Returns /// /// * `Result, Error>` - The next key in the trie or an error. - pub fn advance(&mut self) -> Result, Error> { + pub fn advance(&mut self) -> Result, DatabaseError> { if let Some(last) = self.stack.last() { if !self.can_skip_current_node && self.children_are_in_trie() { // If we can't skip the current node and the children are in the trie, @@ -126,7 +126,7 @@ impl<'a, K: Key + From>, C: TrieCursor> TrieWalker<'a, K, C> { } /// Retrieves the current root node from the DB, seeking either the exact node or the next one. - fn node(&mut self, exact: bool) -> Result, Error> { + fn node(&mut self, exact: bool) -> Result, DatabaseError> { let key = self.key().expect("key must exist"); let entry = if exact { self.cursor.seek_exact(key.hex_data.into())? @@ -142,7 +142,7 @@ impl<'a, K: Key + From>, C: TrieCursor> TrieWalker<'a, K, C> { } /// Consumes the next node in the trie, updating the stack. - fn consume_node(&mut self) -> Result<(), Error> { + fn consume_node(&mut self) -> Result<(), DatabaseError> { let Some((key, node)) = self.node(false)? else { // If no next node is found, clear the stack. self.stack.clear(); @@ -174,7 +174,10 @@ impl<'a, K: Key + From>, C: TrieCursor> TrieWalker<'a, K, C> { } /// Moves to the next sibling node in the trie, updating the stack. - fn move_to_next_sibling(&mut self, allow_root_to_child_nibble: bool) -> Result<(), Error> { + fn move_to_next_sibling( + &mut self, + allow_root_to_child_nibble: bool, + ) -> Result<(), DatabaseError> { let Some(subnode) = self.stack.last_mut() else { return Ok(()); };