Skip to content

Commit

Permalink
chore(mpt): Remove anyhow dev-dependency (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Jan 22, 2025
1 parent 80b9c44 commit bf87631
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/executor/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/executor/src/db/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytes, Self::Error>;
Expand All @@ -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<Header, Self::Error>;
Expand Down
1 change: 0 additions & 1 deletion crates/mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
31 changes: 17 additions & 14 deletions crates/mpt/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@ 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<B256, Bytes>, Vec<ReceiptEnvelope>)> {
) -> Result<(B256, BTreeMap<B256, Bytes>, Vec<ReceiptEnvelope>), TestTrieProviderError> {
// Initialize the provider.
let provider = ProviderBuilder::new().on_http(Url::parse(RPC_URL).expect("invalid rpc url"));

let block_number = 19005266;
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()
Expand Down Expand Up @@ -82,19 +85,19 @@ 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<B256, Bytes>, Vec<TxEnvelope>)> {
) -> Result<(B256, BTreeMap<B256, Bytes>, Vec<TxEnvelope>), TestTrieProviderError> {
// Initialize the provider.
let provider = ProviderBuilder::new().on_http(Url::parse(RPC_URL).expect("invalid rpc url"));

let block_number = 19005266;
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::<Vec<_>>();

Expand Down Expand Up @@ -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<TrieNode> {
fn trie_node_by_hash(&self, key: B256) -> Result<TrieNode, TestTrieProviderError> {
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"))
}
}
6 changes: 3 additions & 3 deletions crates/mpt/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrieNode, Self::Error>;
}

Expand All @@ -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
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/proof-sdk/std-fpvm-proc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ proc-macro = true

[dependencies]
# General
anyhow.workspace = true
cfg-if.workspace = true

# Workspace
Expand Down

0 comments on commit bf87631

Please sign in to comment.