chore(downloader): simplify the canonical blocks check (#22739)

Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
Delweng
2026-03-11 19:28:39 +08:00
committed by GitHub
parent a73f510766
commit 460d522443

View File

@@ -3,7 +3,7 @@ use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockHash, BlockNumber, Sealable, B256};
use async_compression::tokio::bufread::GzipDecoder;
use futures::Future;
use itertools::Either;
use itertools::{Either, Itertools};
use reth_consensus::{Consensus, ConsensusError};
use reth_network_p2p::{
bodies::client::{BodiesClient, BodiesFut},
@@ -163,17 +163,9 @@ impl<B: FullBlock> FileClient<B> {
if self.headers.is_empty() {
return true
}
let mut nums = self.headers.keys().copied().collect::<Vec<_>>();
nums.sort_unstable();
let mut iter = nums.into_iter();
let mut lowest = iter.next().expect("not empty");
for next in iter {
if next != lowest + 1 {
return false
}
lowest = next;
}
true
let (min, max) = self.headers.keys().minmax().into_option().expect("not empty");
// Contiguous range from min to max means no gaps
*max - *min + 1 == self.headers.len() as u64
}
/// Use the provided bodies as the file client's block body buffer.