chore: move triewriter trait (#12598)

This commit is contained in:
Matthias Seitz
2024-11-16 11:32:56 +01:00
committed by GitHub
parent 1945cd8b42
commit d52c7194d1
3 changed files with 32 additions and 41 deletions

View File

@ -17,9 +17,6 @@ pub use state::{StateChangeWriter, StateWriter};
pub use reth_chainspec::ChainSpecProvider;
mod trie;
pub use trie::{StorageTrieWriter, TrieWriter};
mod static_file_provider;
pub use static_file_provider::StaticFileProviderFactory;

View File

@ -1,36 +0,0 @@
use std::collections::HashMap;
use alloy_primitives::B256;
use auto_impl::auto_impl;
use reth_storage_errors::provider::ProviderResult;
use reth_trie::updates::{StorageTrieUpdates, TrieUpdates};
/// Trie Writer
#[auto_impl(&, Arc, Box)]
pub trait TrieWriter: Send + Sync {
/// Writes trie updates to the database.
///
/// Returns the number of entries modified.
fn write_trie_updates(&self, trie_updates: &TrieUpdates) -> ProviderResult<usize>;
}
/// Storage Trie Writer
#[auto_impl(&, Arc, Box)]
pub trait StorageTrieWriter: Send + Sync {
/// Writes storage trie updates from the given storage trie map.
///
/// First sorts the storage trie updates by the hashed address key, writing in sorted order.
///
/// Returns the number of entries modified.
fn write_storage_trie_updates(
&self,
storage_tries: &HashMap<B256, StorageTrieUpdates>,
) -> ProviderResult<usize>;
/// Writes storage trie updates for the given hashed address.
fn write_individual_storage_trie_updates(
&self,
hashed_address: B256,
updates: &StorageTrieUpdates,
) -> ProviderResult<usize>;
}

View File

@ -4,8 +4,8 @@ use alloy_primitives::{
};
use reth_storage_errors::provider::ProviderResult;
use reth_trie::{
updates::TrieUpdates, AccountProof, HashedPostState, HashedStorage, MultiProof, StorageProof,
TrieInput,
updates::{StorageTrieUpdates, TrieUpdates},
AccountProof, HashedPostState, HashedStorage, MultiProof, StorageProof, TrieInput,
};
/// A type that can compute the state root of a given post state.
@ -85,3 +85,33 @@ pub trait StateProofProvider: Send + Sync {
target: HashedPostState,
) -> ProviderResult<HashMap<B256, Bytes>>;
}
/// Trie Writer
#[auto_impl::auto_impl(&, Arc, Box)]
pub trait TrieWriter: Send + Sync {
/// Writes trie updates to the database.
///
/// Returns the number of entries modified.
fn write_trie_updates(&self, trie_updates: &TrieUpdates) -> ProviderResult<usize>;
}
/// Storage Trie Writer
#[auto_impl::auto_impl(&, Arc, Box)]
pub trait StorageTrieWriter: Send + Sync {
/// Writes storage trie updates from the given storage trie map.
///
/// First sorts the storage trie updates by the hashed address key, writing in sorted order.
///
/// Returns the number of entries modified.
fn write_storage_trie_updates(
&self,
storage_tries: &std::collections::HashMap<B256, StorageTrieUpdates>,
) -> ProviderResult<usize>;
/// Writes storage trie updates for the given hashed address.
fn write_individual_storage_trie_updates(
&self,
hashed_address: B256,
updates: &StorageTrieUpdates,
) -> ProviderResult<usize>;
}