Skip to content

Commit

Permalink
chore: only issue single header request (#12496)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 13, 2024
1 parent 5c62d68 commit 39392e9
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions crates/node/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use alloy_rpc_types_engine::{JwtError, JwtSecret};
use eyre::Result;
use reth_consensus::Consensus;
use reth_network_p2p::{
bodies::client::BodiesClient,
headers::client::{HeadersClient, HeadersDirection, HeadersRequest},
priority::Priority,
bodies::client::BodiesClient, headers::client::HeadersClient, priority::Priority,
};
use reth_primitives::{SealedBlock, SealedHeader};
use std::{
Expand Down Expand Up @@ -44,17 +42,13 @@ pub async fn get_single_header<Client>(
where
Client: HeadersClient<Header: reth_primitives_traits::BlockHeader>,
{
let request = HeadersRequest { direction: HeadersDirection::Rising, limit: 1, start: id };
let (peer_id, response) = client.get_header_with_priority(id, Priority::High).await?.split();

let (peer_id, response) =
client.get_headers_with_priority(request, Priority::High).await?.split();

if response.len() != 1 {
let Some(sealed_header) = response.map(|block| block.seal_slow()) else {
client.report_bad_message(peer_id);
eyre::bail!("Invalid number of headers received. Expected: 1. Received: {}", response.len())
}
eyre::bail!("Invalid number of headers received. Expected: 1. Received: 0")
};

let sealed_header = response.into_iter().next().unwrap().seal_slow();
let (header, seal) = sealed_header.into_parts();
let header = SealedHeader::new(header, seal);

Expand Down

0 comments on commit 39392e9

Please sign in to comment.