refactor: reduce ProviderFactory usage (#10798)

This commit is contained in:
Arsenii Kulikov
2024-09-11 11:36:34 +04:00
committed by GitHub
parent f6b2021440
commit d11bbe686b
29 changed files with 190 additions and 129 deletions

View File

@ -620,7 +620,7 @@ where
/// If the database is empty, returns the genesis block.
pub fn lookup_head(&self) -> eyre::Result<Head> {
self.node_config()
.lookup_head(self.provider_factory().clone())
.lookup_head(self.provider_factory())
.wrap_err("the head block is missing")
}
@ -744,7 +744,7 @@ where
}
/// Creates a new [`StaticFileProducer`] with the attached database.
pub fn static_file_producer(&self) -> StaticFileProducer<T::Types> {
pub fn static_file_producer(&self) -> StaticFileProducer<ProviderFactory<T::Types>> {
StaticFileProducer::new(self.provider_factory().clone(), self.prune_modes())
}

View File

@ -32,7 +32,7 @@ pub fn build_networked_pipeline<N, Client, Executor>(
metrics_tx: reth_stages::MetricEventsSender,
prune_config: Option<PruneConfig>,
max_block: Option<BlockNumber>,
static_file_producer: StaticFileProducer<N>,
static_file_producer: StaticFileProducer<ProviderFactory<N>>,
executor: Executor,
exex_manager_handle: ExExManagerHandle,
) -> eyre::Result<Pipeline<N>>
@ -78,7 +78,7 @@ pub fn build_pipeline<N, H, B, Executor>(
max_block: Option<u64>,
metrics_tx: reth_stages::MetricEventsSender,
prune_config: Option<PruneConfig>,
static_file_producer: StaticFileProducer<N>,
static_file_producer: StaticFileProducer<ProviderFactory<N>>,
executor: Executor,
exex_manager_handle: ExExManagerHandle,
) -> eyre::Result<Pipeline<N>>

View File

@ -19,7 +19,7 @@ reth-cli-util.workspace = true
reth-fs-util.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-storage-errors.workspace = true
reth-provider.workspace = true
reth-storage-api.workspace = true
reth-network = { workspace = true, features = ["serde"] }
reth-network-p2p.workspace = true
reth-rpc-eth-types.workspace = true
@ -39,7 +39,6 @@ reth-consensus-common.workspace = true
reth-prune-types.workspace = true
reth-stages-types.workspace = true
reth-optimism-chainspec = { workspace = true, optional = true }
reth-node-types.workspace = true
# ethereum
alloy-genesis.workspace = true
@ -85,7 +84,6 @@ tempfile.workspace = true
[features]
optimism = [
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-rpc-types-compat/optimism",
"reth-rpc-eth-api/optimism",
"dep:reth-optimism-chainspec",

View File

@ -16,10 +16,11 @@ use serde::{de::DeserializeOwned, Serialize};
use std::{fs, path::Path};
use alloy_primitives::{BlockNumber, B256};
use reth_node_types::NodeTypesWithDB;
use reth_primitives::{BlockHashOrNumber, Head, SealedHeader};
use reth_provider::{BlockHashReader, HeaderProvider, ProviderFactory, StageCheckpointReader};
use reth_stages_types::StageId;
use reth_storage_api::{
BlockHashReader, DatabaseProviderFactory, HeaderProvider, StageCheckpointReader,
};
use reth_storage_errors::provider::ProviderResult;
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
use tracing::*;
@ -263,11 +264,13 @@ impl NodeConfig {
/// Fetches the head block from the database.
///
/// If the database is empty, returns the genesis block.
pub fn lookup_head<N: NodeTypesWithDB<ChainSpec = ChainSpec>>(
&self,
factory: ProviderFactory<N>,
) -> ProviderResult<Head> {
let provider = factory.provider()?;
pub fn lookup_head<Factory>(&self, factory: &Factory) -> ProviderResult<Head>
where
Factory: DatabaseProviderFactory<
Provider: HeaderProvider + StageCheckpointReader + BlockHashReader,
>,
{
let provider = factory.database_provider_ro()?;
let head = provider.get_stage_checkpoint(StageId::Finish)?.unwrap_or_default().block_number;