feat: make bodies downloader generic over header (#13259)

This commit is contained in:
Dan Cline
2024-12-10 04:29:51 -05:00
committed by GitHub
parent da99986ea2
commit 15470b4350
10 changed files with 112 additions and 92 deletions

View File

@ -5,7 +5,7 @@ use reth_db::{tables, transaction::DbTx};
use reth_db_api::{cursor::DbCursorRO, transaction::DbTxMut};
use reth_network_p2p::bodies::{downloader::BodyDownloader, response::BlockResponse};
use reth_primitives::StaticFileSegment;
use reth_primitives_traits::{Block, BlockBody};
use reth_primitives_traits::{Block, BlockBody, BlockHeader};
use reth_provider::{
providers::StaticFileWriter, BlockReader, BlockWriter, DBProvider, ProviderError,
StaticFileProviderFactory, StatsReader, StorageLocation,
@ -56,7 +56,7 @@ pub struct BodyStage<D: BodyDownloader> {
/// The body downloader.
downloader: D,
/// Block response buffer.
buffer: Option<Vec<BlockResponse<alloy_consensus::Header, D::Body>>>,
buffer: Option<Vec<BlockResponse<D::Header, D::Body>>>,
}
impl<D: BodyDownloader> BodyStage<D> {
@ -72,9 +72,7 @@ impl<D: BodyDownloader> BodyStage<D> {
unwind_block: Option<u64>,
) -> Result<(), StageError>
where
Provider: DBProvider<Tx: DbTxMut>
+ BlockReader<Header = reth_primitives::Header>
+ StaticFileProviderFactory,
Provider: DBProvider<Tx: DbTxMut> + BlockReader + StaticFileProviderFactory,
{
// Get id for the next tx_num of zero if there are no transactions.
let next_tx_num = provider
@ -151,9 +149,9 @@ where
Provider: DBProvider<Tx: DbTxMut>
+ StaticFileProviderFactory
+ StatsReader
+ BlockReader<Header = reth_primitives::Header>
+ BlockWriter<Block: Block<Body = D::Body>>,
D: BodyDownloader<Body: BlockBody<Transaction: Compact>>,
+ BlockReader
+ BlockWriter<Block: Block<Header = D::Header, Body = D::Body>>,
D: BodyDownloader<Header: BlockHeader, Body: BlockBody<Transaction: Compact>>,
{
/// Return the id of the stage
fn id(&self) -> StageId {
@ -764,6 +762,7 @@ mod tests {
}
impl BodyDownloader for TestBodyDownloader {
type Header = Header;
type Body = BlockBody;
fn set_download_range(
@ -786,7 +785,7 @@ mod tests {
}
impl Stream for TestBodyDownloader {
type Item = BodyDownloaderResult<BlockBody>;
type Item = BodyDownloaderResult<Header, BlockBody>;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();

View File

@ -258,7 +258,7 @@ pub(crate) fn missing_static_data_error<Provider>(
segment: StaticFileSegment,
) -> Result<StageError, ProviderError>
where
Provider: BlockReader<Header = reth_primitives::Header> + StaticFileProviderFactory,
Provider: BlockReader + StaticFileProviderFactory,
{
let mut last_block =
static_file_provider.get_highest_static_file_block(segment).unwrap_or_default();