mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor(storage): unify blocks insertion logic (#12694)
This commit is contained in:
@ -27,7 +27,7 @@ use reth_engine_tree::{
|
||||
EngineApiKind, EngineApiRequest, EngineApiRequestHandler, EngineRequestHandler, FromEngine,
|
||||
RequestHandlerEvent,
|
||||
},
|
||||
persistence::PersistenceHandle,
|
||||
persistence::{PersistenceHandle, PersistenceNodeTypes},
|
||||
tree::{EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
|
||||
};
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
@ -59,7 +59,7 @@ where
|
||||
|
||||
impl<N> LocalEngineService<N>
|
||||
where
|
||||
N: EngineNodeTypes,
|
||||
N: EngineNodeTypes + PersistenceNodeTypes,
|
||||
{
|
||||
/// Constructor for [`LocalEngineService`].
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
@ -8,7 +8,7 @@ use reth_engine_tree::{
|
||||
backfill::PipelineSync,
|
||||
download::BasicBlockDownloader,
|
||||
engine::{EngineApiKind, EngineApiRequest, EngineApiRequestHandler, EngineHandler},
|
||||
persistence::PersistenceHandle,
|
||||
persistence::{PersistenceHandle, PersistenceNodeTypes},
|
||||
tree::{EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
|
||||
};
|
||||
pub use reth_engine_tree::{
|
||||
@ -59,7 +59,7 @@ where
|
||||
|
||||
impl<N, Client, E> EngineService<N, Client, E>
|
||||
where
|
||||
N: EngineNodeTypes,
|
||||
N: EngineNodeTypes + PersistenceNodeTypes,
|
||||
Client: EthBlockClient + 'static,
|
||||
E: BlockExecutorProvider + 'static,
|
||||
{
|
||||
|
||||
@ -27,6 +27,7 @@ reth-payload-builder-primitives.workspace = true
|
||||
reth-payload-primitives.workspace = true
|
||||
reth-payload-validator.workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-prune.workspace = true
|
||||
reth-revm.workspace = true
|
||||
@ -107,4 +108,5 @@ test-utils = [
|
||||
"reth-provider/test-utils",
|
||||
"reth-trie/test-utils",
|
||||
"reth-prune-types?/test-utils",
|
||||
"reth-primitives-traits/test-utils",
|
||||
]
|
||||
|
||||
@ -2,6 +2,8 @@ use crate::metrics::PersistenceMetrics;
|
||||
use alloy_eips::BlockNumHash;
|
||||
use reth_chain_state::ExecutedBlock;
|
||||
use reth_errors::ProviderError;
|
||||
use reth_primitives::BlockBody;
|
||||
use reth_primitives_traits::{Block, FullNodePrimitives};
|
||||
use reth_provider::{
|
||||
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, BlockHashReader,
|
||||
ChainStateBlockWriter, DatabaseProviderFactory, ProviderFactory, StaticFileProviderFactory,
|
||||
@ -16,6 +18,16 @@ use thiserror::Error;
|
||||
use tokio::sync::oneshot;
|
||||
use tracing::{debug, error};
|
||||
|
||||
/// A helper trait with requirements for [`ProviderNodeTypes`] to be used within
|
||||
/// [`PersistenceService`].
|
||||
pub trait PersistenceNodeTypes:
|
||||
ProviderNodeTypes<Primitives: FullNodePrimitives<Block: Block<Body = BlockBody>>>
|
||||
{
|
||||
}
|
||||
impl<T> PersistenceNodeTypes for T where
|
||||
T: ProviderNodeTypes<Primitives: FullNodePrimitives<Block: Block<Body = BlockBody>>>
|
||||
{
|
||||
}
|
||||
/// Writes parts of reth's in memory tree state to the database and static files.
|
||||
///
|
||||
/// This is meant to be a spawned service that listens for various incoming persistence operations,
|
||||
@ -60,7 +72,7 @@ impl<N: ProviderNodeTypes> PersistenceService<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: ProviderNodeTypes> PersistenceService<N> {
|
||||
impl<N: PersistenceNodeTypes> PersistenceService<N> {
|
||||
/// This is the main loop, that will listen to database events and perform the requested
|
||||
/// database actions
|
||||
pub fn run(mut self) -> Result<(), PersistenceError> {
|
||||
@ -198,7 +210,7 @@ impl PersistenceHandle {
|
||||
}
|
||||
|
||||
/// Create a new [`PersistenceHandle`], and spawn the persistence service.
|
||||
pub fn spawn_service<N: ProviderNodeTypes>(
|
||||
pub fn spawn_service<N: PersistenceNodeTypes>(
|
||||
provider_factory: ProviderFactory<N>,
|
||||
pruner: PrunerWithFactory<ProviderFactory<N>>,
|
||||
sync_metrics_tx: MetricEventsSender,
|
||||
|
||||
Reference in New Issue
Block a user