primitives: use SealedHeader::seal (#12507)

This commit is contained in:
Thomas Coratger
2024-11-13 13:41:56 +01:00
committed by GitHub
parent 527767cc34
commit 9313737dbb
32 changed files with 108 additions and 277 deletions

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, io, path::Path};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockHash, BlockNumber, Sealable, B256};
use alloy_primitives::{BlockHash, BlockNumber, B256};
use futures::Future;
use itertools::Either;
use reth_network_p2p::{
@ -114,11 +114,7 @@ impl FileClient {
/// Clones and returns the highest header of this client has or `None` if empty. Seals header
/// before returning.
pub fn tip_header(&self) -> Option<SealedHeader> {
self.headers.get(&self.max_block()?).map(|h| {
let sealed = h.clone().seal_slow();
let (header, seal) = sealed.into_parts();
SealedHeader::new(header, seal)
})
self.headers.get(&self.max_block()?).map(|h| SealedHeader::seal(h.clone()))
}
/// Returns true if all blocks are canonical (no gaps)

View File

@ -4,7 +4,7 @@ use super::task::TaskDownloader;
use crate::metrics::HeaderDownloaderMetrics;
use alloy_consensus::BlockHeader;
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockNumber, Sealable, B256};
use alloy_primitives::{BlockNumber, B256};
use futures::{stream::Stream, FutureExt};
use futures_util::{stream::FuturesUnordered, StreamExt};
use rayon::prelude::*;
@ -250,15 +250,7 @@ where
) -> Result<(), ReverseHeadersDownloaderError<H::Header>> {
let mut validated = Vec::with_capacity(headers.len());
let sealed_headers = headers
.into_par_iter()
.map(|h| {
let sealed = h.seal_slow();
let (header, seal) = sealed.into_parts();
SealedHeader::new(header, seal)
})
.collect::<Vec<_>>();
let sealed_headers = headers.into_par_iter().map(SealedHeader::seal).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) =
@ -384,9 +376,8 @@ where
.into())
}
let sealed_target = headers.swap_remove(0).seal_slow();
let (header, seal) = sealed_target.into_parts();
let target = SealedHeader::new(header, seal);
let header = headers.swap_remove(0);
let target = SealedHeader::seal(header);
match sync_target {
SyncTargetBlock::Hash(hash) | SyncTargetBlock::HashAndNumber { hash, .. } => {

View File

@ -2,7 +2,6 @@
#![allow(dead_code)]
use alloy_primitives::Sealable;
use reth_primitives::SealedHeader;
/// Returns a new [`SealedHeader`] that's the child header of the given `parent`.
@ -10,7 +9,5 @@ pub(crate) fn child_header(parent: &SealedHeader) -> SealedHeader {
let mut child = parent.as_ref().clone();
child.number += 1;
child.parent_hash = parent.hash_slow();
let sealed = child.seal_slow();
let (header, seal) = sealed.into_parts();
SealedHeader::new(header, seal)
SealedHeader::seal(child)
}