Skip to content

Commit 09b2e43

Browse files
committed
batch transform headers
1 parent 28b3d0a commit 09b2e43

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

crates/net/network/src/fetch/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use client::FetchClient;
66

77
use crate::{message::BlockRequest, session::BlockRangeInfo, transform::header::HeaderTransform};
88
use alloy_primitives::B256;
9-
use futures::{future::join_all, StreamExt};
9+
use futures::StreamExt;
1010
use reth_eth_wire::{EthNetworkPrimitives, GetBlockBodies, GetBlockHeaders, NetworkPrimitives};
1111
use reth_network_api::test_utils::PeersHandle;
1212
use reth_network_p2p::{
@@ -282,9 +282,7 @@ impl<N: NetworkPrimitives> StateFetcher<N> {
282282
let header_transform = self.header_transform.clone();
283283
tokio::spawn(async move {
284284
let res = match res {
285-
Ok(headers) => {
286-
Ok(join_all(headers.into_iter().map(|h| header_transform.map(h))).await)
287-
}
285+
Ok(headers) => Ok(header_transform.map(headers).await),
288286
Err(e) => Err(e),
289287
};
290288

crates/net/network/src/transform/header.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
33
use reth_primitives_traits::BlockHeader;
44

5-
/// An instance of the trait applies a mapping to the input header.
5+
/// An instance of the trait applies a mapping to the input headers.
66
#[async_trait::async_trait]
77
pub trait HeaderTransform<H: BlockHeader>: std::fmt::Debug + Send + Sync {
8-
/// Applies a mapping to the input header.
9-
async fn map(&self, header: H) -> H;
8+
/// Applies a mapping to the input headers.
9+
async fn map(&self, headers: Vec<H>) -> Vec<H>;
1010
}
1111

1212
#[async_trait::async_trait]
1313
impl<H: BlockHeader> HeaderTransform<H> for () {
14-
async fn map(&self, header: H) -> H {
15-
header
14+
async fn map(&self, headers: Vec<H>) -> Vec<H> {
15+
headers
1616
}
1717
}
1818

0 commit comments

Comments
 (0)