Move FileClient and BlockFileCodec out of test-utils (#5998)

Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
Thomas Coratger
2024-01-10 20:02:57 +01:00
committed by GitHub
parent 43cdd73acf
commit 26e31f3197
7 changed files with 22 additions and 16 deletions

View File

@ -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"] }
@ -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"]

View File

@ -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);

View File

@ -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},

View File

@ -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;

View File

@ -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};
@ -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";