Skip to content

Commit

Permalink
migrate downloaders
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jan 10, 2025
1 parent 61e6ae7 commit 51654d5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
50 changes: 27 additions & 23 deletions crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,16 @@ mod tests {
);
let (_static_dir, static_dir_path) = create_test_static_files_dir();

let mut downloader = BodiesDownloaderBuilder::default().build(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
),
);
let mut downloader = BodiesDownloaderBuilder::default()
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
),
);
downloader.set_download_range(0..=19).expect("failed to set download range");

assert_matches!(
Expand Down Expand Up @@ -686,16 +687,17 @@ mod tests {
let client = Arc::new(TestBodiesClient::default().with_bodies(bodies.clone()));
let (_static_dir, static_dir_path) = create_test_static_files_dir();

let mut downloader =
BodiesDownloaderBuilder::default().with_request_limit(request_limit).build(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
),
);
let mut downloader = BodiesDownloaderBuilder::default()
.with_request_limit(request_limit)
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
db,
MAINNET.clone(),
StaticFileProvider::read_write(static_dir_path).unwrap(),
),
);
downloader.set_download_range(0..=199).expect("failed to set download range");

let _ = downloader.collect::<Vec<_>>().await;
Expand All @@ -721,7 +723,7 @@ mod tests {
let mut downloader = BodiesDownloaderBuilder::default()
.with_stream_batch_size(stream_batch_size)
.with_request_limit(request_limit)
.build(
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
Expand Down Expand Up @@ -757,7 +759,9 @@ mod tests {
let client = Arc::new(TestBodiesClient::default().with_bodies(bodies.clone()));
let (_static_dir, static_dir_path) = create_test_static_files_dir();

let mut downloader = BodiesDownloaderBuilder::default().with_stream_batch_size(100).build(
let mut downloader = BodiesDownloaderBuilder::default()
.with_stream_batch_size(100)
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
Expand Down Expand Up @@ -803,7 +807,7 @@ mod tests {
.with_stream_batch_size(10)
.with_request_limit(1)
.with_max_buffered_blocks_size_bytes(1)
.build(
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
Expand Down Expand Up @@ -840,7 +844,7 @@ mod tests {
let mut downloader = BodiesDownloaderBuilder::default()
.with_request_limit(3)
.with_stream_batch_size(100)
.build(
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
ProviderFactory::<MockNodeTypesWithDB>::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/net/downloaders/src/bodies/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mod tests {
let headers = random_header_range(&mut rng, 0..20, B256::ZERO);

let client = Arc::new(TestBodiesClient::default());
let fut = BodiesRequestFuture::new(
let fut = BodiesRequestFuture::<reth_primitives::Block, _>::new(
client.clone(),
Arc::new(TestConsensus::default()),
BodyDownloaderMetrics::default(),
Expand All @@ -299,7 +299,7 @@ mod tests {
let client = Arc::new(
TestBodiesClient::default().with_bodies(bodies.clone()).with_max_batch_size(batch_size),
);
let fut = BodiesRequestFuture::new(
let fut = BodiesRequestFuture::<reth_primitives::Block, _>::new(
client.clone(),
Arc::new(TestConsensus::default()),
BodyDownloaderMetrics::default(),
Expand Down
18 changes: 10 additions & 8 deletions crates/net/downloaders/src/bodies/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ impl<B: Block + 'static> TaskDownloader<B> {
/// use reth_consensus::{Consensus, ConsensusError};
/// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader};
/// use reth_network_p2p::bodies::client::BodiesClient;
/// use reth_primitives_traits::InMemorySize;
/// use reth_primitives_traits::{Block, InMemorySize};
/// use reth_storage_api::HeaderProvider;
/// use std::{fmt::Debug, sync::Arc};
///
/// fn t<
/// B: BodiesClient<Block: Debug + InMemorySize> + 'static,
/// Provider: HeaderProvider<Header = alloy_consensus::Header> + Unpin + 'static,
/// B: Block,
/// C: BodiesClient<Body = B::Body> + 'static,
/// Provider: HeaderProvider<Header = B::Header> + Unpin + 'static,
/// >(
/// client: Arc<B>,
/// consensus: Arc<dyn Consensus<Provider::Header, B::Block, Error = ConsensusError>>,
/// client: Arc<C>,
/// consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
/// provider: Provider,
/// ) {
/// let downloader = BodiesDownloaderBuilder::default().build(client, consensus, provider);
/// let downloader =
/// BodiesDownloaderBuilder::default().build::<B, _, _>(client, consensus, provider);
/// let downloader = TaskDownloader::spawn(downloader);
/// }
/// ```
Expand Down Expand Up @@ -193,7 +195,7 @@ mod tests {
let client = Arc::new(
TestBodiesClient::default().with_bodies(bodies.clone()).with_should_delay(true),
);
let downloader = BodiesDownloaderBuilder::default().build(
let downloader = BodiesDownloaderBuilder::default().build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
factory,
Expand All @@ -215,7 +217,7 @@ mod tests {
reth_tracing::init_test_tracing();
let factory = create_test_provider_factory();

let downloader = BodiesDownloaderBuilder::default().build(
let downloader = BodiesDownloaderBuilder::default().build::<reth_primitives::Block, _, _>(
Arc::new(TestBodiesClient::default()),
Arc::new(TestConsensus::default()),
factory,
Expand Down
22 changes: 12 additions & 10 deletions crates/net/downloaders/src/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,12 @@ mod tests {

let client: Arc<FileClient> =
Arc::new(FileClient::from_file(file.into()).await.unwrap().with_bodies(bodies.clone()));
let mut downloader = BodiesDownloaderBuilder::default().build(
client.clone(),
Arc::new(TestConsensus::default()),
factory,
);
let mut downloader = BodiesDownloaderBuilder::default()
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
factory,
);
downloader.set_download_range(0..=19).expect("failed to set download range");

assert_matches!(
Expand Down Expand Up @@ -628,11 +629,12 @@ mod tests {
// insert headers in db for the bodies downloader
insert_headers(factory.db_ref().db(), &headers);

let mut downloader = BodiesDownloaderBuilder::default().build(
client.clone(),
Arc::new(TestConsensus::default()),
factory,
);
let mut downloader = BodiesDownloaderBuilder::default()
.build::<reth_primitives::Block, _, _>(
client.clone(),
Arc::new(TestConsensus::default()),
factory,
);
downloader.set_download_range(0..=19).expect("failed to set download range");

assert_matches!(
Expand Down

0 comments on commit 51654d5

Please sign in to comment.