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
20 changes: 20 additions & 0 deletions crates/optimism/trie/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use alloy_primitives::B256;
use reth_db::DatabaseError;
use reth_execution_errors::BlockExecutionError;
use reth_provider::ProviderError;
use reth_trie::Nibbles;
use std::sync::Arc;
use thiserror::Error;
Expand Down Expand Up @@ -82,6 +84,12 @@ pub enum OpProofsStorageError {
/// Error occurred while trying to acquire a lock.
#[error("failed lock attempt")]
TryLockError,
/// Error occurred during block execution.
#[error(transparent)]
ExecutionError(Arc<BlockExecutionError>),
/// Error occurred while interacting with the provider.
#[error(transparent)]
ProviderError(Arc<ProviderError>),
}

impl From<TryLockError> for OpProofsStorageError {
Expand All @@ -90,6 +98,18 @@ impl From<TryLockError> for OpProofsStorageError {
}
}

impl From<BlockExecutionError> for OpProofsStorageError {
fn from(error: BlockExecutionError) -> Self {
Self::ExecutionError(Arc::new(error))
}
}

impl From<ProviderError> for OpProofsStorageError {
fn from(error: ProviderError) -> Self {
Self::ProviderError(Arc::new(error))
}
}

impl From<OpProofsStorageError> for DatabaseError {
fn from(error: OpProofsStorageError) -> Self {
match error {
Expand Down
15 changes: 6 additions & 9 deletions crates/optimism/trie/src/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
pub async fn execute_and_store_block_updates(
&self,
block: &RecoveredBlock<BlockTy<Evm::Primitives>>,
) -> eyre::Result<()> {
) -> Result<(), OpProofsStorageError> {
let mut operation_durations = OperationDurations::default();

let start = Instant::now();
Expand All @@ -49,21 +49,20 @@ where
self.storage.get_earliest_block_number().await?,
self.storage.get_latest_block_number().await?,
) else {
return Err(OpProofsStorageError::NoBlocksFound.into());
return Err(OpProofsStorageError::NoBlocksFound);
};

let parent_block_number = block.number() - 1;
if parent_block_number < earliest {
return Err(OpProofsStorageError::UnknownParent.into());
return Err(OpProofsStorageError::UnknownParent);
}

if parent_block_number > latest {
return Err(OpProofsStorageError::MissingParentBlock {
block_number: block.number(),
parent_block_number,
latest_block_number: latest,
}
.into());
});
}

let block_ref =
Expand All @@ -80,8 +79,7 @@ where
let db = StateProviderDatabase::new(&state_provider);
let block_executor = self.evm_config.batch_executor(db);

let execution_result =
block_executor.execute(&(*block).clone()).map_err(|err| eyre::eyre!(err))?;
let execution_result = block_executor.execute(&(*block).clone())?;

operation_durations.execution_duration_seconds = start.elapsed();

Expand All @@ -97,8 +95,7 @@ where
block_number: block.number(),
current_state_hash: state_root,
expected_state_hash: block.state_root(),
}
.into());
});
}

let update_result = self
Expand Down
10 changes: 2 additions & 8 deletions crates/optimism/trie/tests/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,7 @@ async fn test_execute_and_store_block_updates_missing_parent_block() {
// EXPECT: MissingParentBlock
let err = collector.execute_and_store_block_updates(&incorrect_block).await.unwrap_err();

assert!(matches!(
err.downcast_ref::<OpProofsStorageError>().unwrap(),
OpProofsStorageError::MissingParentBlock { .. }
));
assert!(matches!(err, OpProofsStorageError::MissingParentBlock { .. }));
}

#[tokio::test]
Expand Down Expand Up @@ -425,10 +422,7 @@ async fn test_execute_and_store_block_updates_state_root_mismatch() {
// EXPECT: StateRootMismatch
let err = collector.execute_and_store_block_updates(&block).await.unwrap_err();

assert!(matches!(
err.downcast_ref::<OpProofsStorageError>(),
Some(OpProofsStorageError::StateRootMismatch { .. })
));
assert!(matches!(err, OpProofsStorageError::StateRootMismatch { .. }));
}

/// Test with multiple blocks before and after backfill
Expand Down
Loading