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
13 changes: 12 additions & 1 deletion crates/optimism/trie/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ use thiserror::Error;
/// Error type for storage operations
#[derive(Debug, Error)]
pub enum OpProofsStorageError {
// TODO: add more errors once we know what they are
/// 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 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),
Expand Down
24 changes: 11 additions & 13 deletions crates/optimism/trie/src/live.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Live trie collector for external proofs storage.

use crate::{
api::{BlockStateDiff, OpProofsStorage},
api::{BlockStateDiff, OpProofsStorage, OpProofsStorageError},
provider::OpProofsStateProviderRef,
};
use reth_evm::{execute::Executor, ConfigureEvm};
Expand Down Expand Up @@ -49,25 +49,23 @@ where
self.storage.get_earliest_block_number().await?,
self.storage.get_latest_block_number().await?,
) else {
return Err(eyre::eyre!("No blocks stored"));
return Err(OpProofsStorageError::NoBlocksFound.into());
};

let fetch_block_duration = start.elapsed();

let parent_block_number = block.number() - 1;
if parent_block_number < earliest {
return Err(eyre::eyre!(
"Parent block number is less than earliest stored block number"
));
return Err(OpProofsStorageError::UnknownParent.into());
}

if parent_block_number > latest {
return Err(eyre::eyre!(
"Cannot execute block updates for block {} without parent state {} (latest stored block number: {})",
return Err(OpProofsStorageError::BlockUpdateFailed(
block.number(),
parent_block_number,
latest
));
latest,
)
.into());
}

let block_number = block.number();
Expand Down Expand Up @@ -97,12 +95,12 @@ where
let calculate_state_root_duration = start.elapsed() - execute_block_duration;

if state_root != block.state_root() {
return Err(eyre::eyre!(
"State root mismatch for block {} (have: {}, expected: {})",
return Err(OpProofsStorageError::StateRootMismatch(
block.number(),
state_root,
block.state_root()
));
block.state_root(),
)
.into());
}

self.storage
Expand Down
Loading