feat(downloaders): add file-client feature gate (#18707)

This commit is contained in:
Waiting
2025-09-26 20:59:08 +08:00
committed by GitHub
parent 597fa73023
commit 5dc2857713
4 changed files with 13 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ reth-testing-utils = { workspace = true, optional = true }
alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-rlp = { workspace = true, optional = true }
# async
futures.workspace = true
@@ -40,7 +40,7 @@ pin-project.workspace = true
tokio = { workspace = true, features = ["sync", "fs", "io-util"] }
tokio-stream.workspace = true
tokio-util = { workspace = true, features = ["codec"] }
async-compression = { workspace = true, features = ["gzip", "tokio"] }
async-compression = { workspace = true, features = ["gzip", "tokio"], optional = true }
# metrics
reth-metrics.workspace = true
@@ -55,6 +55,7 @@ tempfile = { workspace = true, optional = true }
itertools.workspace = true
[dev-dependencies]
async-compression = { workspace = true, features = ["gzip", "tokio"] }
reth-ethereum-primitives.workspace = true
reth-chainspec.workspace = true
reth-db = { workspace = true, features = ["test-utils"] }
@@ -71,6 +72,8 @@ rand.workspace = true
tempfile.workspace = true
[features]
default = []
file-client = ["dep:async-compression", "dep:alloy-rlp"]
test-utils = [
"tempfile",
"reth-db-api",

View File

@@ -3,6 +3,7 @@
//! ## Feature Flags
//!
//! - `test-utils`: Export utilities for testing
//! - `file-client`: Enables the file-based clients for reading blocks and receipts from files.
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
@@ -25,20 +26,24 @@ pub mod metrics;
///
/// Contains [`FileClient`](file_client::FileClient) to read block data from files,
/// efficiently buffering headers and bodies for retrieval.
#[cfg(any(test, feature = "file-client"))]
pub mod file_client;
/// Module managing file-based data retrieval and buffering of receipts.
///
/// Contains [`ReceiptFileClient`](receipt_file_client::ReceiptFileClient) to read receipt data from
/// files, efficiently buffering receipts for retrieval.
#[cfg(any(test, feature = "file-client"))]
pub mod receipt_file_client;
/// Module with a codec for reading and encoding block bodies in files.
///
/// Enables decoding and encoding `Block` types within file contexts.
#[cfg(any(test, feature = "file-client"))]
pub mod file_codec;
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
#[cfg(any(test, feature = "file-client"))]
pub use file_client::{DecodedFileChunk, FileClientError};

View File

@@ -2,6 +2,7 @@
#![allow(dead_code)]
#[cfg(any(test, feature = "file-client"))]
use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec};
use alloy_primitives::B256;
use futures::SinkExt;
@@ -37,6 +38,7 @@ pub(crate) fn generate_bodies(
/// Generate a set of bodies, write them to a temporary file, and return the file along with the
/// bodies and corresponding block hashes
#[cfg(any(test, feature = "file-client"))]
pub(crate) async fn generate_bodies_file(
range: RangeInclusive<u64>,
) -> (tokio::fs::File, Vec<SealedHeader>, HashMap<B256, BlockBody>) {