mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: create new methods with Config arguments for existing builders (#5837)
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
@ -14,6 +14,7 @@ reth-interfaces.workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-tasks.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-config.workspace = true
|
||||
|
||||
# async
|
||||
futures.workspace = true
|
||||
|
||||
@ -2,6 +2,7 @@ use super::queue::BodiesRequestQueue;
|
||||
use crate::{bodies::task::TaskDownloader, metrics::BodyDownloaderMetrics};
|
||||
use futures::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use reth_config::BodiesConfig;
|
||||
use reth_interfaces::{
|
||||
consensus::Consensus,
|
||||
p2p::{
|
||||
@ -492,6 +493,21 @@ pub struct BodiesDownloaderBuilder {
|
||||
pub concurrent_requests_range: RangeInclusive<usize>,
|
||||
}
|
||||
|
||||
impl BodiesDownloaderBuilder {
|
||||
/// Creates a new [BodiesDownloaderBuilder] with configurations based on the provided
|
||||
/// [BodiesConfig].
|
||||
pub fn new(config: BodiesConfig) -> Self {
|
||||
BodiesDownloaderBuilder::default()
|
||||
.with_stream_batch_size(config.downloader_stream_batch_size)
|
||||
.with_request_limit(config.downloader_request_limit)
|
||||
.with_max_buffered_blocks_size_bytes(config.downloader_max_buffered_blocks_size_bytes)
|
||||
.with_concurrent_requests_range(
|
||||
config.downloader_min_concurrent_requests..=
|
||||
config.downloader_max_concurrent_requests,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BodiesDownloaderBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
||||
@ -5,6 +5,7 @@ use crate::metrics::HeaderDownloaderMetrics;
|
||||
use futures::{stream::Stream, FutureExt};
|
||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||
use rayon::prelude::*;
|
||||
use reth_config::config::HeadersConfig;
|
||||
use reth_interfaces::{
|
||||
consensus::Consensus,
|
||||
p2p::{
|
||||
@ -1087,6 +1088,19 @@ pub struct ReverseHeadersDownloaderBuilder {
|
||||
max_buffered_responses: usize,
|
||||
}
|
||||
|
||||
impl ReverseHeadersDownloaderBuilder {
|
||||
/// Creates a new [ReverseHeadersDownloaderBuilder] with configurations based on the provided
|
||||
/// [HeadersConfig].
|
||||
pub fn new(config: HeadersConfig) -> Self {
|
||||
ReverseHeadersDownloaderBuilder::default()
|
||||
.request_limit(config.downloader_request_limit)
|
||||
.min_concurrent_requests(config.downloader_min_concurrent_requests)
|
||||
.max_concurrent_requests(config.downloader_max_concurrent_requests)
|
||||
.max_buffered_responses(config.downloader_max_buffered_responses)
|
||||
.stream_batch_size(config.commit_threshold as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ReverseHeadersDownloaderBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user