Skip to content

Commit

Permalink
Move FileClient and BlockFileCodec out of test-utils (paradigmxyz…
Browse files Browse the repository at this point in the history
…#5998)

Co-authored-by: Dan Cline <[email protected]>
  • Loading branch information
tcoratger and Rjected authored Jan 10, 2024
1 parent 43cdd73 commit 26e31f3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ reth-rpc-types-compat.workspace = true
reth-rpc-api = { workspace = true, features = ["client"] }
reth-network = { workspace = true, features = ["serde"] }
reth-network-api.workspace = true
reth-downloaders = { workspace = true, features = ["test-utils"] }
reth-downloaders.workspace = true
reth-tracing.workspace = true
reth-tasks.workspace = true
reth-net-nat.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use reth_beacon_consensus::BeaconConsensus;
use reth_config::Config;
use reth_db::{database::Database, init_db};
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
headers::reverse_headers::ReverseHeadersDownloaderBuilder, test_utils::FileClient,
bodies::bodies::BodiesDownloaderBuilder, file_client::FileClient,
headers::reverse_headers::ReverseHeadersDownloaderBuilder,
};
use reth_interfaces::consensus::Consensus;
use reth_primitives::{stage::StageId, ChainSpec, B256};
Expand Down
7 changes: 4 additions & 3 deletions crates/net/downloaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ thiserror.workspace = true

# optional deps for the test-utils feature
reth-db = { workspace = true, optional = true }
alloy-rlp = { workspace = true, optional = true }
alloy-rlp.workspace = true
tempfile = { workspace = true, optional = true }
itertools = { workspace = true, optional = true }
itertools.workspace = true

[dev-dependencies]
reth-db = { workspace = true, features = ["test-utils"] }
Expand All @@ -55,4 +55,5 @@ itertools.workspace = true
tempfile.workspace = true

[features]
test-utils = ["dep:alloy-rlp", "dep:tempfile", "dep:itertools", "reth-db/test-utils", "reth-interfaces/test-utils"]
test-utils = ["dep:tempfile", "reth-db/test-utils", "reth-interfaces/test-utils"]

Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ impl FileClient {
}

/// Use the provided bodies as the file client's block body buffer.
pub(crate) fn with_bodies(mut self, bodies: HashMap<BlockHash, BlockBody>) -> Self {
pub fn with_bodies(mut self, bodies: HashMap<BlockHash, BlockBody>) -> Self {
self.bodies = bodies;
self
}

/// Use the provided headers as the file client's block body buffer.
pub(crate) fn with_headers(mut self, headers: HashMap<BlockNumber, Header>) -> Self {
pub fn with_headers(mut self, headers: HashMap<BlockNumber, Header>) -> Self {
self.headers = headers;
for (number, header) in &self.headers {
self.hash_to_number.insert(header.hash_slow(), *number);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Codec for reading raw block bodies from a file.

use super::FileClientError;
use crate::file_client::FileClientError;
use alloy_rlp::{Decodable, Encodable};
use reth_primitives::{
bytes::{Buf, BytesMut},
Expand Down
11 changes: 11 additions & 0 deletions crates/net/downloaders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ pub mod headers;
/// Common downloader metrics.
pub mod metrics;

/// Module managing file-based data retrieval and buffering.
///
/// Contains [FileClient](file_client::FileClient) to read block data from files,
/// efficiently buffering headers and bodies for retrieval.
pub mod file_client;

/// Module with a codec for reading and encoding block bodies in files.
///
/// Enables decoding and encoding `Block` types within file contexts.
pub mod file_codec;

#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
8 changes: 1 addition & 7 deletions crates/net/downloaders/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![allow(dead_code)]

use crate::bodies::test_utils::create_raw_bodies;
use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec};
use futures::SinkExt;
use reth_interfaces::test_utils::{generators, generators::random_block_range};
use reth_primitives::{BlockBody, SealedHeader, B256};
Expand All @@ -13,12 +13,6 @@ use tokio_util::codec::FramedWrite;
mod bodies_client;
pub use bodies_client::TestBodiesClient;

mod file_client;
pub use file_client::{FileClient, FileClientError};

mod file_codec;
pub(crate) use file_codec::BlockFileCodec;

/// Metrics scope used for testing.
pub(crate) const TEST_SCOPE: &str = "downloaders.test";

Expand Down

0 comments on commit 26e31f3

Please sign in to comment.