From bf8763192566754b47b2d6cc19aa363328e23e6d Mon Sep 17 00:00:00 2001 From: clabby Date: Wed, 22 Jan 2025 11:34:52 -0500 Subject: [PATCH] chore(mpt): Remove `anyhow` dev-dependency (#919) --- Cargo.lock | 2 -- crates/executor/src/db/mod.rs | 1 - crates/executor/src/db/traits.rs | 4 +-- crates/mpt/Cargo.toml | 1 - crates/mpt/src/test_util.rs | 31 +++++++++++++---------- crates/mpt/src/traits.rs | 6 ++--- crates/proof-sdk/std-fpvm-proc/Cargo.toml | 1 - 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 201b0c5cc..180276d42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2510,7 +2510,6 @@ dependencies = [ "alloy-rpc-types", "alloy-transport-http", "alloy-trie", - "anyhow", "criterion", "pprof", "proptest", @@ -2604,7 +2603,6 @@ dependencies = [ name = "kona-std-fpvm-proc" version = "0.1.2" dependencies = [ - "anyhow", "cfg-if", "kona-std-fpvm", "proc-macro2", diff --git a/crates/executor/src/db/mod.rs b/crates/executor/src/db/mod.rs index af77fcaa9..782bffcd6 100644 --- a/crates/executor/src/db/mod.rs +++ b/crates/executor/src/db/mod.rs @@ -48,7 +48,6 @@ pub use traits::{NoopTrieDBProvider, TrieDBProvider}; /// ```rust /// use alloy_consensus::{Header, Sealable}; /// use alloy_primitives::{Bytes, B256}; -/// use anyhow::Result; /// use kona_executor::{NoopTrieDBProvider, TrieDB}; /// use kona_mpt::NoopTrieHinter; /// use revm::{db::states::bundle_state::BundleRetention, EvmBuilder, StateBuilder}; diff --git a/crates/executor/src/db/traits.rs b/crates/executor/src/db/traits.rs index 5445ac5fa..8061c1417 100644 --- a/crates/executor/src/db/traits.rs +++ b/crates/executor/src/db/traits.rs @@ -16,7 +16,7 @@ pub trait TrieDBProvider: TrieProvider { /// /// ## Returns /// - Ok(Bytes): The bytecode of the contract. - /// - Err(anyhow::Error): If the bytecode hash could not be fetched. + /// - Err(Self::Error): If the bytecode hash could not be fetched. /// /// [TrieDB]: crate::TrieDB fn bytecode_by_hash(&self, code_hash: B256) -> Result; @@ -28,7 +28,7 @@ pub trait TrieDBProvider: TrieProvider { /// /// ## Returns /// - Ok(Bytes): The [Header]. - /// - Err(anyhow::Error): If the [Header] could not be fetched. + /// - Err(Self::Error): If the [Header] could not be fetched. /// /// [TrieDB]: crate::TrieDB fn header_by_hash(&self, hash: B256) -> Result; diff --git a/crates/mpt/Cargo.toml b/crates/mpt/Cargo.toml index 0e4e5ebf3..8931b5e89 100644 --- a/crates/mpt/Cargo.toml +++ b/crates/mpt/Cargo.toml @@ -30,7 +30,6 @@ alloy-rpc-types = { workspace = true, features = ["eth", "debug"] } # General rand.workspace = true -anyhow.workspace = true reqwest.workspace = true proptest.workspace = true tokio = { workspace = true, features = ["full"] } diff --git a/crates/mpt/src/test_util.rs b/crates/mpt/src/test_util.rs index f5ca94ace..1e13ad757 100644 --- a/crates/mpt/src/test_util.rs +++ b/crates/mpt/src/test_util.rs @@ -7,14 +7,17 @@ use alloy_primitives::{keccak256, Bytes, Log, B256}; use alloy_provider::{network::eip2718::Encodable2718, Provider, ProviderBuilder}; use alloy_rlp::Decodable; use alloy_rpc_types::{BlockTransactions, BlockTransactionsKind}; -use anyhow::{anyhow, Result}; use reqwest::Url; const RPC_URL: &str = "https://docs-demo.quiknode.pro/"; +#[derive(thiserror::Error, Debug, Eq, PartialEq)] +#[error("TestTrieProviderError: {0}")] +pub(crate) struct TestTrieProviderError(&'static str); + /// Grabs a live merkleized receipts list within a block header. pub(crate) async fn get_live_derivable_receipts_list( -) -> Result<(B256, BTreeMap, Vec)> { +) -> Result<(B256, BTreeMap, Vec), TestTrieProviderError> { // Initialize the provider. let provider = ProviderBuilder::new().on_http(Url::parse(RPC_URL).expect("invalid rpc url")); @@ -22,13 +25,13 @@ pub(crate) async fn get_live_derivable_receipts_list( let block = provider .get_block(block_number.into(), BlockTransactionsKind::Full) .await - .map_err(anyhow::Error::from)? - .ok_or_else(|| anyhow!("Missing block"))?; + .map_err(|_| TestTrieProviderError("Missing block"))? + .ok_or(TestTrieProviderError("Missing block"))?; let receipts = provider .get_block_receipts(block_number.into()) .await - .map_err(anyhow::Error::from)? - .ok_or_else(|| anyhow!("Missing receipts"))?; + .map_err(|_| TestTrieProviderError("Missing receipts"))? + .ok_or(TestTrieProviderError("Missing receipts"))?; let consensus_receipts = receipts .into_iter() @@ -82,7 +85,7 @@ pub(crate) async fn get_live_derivable_receipts_list( /// Grabs a live merkleized transactions list within a block header. pub(crate) async fn get_live_derivable_transactions_list( -) -> Result<(B256, BTreeMap, Vec)> { +) -> Result<(B256, BTreeMap, Vec), TestTrieProviderError> { // Initialize the provider. let provider = ProviderBuilder::new().on_http(Url::parse(RPC_URL).expect("invalid rpc url")); @@ -90,11 +93,11 @@ pub(crate) async fn get_live_derivable_transactions_list( let block = provider .get_block(block_number.into(), BlockTransactionsKind::Full) .await - .map_err(anyhow::Error::from)? - .ok_or_else(|| anyhow!("Missing block"))?; + .map_err(|_| TestTrieProviderError("Missing block"))? + .ok_or(TestTrieProviderError("Missing block"))?; let BlockTransactions::Full(txs) = block.transactions else { - anyhow::bail!("Did not fetch full block"); + return Err(TestTrieProviderError("Did not fetch full block")); }; let consensus_txs = txs.into_iter().map(TxEnvelope::from).collect::>(); @@ -131,17 +134,17 @@ impl TrieNodeProvider { } impl TrieProvider for TrieNodeProvider { - type Error = anyhow::Error; + type Error = TestTrieProviderError; - 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!("Key not found"))? + .ok_or(TestTrieProviderError("key not found in trie"))? .as_ref(), ) - .map_err(Into::into) + .map_err(|_| TestTrieProviderError("failed to decode trie node")) } } diff --git a/crates/mpt/src/traits.rs b/crates/mpt/src/traits.rs index 0b8b539e7..75736c36b 100644 --- a/crates/mpt/src/traits.rs +++ b/crates/mpt/src/traits.rs @@ -18,7 +18,7 @@ pub trait TrieProvider { /// /// ## Returns /// - Ok(TrieNode): The trie node preimage. - /// - Err(anyhow::Error): If the trie node preimage could not be fetched. + /// - Err(Self::Error): If the trie node preimage could not be fetched. fn trie_node_by_hash(&self, key: B256) -> Result; } @@ -45,7 +45,7 @@ pub trait TrieHinter { /// /// ## Returns /// - Ok(()): If the hint was successful. - /// - Err(anyhow::Error): If the hint was unsuccessful. + /// - Err(Self::Error): If the hint was unsuccessful. fn hint_account_proof(&self, address: Address, block_number: u64) -> Result<(), Self::Error>; /// Hints the host to fetch the trie node preimages on the path to the storage slot within the @@ -58,7 +58,7 @@ pub trait TrieHinter { /// /// ## Returns /// - Ok(()): If the hint was successful. - /// - Err(anyhow::Error): If the hint was unsuccessful. + /// - Err(Self::Error): If the hint was unsuccessful. fn hint_storage_proof( &self, address: Address, diff --git a/crates/proof-sdk/std-fpvm-proc/Cargo.toml b/crates/proof-sdk/std-fpvm-proc/Cargo.toml index c0421752b..ffb5cdead 100644 --- a/crates/proof-sdk/std-fpvm-proc/Cargo.toml +++ b/crates/proof-sdk/std-fpvm-proc/Cargo.toml @@ -13,7 +13,6 @@ proc-macro = true [dependencies] # General -anyhow.workspace = true cfg-if.workspace = true # Workspace