Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions crates/optimism/trie/src/api.rs
Original file line number Diff line number Diff line change
@@ -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<OpProofsStorageError> for DatabaseError {
fn from(error: OpProofsStorageError) -> Self {
Self::Other(error.to_string())
}
}

/// Result type for storage operations
pub type OpProofsStorageResult<T> = Result<T, OpProofsStorageError>;

/// Seeks and iterates over trie nodes in the database by path (lexicographical order)
pub trait OpProofsTrieCursorRO: Send + Sync {
Expand Down
47 changes: 47 additions & 0 deletions crates/optimism/trie/src/error.rs
Original file line number Diff line number Diff line change
@@ -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<OpProofsStorageError> for DatabaseError {
fn from(error: OpProofsStorageError) -> Self {
Self::Other(error.to_string())
}
}

/// Result type for storage operations
pub type OpProofsStorageResult<T> = Result<T, OpProofsStorageError>;
8 changes: 4 additions & 4 deletions crates/optimism/trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
5 changes: 2 additions & 3 deletions crates/optimism/trie/src/live.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down