From f4d4e23c8ebf93e9e0e160dc5124e437c9b04fdc Mon Sep 17 00:00:00 2001 From: clabby Date: Wed, 22 Jan 2025 15:41:40 -0500 Subject: [PATCH] chore(executor): Remove `anyhow` dev-dependency (#937) --- Cargo.lock | 1 - crates/executor/Cargo.toml | 1 - crates/executor/benches/execution.rs | 34 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 180276d4..8cf2edae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2428,7 +2428,6 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "alloy-rpc-types-engine", - "anyhow", "criterion", "kona-mpt", "maili-genesis", diff --git a/crates/executor/Cargo.toml b/crates/executor/Cargo.toml index 76a27954..1b2fd94e 100644 --- a/crates/executor/Cargo.toml +++ b/crates/executor/Cargo.toml @@ -37,7 +37,6 @@ tracing.workspace = true [dev-dependencies] rand.workspace = true -anyhow.workspace = true alloy-rlp.workspace = true serde_json.workspace = true alloy-rpc-types-engine.workspace = true diff --git a/crates/executor/benches/execution.rs b/crates/executor/benches/execution.rs index d018cdc3..6a14b1bb 100644 --- a/crates/executor/benches/execution.rs +++ b/crates/executor/benches/execution.rs @@ -1,11 +1,11 @@ -#![allow(missing_docs)] //! Benches for the [StatelessL2BlockExecutor] implementation. +#![allow(missing_docs)] + use alloy_consensus::{Header, Sealable}; use alloy_primitives::{address, b256, hex, Bytes, B256}; use alloy_rlp::Decodable; use alloy_rpc_types_engine::PayloadAttributes; -use anyhow::{anyhow, Result}; use criterion::{criterion_group, criterion_main, Bencher, Criterion}; use kona_executor::{StatelessL2BlockExecutor, TrieDBProvider}; use kona_mpt::{NoopTrieHinter, TrieNode, TrieProvider}; @@ -22,6 +22,14 @@ struct TestdataTrieProvider { preimages: HashMap, } +#[derive(Debug, thiserror::Error)] +enum TestdataTrieProviderError { + #[error("RLP error: {0}")] + Rlp(alloy_rlp::Error), + #[error("Preimage not found for key: {0}")] + PreimageNotFound(B256), +} + impl TestdataTrieProvider { /// Constructs a new [TestdataTrieProvider] with the given testdata folder. pub(crate) fn new(testdata_folder: &str) -> Self { @@ -35,35 +43,33 @@ impl TestdataTrieProvider { } impl TrieProvider for TestdataTrieProvider { - type Error = anyhow::Error; + type Error = TestdataTrieProviderError; - fn trie_node_by_hash(&self, key: B256) -> Result { + fn trie_node_by_hash(&self, key: B256) -> Result { TrieNode::decode( &mut self .preimages .get(&key) .cloned() - .ok_or_else(|| anyhow!("Preimage not found for key: {}", key))? + .ok_or(TestdataTrieProviderError::PreimageNotFound(key))? .as_ref(), ) - .map_err(Into::into) + .map_err(TestdataTrieProviderError::Rlp) } } impl TrieDBProvider for TestdataTrieProvider { - fn bytecode_by_hash(&self, code_hash: B256) -> Result { + fn bytecode_by_hash(&self, code_hash: B256) -> Result { self.preimages .get(&code_hash) .cloned() - .ok_or_else(|| anyhow!("Bytecode not found for hash: {}", code_hash)) + .ok_or(TestdataTrieProviderError::PreimageNotFound(code_hash)) } - fn header_by_hash(&self, hash: B256) -> Result
{ - let encoded_header = self - .preimages - .get(&hash) - .ok_or_else(|| anyhow!("Header not found for hash: {}", hash))?; - Header::decode(&mut encoded_header.as_ref()).map_err(|e| anyhow!(e)) + fn header_by_hash(&self, hash: B256) -> Result { + let encoded_header = + self.preimages.get(&hash).ok_or(TestdataTrieProviderError::PreimageNotFound(hash))?; + Header::decode(&mut encoded_header.as_ref()).map_err(TestdataTrieProviderError::Rlp) } }