mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove StaticFileProvider field from StaticFileProducer (#8583)
This commit is contained in:
@ -31,7 +31,7 @@ use reth_primitives::{
|
|||||||
};
|
};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::StaticFileProvider, BlockExecutionWriter, HeaderSyncMode, ProviderFactory,
|
providers::StaticFileProvider, BlockExecutionWriter, HeaderSyncMode, ProviderFactory,
|
||||||
StageCheckpointReader, StaticFileProviderFactory,
|
StageCheckpointReader,
|
||||||
};
|
};
|
||||||
use reth_stages::{
|
use reth_stages::{
|
||||||
sets::DefaultStages,
|
sets::DefaultStages,
|
||||||
@ -223,11 +223,8 @@ impl Command {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let static_file_producer = StaticFileProducer::new(
|
let static_file_producer =
|
||||||
provider_factory.clone(),
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Configure the pipeline
|
// Configure the pipeline
|
||||||
let fetch_client = network.fetch_client().await?;
|
let fetch_client = network.fetch_client().await?;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
|||||||
use reth_primitives::{ChainSpec, PruneModes};
|
use reth_primitives::{ChainSpec, PruneModes};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::{BlockchainProvider, StaticFileProvider},
|
providers::{BlockchainProvider, StaticFileProvider},
|
||||||
CanonStateSubscriptions, ProviderFactory, StaticFileProviderFactory,
|
CanonStateSubscriptions, ProviderFactory,
|
||||||
};
|
};
|
||||||
use reth_stages::Pipeline;
|
use reth_stages::Pipeline;
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
@ -181,11 +181,7 @@ impl Command {
|
|||||||
network_client,
|
network_client,
|
||||||
Pipeline::builder().build(
|
Pipeline::builder().build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
blockchain_db.clone(),
|
blockchain_db.clone(),
|
||||||
Box::new(ctx.task_executor.clone()),
|
Box::new(ctx.task_executor.clone()),
|
||||||
|
|||||||
@ -30,7 +30,6 @@ use reth_primitives::{stage::StageId, ChainSpec, PruneModes, B256};
|
|||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::StaticFileProvider, BlockNumReader, ChainSpecProvider, HeaderProvider,
|
providers::StaticFileProvider, BlockNumReader, ChainSpecProvider, HeaderProvider,
|
||||||
HeaderSyncMode, ProviderError, ProviderFactory, StageCheckpointReader,
|
HeaderSyncMode, ProviderError, ProviderFactory, StageCheckpointReader,
|
||||||
StaticFileProviderFactory,
|
|
||||||
};
|
};
|
||||||
use reth_stages::{prelude::*, Pipeline, StageSet};
|
use reth_stages::{prelude::*, Pipeline, StageSet};
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
@ -146,11 +145,7 @@ impl ImportCommand {
|
|||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
&consensus,
|
&consensus,
|
||||||
Arc::new(file_client),
|
Arc::new(file_client),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
self.no_state,
|
self.no_state,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@ -20,10 +20,7 @@ use reth_downloaders::file_client::{
|
|||||||
use reth_node_core::args::DatadirArgs;
|
use reth_node_core::args::DatadirArgs;
|
||||||
use reth_optimism_primitives::bedrock_import::is_dup_tx;
|
use reth_optimism_primitives::bedrock_import::is_dup_tx;
|
||||||
use reth_primitives::{stage::StageId, PruneModes};
|
use reth_primitives::{stage::StageId, PruneModes};
|
||||||
use reth_provider::{
|
use reth_provider::{providers::StaticFileProvider, ProviderFactory, StageCheckpointReader};
|
||||||
providers::StaticFileProvider, ProviderFactory, StageCheckpointReader,
|
|
||||||
StaticFileProviderFactory,
|
|
||||||
};
|
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
@ -134,11 +131,7 @@ impl ImportOpCommand {
|
|||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
&consensus,
|
&consensus,
|
||||||
Arc::new(file_client),
|
Arc::new(file_client),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@ -158,11 +158,7 @@ impl Command {
|
|||||||
)
|
)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory, PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
Ok(pipeline)
|
Ok(pipeline)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -436,7 +436,6 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
test_utils::create_test_provider_factory_with_chain_spec, BundleStateWithReceipts,
|
test_utils::create_test_provider_factory_with_chain_spec, BundleStateWithReceipts,
|
||||||
StaticFileProviderFactory,
|
|
||||||
};
|
};
|
||||||
use reth_stages::{test_utils::TestStages, ExecOutput, StageError};
|
use reth_stages::{test_utils::TestStages, ExecOutput, StageError};
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
@ -499,11 +498,8 @@ mod tests {
|
|||||||
|
|
||||||
let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
|
let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
|
||||||
|
|
||||||
let static_file_producer = StaticFileProducer::new(
|
let static_file_producer =
|
||||||
provider_factory.clone(),
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
pipeline.build(provider_factory, static_file_producer)
|
pipeline.build(provider_factory, static_file_producer)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ use reth_payload_builder::test_utils::spawn_test_payload_service;
|
|||||||
use reth_primitives::{BlockNumber, ChainSpec, FinishedExExHeight, PruneModes, B256};
|
use reth_primitives::{BlockNumber, ChainSpec, FinishedExExHeight, PruneModes, B256};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec,
|
providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec,
|
||||||
BundleStateWithReceipts, HeaderSyncMode, StaticFileProviderFactory,
|
BundleStateWithReceipts, HeaderSyncMode,
|
||||||
};
|
};
|
||||||
use reth_prune::Pruner;
|
use reth_prune::Pruner;
|
||||||
use reth_rpc_types::engine::{
|
use reth_rpc_types::engine::{
|
||||||
@ -349,11 +349,8 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let static_file_producer = StaticFileProducer::new(
|
let static_file_producer =
|
||||||
provider_factory.clone(),
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Setup pipeline
|
// Setup pipeline
|
||||||
let (tip_tx, tip_rx) = watch::channel(B256::default());
|
let (tip_tx, tip_rx) = watch::channel(B256::default());
|
||||||
|
|||||||
@ -373,7 +373,6 @@ where
|
|||||||
factory.clone(),
|
factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(
|
||||||
factory.clone(),
|
factory.clone(),
|
||||||
factory.static_file_provider(),
|
|
||||||
self.prune_modes().unwrap_or_default(),
|
self.prune_modes().unwrap_or_default(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -432,7 +431,6 @@ where
|
|||||||
pub fn static_file_producer(&self) -> StaticFileProducer<DB> {
|
pub fn static_file_producer(&self) -> StaticFileProducer<DB> {
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(
|
||||||
self.provider_factory().clone(),
|
self.provider_factory().clone(),
|
||||||
self.static_file_provider(),
|
|
||||||
self.prune_modes().unwrap_or_default(),
|
self.prune_modes().unwrap_or_default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -647,11 +647,7 @@ mod tests {
|
|||||||
.with_max_block(10)
|
.with_max_block(10)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let events = pipeline.events();
|
let events = pipeline.events();
|
||||||
|
|
||||||
@ -726,11 +722,7 @@ mod tests {
|
|||||||
.with_max_block(10)
|
.with_max_block(10)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let events = pipeline.events();
|
let events = pipeline.events();
|
||||||
|
|
||||||
@ -858,11 +850,7 @@ mod tests {
|
|||||||
.with_max_block(10)
|
.with_max_block(10)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let events = pipeline.events();
|
let events = pipeline.events();
|
||||||
|
|
||||||
@ -972,11 +960,7 @@ mod tests {
|
|||||||
.with_max_block(10)
|
.with_max_block(10)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let events = pipeline.events();
|
let events = pipeline.events();
|
||||||
|
|
||||||
@ -1083,11 +1067,7 @@ mod tests {
|
|||||||
.with_max_block(10)
|
.with_max_block(10)
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let result = pipeline.run().await;
|
let result = pipeline.run().await;
|
||||||
assert_matches!(result, Ok(()));
|
assert_matches!(result, Ok(()));
|
||||||
@ -1100,11 +1080,7 @@ mod tests {
|
|||||||
)))
|
)))
|
||||||
.build(
|
.build(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
StaticFileProducer::new(
|
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
|
||||||
provider_factory.clone(),
|
|
||||||
provider_factory.static_file_provider(),
|
|
||||||
PruneModes::default(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let result = pipeline.run().await;
|
let result = pipeline.run().await;
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
|
|||||||
@ -48,7 +48,6 @@
|
|||||||
//! # let executor_provider = EthExecutorProvider::mainnet();
|
//! # let executor_provider = EthExecutorProvider::mainnet();
|
||||||
//! # let static_file_producer = StaticFileProducer::new(
|
//! # let static_file_producer = StaticFileProducer::new(
|
||||||
//! # provider_factory.clone(),
|
//! # provider_factory.clone(),
|
||||||
//! # provider_factory.static_file_provider(),
|
|
||||||
//! # PruneModes::default()
|
//! # PruneModes::default()
|
||||||
//! # );
|
//! # );
|
||||||
//! // Create a pipeline that can fully sync
|
//! // Create a pipeline that can fully sync
|
||||||
|
|||||||
@ -23,11 +23,8 @@
|
|||||||
//! # fn create(exec: impl BlockExecutorProvider) {
|
//! # fn create(exec: impl BlockExecutorProvider) {
|
||||||
//!
|
//!
|
||||||
//! let provider_factory = create_test_provider_factory();
|
//! let provider_factory = create_test_provider_factory();
|
||||||
//! let static_file_producer = StaticFileProducer::new(
|
//! let static_file_producer =
|
||||||
//! provider_factory.clone(),
|
//! StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
|
||||||
//! provider_factory.static_file_provider(),
|
|
||||||
//! PruneModes::default(),
|
|
||||||
//! );
|
|
||||||
//! // Build a pipeline with all offline stages.
|
//! // Build a pipeline with all offline stages.
|
||||||
//! let pipeline = Pipeline::builder()
|
//! let pipeline = Pipeline::builder()
|
||||||
//! .add_stages(OfflineStages::new(exec, StageConfig::default(), PruneModes::default()))
|
//! .add_stages(OfflineStages::new(exec, StageConfig::default(), PruneModes::default()))
|
||||||
|
|||||||
@ -5,10 +5,7 @@ use parking_lot::Mutex;
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use reth_db::database::Database;
|
use reth_db::database::Database;
|
||||||
use reth_primitives::{static_file::HighestStaticFiles, BlockNumber, PruneModes};
|
use reth_primitives::{static_file::HighestStaticFiles, BlockNumber, PruneModes};
|
||||||
use reth_provider::{
|
use reth_provider::{providers::StaticFileWriter, ProviderFactory, StaticFileProviderFactory};
|
||||||
providers::{StaticFileProvider, StaticFileWriter},
|
|
||||||
ProviderFactory,
|
|
||||||
};
|
|
||||||
use reth_storage_errors::provider::ProviderResult;
|
use reth_storage_errors::provider::ProviderResult;
|
||||||
use reth_tokio_util::{EventSender, EventStream};
|
use reth_tokio_util::{EventSender, EventStream};
|
||||||
use std::{
|
use std::{
|
||||||
@ -31,16 +28,8 @@ pub struct StaticFileProducer<DB>(Arc<Mutex<StaticFileProducerInner<DB>>>);
|
|||||||
|
|
||||||
impl<DB: Database> StaticFileProducer<DB> {
|
impl<DB: Database> StaticFileProducer<DB> {
|
||||||
/// Creates a new [`StaticFileProducer`].
|
/// Creates a new [`StaticFileProducer`].
|
||||||
pub fn new(
|
pub fn new(provider_factory: ProviderFactory<DB>, prune_modes: PruneModes) -> Self {
|
||||||
provider_factory: ProviderFactory<DB>,
|
Self(Arc::new(Mutex::new(StaticFileProducerInner::new(provider_factory, prune_modes))))
|
||||||
static_file_provider: StaticFileProvider,
|
|
||||||
prune_modes: PruneModes,
|
|
||||||
) -> Self {
|
|
||||||
Self(Arc::new(Mutex::new(StaticFileProducerInner::new(
|
|
||||||
provider_factory,
|
|
||||||
static_file_provider,
|
|
||||||
prune_modes,
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +47,6 @@ impl<DB> Deref for StaticFileProducer<DB> {
|
|||||||
pub struct StaticFileProducerInner<DB> {
|
pub struct StaticFileProducerInner<DB> {
|
||||||
/// Provider factory
|
/// Provider factory
|
||||||
provider_factory: ProviderFactory<DB>,
|
provider_factory: ProviderFactory<DB>,
|
||||||
/// Static File provider
|
|
||||||
static_file_provider: StaticFileProvider,
|
|
||||||
/// Pruning configuration for every part of the data that can be pruned. Set by user, and
|
/// Pruning configuration for every part of the data that can be pruned. Set by user, and
|
||||||
/// needed in [`StaticFileProducerInner`] to prevent attempting to move prunable data to static
|
/// needed in [`StaticFileProducerInner`] to prevent attempting to move prunable data to static
|
||||||
/// files. See [`StaticFileProducerInner::get_static_file_targets`].
|
/// files. See [`StaticFileProducerInner::get_static_file_targets`].
|
||||||
@ -102,17 +89,8 @@ impl StaticFileTargets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<DB: Database> StaticFileProducerInner<DB> {
|
impl<DB: Database> StaticFileProducerInner<DB> {
|
||||||
fn new(
|
fn new(provider_factory: ProviderFactory<DB>, prune_modes: PruneModes) -> Self {
|
||||||
provider_factory: ProviderFactory<DB>,
|
Self { provider_factory, prune_modes, event_sender: Default::default() }
|
||||||
static_file_provider: StaticFileProvider,
|
|
||||||
prune_modes: PruneModes,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
provider_factory,
|
|
||||||
static_file_provider,
|
|
||||||
prune_modes,
|
|
||||||
event_sender: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen for events on the `static_file_producer`.
|
/// Listen for events on the `static_file_producer`.
|
||||||
@ -123,8 +101,9 @@ impl<DB: Database> StaticFileProducerInner<DB> {
|
|||||||
/// Run the `static_file_producer`.
|
/// Run the `static_file_producer`.
|
||||||
///
|
///
|
||||||
/// For each [Some] target in [`StaticFileTargets`], initializes a corresponding [Segment] and
|
/// For each [Some] target in [`StaticFileTargets`], initializes a corresponding [Segment] and
|
||||||
/// runs it with the provided block range using [`StaticFileProvider`] and a read-only
|
/// runs it with the provided block range using [`reth_provider::providers::StaticFileProvider`]
|
||||||
/// database transaction from [`ProviderFactory`]. All segments are run in parallel.
|
/// and a read-only database transaction from [`ProviderFactory`]. All segments are run in
|
||||||
|
/// parallel.
|
||||||
///
|
///
|
||||||
/// NOTE: it doesn't delete the data from database, and the actual deleting (aka pruning) logic
|
/// NOTE: it doesn't delete the data from database, and the actual deleting (aka pruning) logic
|
||||||
/// lives in the `prune` crate.
|
/// lives in the `prune` crate.
|
||||||
@ -135,7 +114,7 @@ impl<DB: Database> StaticFileProducerInner<DB> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug_assert!(targets.is_contiguous_to_highest_static_files(
|
debug_assert!(targets.is_contiguous_to_highest_static_files(
|
||||||
self.static_file_provider.get_highest_static_files()
|
self.provider_factory.static_file_provider().get_highest_static_files()
|
||||||
));
|
));
|
||||||
|
|
||||||
self.event_sender.notify(StaticFileProducerEvent::Started { targets: targets.clone() });
|
self.event_sender.notify(StaticFileProducerEvent::Started { targets: targets.clone() });
|
||||||
@ -162,7 +141,7 @@ impl<DB: Database> StaticFileProducerInner<DB> {
|
|||||||
// Create a new database transaction on every segment to prevent long-lived read-only
|
// Create a new database transaction on every segment to prevent long-lived read-only
|
||||||
// transactions
|
// transactions
|
||||||
let provider = self.provider_factory.provider()?.disable_long_read_transaction_safety();
|
let provider = self.provider_factory.provider()?.disable_long_read_transaction_safety();
|
||||||
segment.copy_to_static_files(provider, self.static_file_provider.clone(), block_range.clone())?;
|
segment.copy_to_static_files(provider, self.provider_factory.static_file_provider(), block_range.clone())?;
|
||||||
|
|
||||||
let elapsed = start.elapsed(); // TODO(alexey): track in metrics
|
let elapsed = start.elapsed(); // TODO(alexey): track in metrics
|
||||||
debug!(target: "static_file", segment = %segment.segment(), ?block_range, ?elapsed, "Finished StaticFileProducer segment");
|
debug!(target: "static_file", segment = %segment.segment(), ?block_range, ?elapsed, "Finished StaticFileProducer segment");
|
||||||
@ -170,9 +149,11 @@ impl<DB: Database> StaticFileProducerInner<DB> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.static_file_provider.commit()?;
|
self.provider_factory.static_file_provider().commit()?;
|
||||||
for (segment, block_range) in segments {
|
for (segment, block_range) in segments {
|
||||||
self.static_file_provider.update_index(segment.segment(), Some(*block_range.end()))?;
|
self.provider_factory
|
||||||
|
.static_file_provider()
|
||||||
|
.update_index(segment.segment(), Some(*block_range.end()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let elapsed = start.elapsed(); // TODO(alexey): track in metrics
|
let elapsed = start.elapsed(); // TODO(alexey): track in metrics
|
||||||
@ -186,12 +167,13 @@ impl<DB: Database> StaticFileProducerInner<DB> {
|
|||||||
|
|
||||||
/// Returns a static file targets at the provided finalized block numbers per segment.
|
/// Returns a static file targets at the provided finalized block numbers per segment.
|
||||||
/// The target is determined by the check against highest `static_files` using
|
/// The target is determined by the check against highest `static_files` using
|
||||||
/// [`StaticFileProvider::get_highest_static_files`].
|
/// [`reth_provider::providers::StaticFileProvider::get_highest_static_files`].
|
||||||
pub fn get_static_file_targets(
|
pub fn get_static_file_targets(
|
||||||
&self,
|
&self,
|
||||||
finalized_block_numbers: HighestStaticFiles,
|
finalized_block_numbers: HighestStaticFiles,
|
||||||
) -> ProviderResult<StaticFileTargets> {
|
) -> ProviderResult<StaticFileTargets> {
|
||||||
let highest_static_files = self.static_file_provider.get_highest_static_files();
|
let highest_static_files =
|
||||||
|
self.provider_factory.static_file_provider().get_highest_static_files();
|
||||||
|
|
||||||
let targets = StaticFileTargets {
|
let targets = StaticFileTargets {
|
||||||
headers: finalized_block_numbers.headers.and_then(|finalized_block_number| {
|
headers: finalized_block_numbers.headers.and_then(|finalized_block_number| {
|
||||||
@ -251,8 +233,7 @@ mod tests {
|
|||||||
static_file::HighestStaticFiles, PruneModes, StaticFileSegment, B256, U256,
|
static_file::HighestStaticFiles, PruneModes, StaticFileSegment, B256, U256,
|
||||||
};
|
};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::{StaticFileProvider, StaticFileWriter},
|
providers::StaticFileWriter, ProviderError, ProviderFactory, StaticFileProviderFactory,
|
||||||
ProviderError, ProviderFactory, StaticFileProviderFactory,
|
|
||||||
};
|
};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::{
|
||||||
@ -265,7 +246,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
fn setup() -> (ProviderFactory<Arc<TempDatabase<DatabaseEnv>>>, StaticFileProvider, TempDir) {
|
fn setup() -> (ProviderFactory<Arc<TempDatabase<DatabaseEnv>>>, TempDir) {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
|
|
||||||
@ -297,19 +278,15 @@ mod tests {
|
|||||||
db.insert_receipts(receipts).expect("insert receipts");
|
db.insert_receipts(receipts).expect("insert receipts");
|
||||||
|
|
||||||
let provider_factory = db.factory;
|
let provider_factory = db.factory;
|
||||||
let static_file_provider = provider_factory.static_file_provider();
|
(provider_factory, db.temp_static_files_dir)
|
||||||
(provider_factory, static_file_provider, db.temp_static_files_dir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run() {
|
fn run() {
|
||||||
let (provider_factory, static_file_provider, _temp_static_files_dir) = setup();
|
let (provider_factory, _temp_static_files_dir) = setup();
|
||||||
|
|
||||||
let static_file_producer = StaticFileProducerInner::new(
|
let static_file_producer =
|
||||||
provider_factory,
|
StaticFileProducerInner::new(provider_factory.clone(), PruneModes::default());
|
||||||
static_file_provider.clone(),
|
|
||||||
PruneModes::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let targets = static_file_producer
|
let targets = static_file_producer
|
||||||
.get_static_file_targets(HighestStaticFiles {
|
.get_static_file_targets(HighestStaticFiles {
|
||||||
@ -328,7 +305,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_matches!(static_file_producer.run(targets), Ok(_));
|
assert_matches!(static_file_producer.run(targets), Ok(_));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
static_file_provider.get_highest_static_files(),
|
provider_factory.static_file_provider().get_highest_static_files(),
|
||||||
HighestStaticFiles { headers: Some(1), receipts: Some(1), transactions: Some(1) }
|
HighestStaticFiles { headers: Some(1), receipts: Some(1), transactions: Some(1) }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -349,7 +326,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_matches!(static_file_producer.run(targets), Ok(_));
|
assert_matches!(static_file_producer.run(targets), Ok(_));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
static_file_provider.get_highest_static_files(),
|
provider_factory.static_file_provider().get_highest_static_files(),
|
||||||
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
|
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -373,7 +350,7 @@ mod tests {
|
|||||||
Err(ProviderError::BlockBodyIndicesNotFound(4))
|
Err(ProviderError::BlockBodyIndicesNotFound(4))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
static_file_provider.get_highest_static_files(),
|
provider_factory.static_file_provider().get_highest_static_files(),
|
||||||
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
|
HighestStaticFiles { headers: Some(3), receipts: Some(3), transactions: Some(3) }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -381,10 +358,9 @@ mod tests {
|
|||||||
/// Tests that a cloneable [`StaticFileProducer`] type is not susceptible to any race condition.
|
/// Tests that a cloneable [`StaticFileProducer`] type is not susceptible to any race condition.
|
||||||
#[test]
|
#[test]
|
||||||
fn only_one() {
|
fn only_one() {
|
||||||
let (provider_factory, static_file_provider, _temp_static_files_dir) = setup();
|
let (provider_factory, _temp_static_files_dir) = setup();
|
||||||
|
|
||||||
let static_file_producer =
|
let static_file_producer = StaticFileProducer::new(provider_factory, PruneModes::default());
|
||||||
StaticFileProducer::new(provider_factory, static_file_provider, PruneModes::default());
|
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user