diff --git a/Cargo.lock b/Cargo.lock index 59bcee4bf..898170dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4506,6 +4506,7 @@ dependencies = [ "itertools 0.10.5", "metrics", "pin-project", + "rayon", "reth-db", "reth-eth-wire", "reth-interfaces", diff --git a/crates/net/downloaders/Cargo.toml b/crates/net/downloaders/Cargo.toml index cb7d8fc2b..76a7fc67a 100644 --- a/crates/net/downloaders/Cargo.toml +++ b/crates/net/downloaders/Cargo.toml @@ -26,6 +26,7 @@ tokio-stream = "0.1" # misc tracing = "0.1.37" metrics = "0.20.1" +rayon = "1.6.0" # optional deps for the test-utils feature thiserror = { version = "1", optional = true } diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index 8bcf9031d..5e0f869b6 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -4,6 +4,7 @@ use super::task::TaskDownloader; use crate::metrics::DownloaderMetrics; use futures::{stream::Stream, FutureExt}; use futures_util::{stream::FuturesUnordered, StreamExt}; +use rayon::prelude::*; use reth_interfaces::{ consensus::Consensus, p2p::{ @@ -200,9 +201,8 @@ where let sync_target_hash = self.existing_sync_target_hash(); let mut validated = Vec::with_capacity(headers.len()); - for parent in headers { - let parent = parent.seal_slow(); - + let sealed_headers = headers.into_par_iter().map(|h| h.seal_slow()).collect::>(); + for parent in sealed_headers { // Validate that the header is the parent header of the last validated header. if let Some(validated_header) = validated.last().or_else(|| self.lowest_validated_header())