perf(download): parallel header sealing (#1536)

This commit is contained in:
Roman Krasiuk
2023-02-24 10:13:18 +02:00
committed by GitHub
parent 6d138daa11
commit b14ee4e925
3 changed files with 5 additions and 3 deletions

1
Cargo.lock generated
View File

@ -4506,6 +4506,7 @@ dependencies = [
"itertools 0.10.5",
"metrics",
"pin-project",
"rayon",
"reth-db",
"reth-eth-wire",
"reth-interfaces",

View File

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

View File

@ -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::<Vec<_>>();
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())