diff --git a/crates/optimism/trie/src/api.rs b/crates/optimism/trie/src/api.rs index 27483c133a1..ed42b1615cb 100644 --- a/crates/optimism/trie/src/api.rs +++ b/crates/optimism/trie/src/api.rs @@ -1,55 +1,12 @@ //! Storage API for external storage of intermediary trie nodes. +use crate::OpProofsStorageResult; use alloy_eips::eip1898::BlockWithParent; use alloy_primitives::{map::HashMap, B256, U256}; use auto_impl::auto_impl; -use reth_db::DatabaseError; use reth_primitives_traits::Account; use reth_trie::{updates::TrieUpdates, BranchNodeCompact, HashedPostState, Nibbles}; use std::fmt::Debug; -use thiserror::Error; - -/// Error type for storage operations -#[derive(Debug, Error)] -pub enum OpProofsStorageError { - /// No blocks found - #[error("No blocks found")] - NoBlocksFound, - /// Parent block number is less than earliest stored block number - #[error("Parent block number is less than earliest stored block number")] - UnknownParent, - /// Block is out of order - #[error("Block {block_number} is out of order (parent: {parent_block_hash}, latest stored block hash: {latest_block_hash})")] - OutOfOrder { - /// The block number being inserted - block_number: u64, - /// The parent hash of the block being inserted - parent_block_hash: B256, - /// block hash of the latest stored block - latest_block_hash: B256, - }, - /// Block update failed since parent state - #[error("Cannot execute block updates for block {0} without parent state {1} (latest stored block number: {2})")] - BlockUpdateFailed(u64, u64, u64), - /// State root mismatch - #[error("State root mismatch for block {0} (have: {1}, expected: {2})")] - StateRootMismatch(u64, B256, B256), - /// Error occurred while interacting with the database. - #[error(transparent)] - DatabaseError(#[from] DatabaseError), - /// Other error - #[error("Other error: {0}")] - Other(eyre::Error), -} - -impl From for DatabaseError { - fn from(error: OpProofsStorageError) -> Self { - Self::Other(error.to_string()) - } -} - -/// Result type for storage operations -pub type OpProofsStorageResult = Result; /// Seeks and iterates over trie nodes in the database by path (lexicographical order) pub trait OpProofsTrieCursorRO: Send + Sync { diff --git a/crates/optimism/trie/src/error.rs b/crates/optimism/trie/src/error.rs new file mode 100644 index 00000000000..7dd9a5484ce --- /dev/null +++ b/crates/optimism/trie/src/error.rs @@ -0,0 +1,47 @@ +//! Errors interfacing with [`OpProofsStore`](crate::OpProofsStore) type. + +use alloy_primitives::B256; +use reth_db::DatabaseError; +use thiserror::Error; + +/// Error type for storage operations +#[derive(Debug, Error)] +pub enum OpProofsStorageError { + /// No blocks found + #[error("No blocks found")] + NoBlocksFound, + /// Parent block number is less than earliest stored block number + #[error("Parent block number is less than earliest stored block number")] + UnknownParent, + /// Block is out of order + #[error("Block {block_number} is out of order (parent: {parent_block_hash}, latest stored block hash: {latest_block_hash})")] + OutOfOrder { + /// The block number being inserted + block_number: u64, + /// The parent hash of the block being inserted + parent_block_hash: B256, + /// block hash of the latest stored block + latest_block_hash: B256, + }, + /// Block update failed since parent state + #[error("Cannot execute block updates for block {0} without parent state {1} (latest stored block number: {2})")] + BlockUpdateFailed(u64, u64, u64), + /// State root mismatch + #[error("State root mismatch for block {0} (have: {1}, expected: {2})")] + StateRootMismatch(u64, B256, B256), + /// Error occurred while interacting with the database. + #[error(transparent)] + DatabaseError(#[from] DatabaseError), + /// Other error + #[error("Other error: {0}")] + Other(eyre::Error), +} + +impl From for DatabaseError { + fn from(error: OpProofsStorageError) -> Self { + Self::Other(error.to_string()) + } +} + +/// Result type for storage operations +pub type OpProofsStorageResult = Result; diff --git a/crates/optimism/trie/src/lib.rs b/crates/optimism/trie/src/lib.rs index a4e57110c97..cee57d0af82 100644 --- a/crates/optimism/trie/src/lib.rs +++ b/crates/optimism/trie/src/lib.rs @@ -13,10 +13,7 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] pub mod api; -pub use api::{ - BlockStateDiff, OpProofsHashedCursorRO, OpProofsStorageError, OpProofsStorageResult, - OpProofsStore, OpProofsTrieCursorRO, -}; +pub use api::{BlockStateDiff, OpProofsHashedCursorRO, OpProofsStore, OpProofsTrieCursorRO}; pub mod backfill; pub use backfill::BackfillJob; @@ -52,3 +49,6 @@ pub use cursor::{OpProofsHashedAccountCursor, OpProofsHashedStorageCursor, OpPro pub mod cursor_factory; pub use cursor_factory::{OpProofsHashedAccountCursorFactory, OpProofsTrieCursorFactory}; + +pub mod error; +pub use error::{OpProofsStorageError, OpProofsStorageResult}; diff --git a/crates/optimism/trie/src/live.rs b/crates/optimism/trie/src/live.rs index c2ac5fc3fb4..23063a4ee84 100644 --- a/crates/optimism/trie/src/live.rs +++ b/crates/optimism/trie/src/live.rs @@ -1,9 +1,8 @@ //! Live trie collector for external proofs storage. use crate::{ - api::{BlockStateDiff, OpProofsStorageError, OpProofsStore}, - provider::OpProofsStateProviderRef, - OpProofsStorage, + provider::OpProofsStateProviderRef, BlockStateDiff, OpProofsStorage, OpProofsStorageError, + OpProofsStore, }; use alloy_eips::{eip1898::BlockWithParent, NumHash}; use derive_more::Constructor;