Skip to content

Commit

Permalink
chore(mpt): mpt noop trait impls (#649)
Browse files Browse the repository at this point in the history
* chore(mpt): mpt noop trait impls

* chore(mpt): mpt noop trait impls
  • Loading branch information
refcell authored Oct 8, 2024
1 parent 5dd6f3c commit d13f55e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 1 addition & 46 deletions crates/mpt/src/fetcher.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Bytes, Self::Error> {
Ok(Bytes::new())
}

fn bytecode_by_hash(&self, _code_hash: B256) -> Result<Bytes, Self::Error> {
Ok(Bytes::new())
}

fn header_by_hash(&self, _hash: B256) -> Result<Header, Self::Error> {
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(())
}
}
5 changes: 4 additions & 1 deletion crates/mpt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ pub use errors::{
};

mod fetcher;
pub use fetcher::{NoopTrieHinter, NoopTrieProvider, TrieHinter, TrieProvider};
pub use fetcher::{TrieHinter, TrieProvider};

mod node;
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;

Expand Down
4 changes: 2 additions & 2 deletions crates/mpt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
52 changes: 52 additions & 0 deletions crates/mpt/src/noop.rs
Original file line number Diff line number Diff line change
@@ -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<Bytes, Self::Error> {
Ok(Bytes::new())
}

fn bytecode_by_hash(&self, _code_hash: B256) -> Result<Bytes, Self::Error> {
Ok(Bytes::new())
}

fn header_by_hash(&self, _hash: B256) -> Result<Header, Self::Error> {
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(())
}
}

0 comments on commit d13f55e

Please sign in to comment.