diff --git a/.github/codecov.yml b/.github/codecov.yml index b0871426..0e9d103c 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -25,6 +25,7 @@ ignore: - "bin/" - "crates/providers-alloy/src/alloy_providers.rs" # Flaky testing with online providers - "crates/providers-alloy/src/beacon_client.rs" # Flaky testing with online providers + - "crates/mpt/src/noop.rs" # Uncovered noop implementations used downstream and by tests # Make comments less noisy comment: diff --git a/crates/mpt/src/fetcher.rs b/crates/mpt/src/fetcher.rs index 280ac878..16e7f506 100644 --- a/crates/mpt/src/fetcher.rs +++ b/crates/mpt/src/fetcher.rs @@ -1,7 +1,7 @@ //! Contains the [TrieProvider] trait for fetching trie node preimages, contract bytecode, and //! headers. -use alloc::string::{String, ToString}; +use alloc::string::ToString; use alloy_consensus::Header; use alloy_primitives::{Address, Bytes, B256, U256}; use core::fmt::Display; @@ -93,48 +93,3 @@ pub trait TrieHinter { block_number: u64, ) -> Result<(), Self::Error>; } - -/// The default, no-op implementation of the [TrieProvider] trait, used for testing. -#[derive(Debug, Clone, Copy)] -pub struct NoopTrieProvider; - -impl TrieProvider for NoopTrieProvider { - type Error = String; - - fn trie_node_preimage(&self, _key: B256) -> Result { - Ok(Bytes::new()) - } - - fn bytecode_by_hash(&self, _code_hash: B256) -> Result { - Ok(Bytes::new()) - } - - fn header_by_hash(&self, _hash: B256) -> Result { - Ok(Header::default()) - } -} - -/// The default, no-op implementation of the [TrieHinter] trait, used for testing. -#[derive(Debug, Clone, Copy)] -pub struct NoopTrieHinter; - -impl TrieHinter for NoopTrieHinter { - type Error = String; - - fn hint_trie_node(&self, _hash: B256) -> Result<(), Self::Error> { - Ok(()) - } - - fn hint_account_proof(&self, _address: Address, _block_number: u64) -> Result<(), Self::Error> { - Ok(()) - } - - fn hint_storage_proof( - &self, - _address: Address, - _slot: U256, - _block_number: u64, - ) -> Result<(), Self::Error> { - Ok(()) - } -} diff --git a/crates/mpt/src/lib.rs b/crates/mpt/src/lib.rs index 8db704da..8a98d413 100644 --- a/crates/mpt/src/lib.rs +++ b/crates/mpt/src/lib.rs @@ -19,7 +19,7 @@ pub use errors::{ }; mod fetcher; -pub use fetcher::{NoopTrieHinter, NoopTrieProvider, TrieHinter, TrieProvider}; +pub use fetcher::{TrieHinter, TrieProvider}; mod node; pub use node::TrieNode; @@ -27,6 +27,9 @@ pub use node::TrieNode; mod list_walker; pub use list_walker::OrderedListWalker; +mod noop; +pub use noop::{NoopTrieHinter, NoopTrieProvider}; + mod util; pub use util::ordered_trie_with_encoder; diff --git a/crates/mpt/src/node.rs b/crates/mpt/src/node.rs index d7976896..4bf48710 100644 --- a/crates/mpt/src/node.rs +++ b/crates/mpt/src/node.rs @@ -684,8 +684,8 @@ impl Decodable for TrieNode { mod test { use super::*; use crate::{ - fetcher::NoopTrieProvider, ordered_trie_with_encoder, test_util::TrieNodeProvider, - NoopTrieHinter, TrieNode, + ordered_trie_with_encoder, test_util::TrieNodeProvider, NoopTrieHinter, NoopTrieProvider, + TrieNode, }; use alloc::{collections::BTreeMap, vec, vec::Vec}; use alloy_primitives::{b256, bytes, hex, keccak256}; diff --git a/crates/mpt/src/noop.rs b/crates/mpt/src/noop.rs new file mode 100644 index 00000000..3bd08cad --- /dev/null +++ b/crates/mpt/src/noop.rs @@ -0,0 +1,52 @@ +//! Trait implementations for `kona-mpt` traits that are effectively a no-op. +//! Providers trait implementations for downstream users who do not require hinting. + +use crate::{TrieHinter, TrieProvider}; +use alloc::string::String; +use alloy_consensus::Header; +use alloy_primitives::{Address, Bytes, B256, U256}; + +/// The default, no-op implementation of the [TrieProvider] trait, used for testing. +#[derive(Debug, Clone, Copy)] +pub struct NoopTrieProvider; + +impl TrieProvider for NoopTrieProvider { + type Error = String; + + fn trie_node_preimage(&self, _key: B256) -> Result { + Ok(Bytes::new()) + } + + fn bytecode_by_hash(&self, _code_hash: B256) -> Result { + Ok(Bytes::new()) + } + + fn header_by_hash(&self, _hash: B256) -> Result { + Ok(Header::default()) + } +} + +/// The default, no-op implementation of the [TrieHinter] trait, used for testing. +#[derive(Debug, Clone, Copy)] +pub struct NoopTrieHinter; + +impl TrieHinter for NoopTrieHinter { + type Error = String; + + fn hint_trie_node(&self, _hash: B256) -> Result<(), Self::Error> { + Ok(()) + } + + fn hint_account_proof(&self, _address: Address, _block_number: u64) -> Result<(), Self::Error> { + Ok(()) + } + + fn hint_storage_proof( + &self, + _address: Address, + _slot: U256, + _block_number: u64, + ) -> Result<(), Self::Error> { + Ok(()) + } +}