Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(executor): Remove anyhow dev-dependency #937

Merged
merged 1 commit into from
Jan 22, 2025
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
1 change: 0 additions & 1 deletion 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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions crates/executor/benches/execution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![allow(missing_docs)]
//! Benches for the [StatelessL2BlockExecutor] implementation.

#![allow(missing_docs)]

clabby marked this conversation as resolved.
Show resolved Hide resolved
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};
Expand All @@ -22,6 +22,14 @@ struct TestdataTrieProvider {
preimages: HashMap<B256, Bytes>,
}

#[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 {
Expand All @@ -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<TrieNode> {
fn trie_node_by_hash(&self, key: B256) -> Result<TrieNode, Self::Error> {
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<Bytes> {
fn bytecode_by_hash(&self, code_hash: B256) -> Result<Bytes, TestdataTrieProviderError> {
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<Header> {
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<Header, TestdataTrieProviderError> {
let encoded_header =
self.preimages.get(&hash).ok_or(TestdataTrieProviderError::PreimageNotFound(hash))?;
Header::decode(&mut encoded_header.as_ref()).map_err(TestdataTrieProviderError::Rlp)
}
}

Expand Down
Loading