feat: integrate HeaderValidator + make FileClient generic over block (#12681)

This commit is contained in:
Arsenii Kulikov
2024-11-20 15:07:24 +04:00
committed by GitHub
parent 6977cf0453
commit 868f3acdbc
19 changed files with 143 additions and 89 deletions

View File

@ -370,7 +370,7 @@ where
.with_tip_sender(tip_tx),
TestPipelineConfig::Real => {
let header_downloader = ReverseHeadersDownloaderBuilder::default()
.build(client.clone(), consensus.clone())
.build(client.clone(), consensus.clone().as_header_validator())
.into_task();
let body_downloader = BodiesDownloaderBuilder::default()

View File

@ -11,7 +11,7 @@
extern crate alloc;
use alloc::{fmt::Debug, vec::Vec};
use alloc::{fmt::Debug, sync::Arc, vec::Vec};
use alloy_consensus::Header;
use alloy_eips::eip7685::Requests;
use alloy_primitives::{BlockHash, BlockNumber, Bloom, B256, U256};
@ -46,7 +46,9 @@ impl<'a> PostExecutionInput<'a> {
/// Consensus is a protocol that chooses canonical chain.
#[auto_impl::auto_impl(&, Arc)]
pub trait Consensus<H = Header, B = BlockBody>: HeaderValidator<H> + Debug + Send + Sync {
pub trait Consensus<H = Header, B = BlockBody>:
AsHeaderValidator<H> + HeaderValidator<H> + Debug + Send + Sync
{
/// Ensures that body field values match the header.
fn validate_body_against_header(
&self,
@ -143,6 +145,23 @@ pub trait HeaderValidator<H = Header>: Debug + Send + Sync {
) -> Result<(), ConsensusError>;
}
/// Helper trait to cast `Arc<dyn Consensus>` to `Arc<dyn HeaderValidator>`
pub trait AsHeaderValidator<H>: HeaderValidator<H> {
/// Converts the [`Arc`] of self to [`Arc`] of [`HeaderValidator`]
fn as_header_validator<'a>(self: Arc<Self>) -> Arc<dyn HeaderValidator<H> + 'a>
where
Self: 'a;
}
impl<T: HeaderValidator<H>, H> AsHeaderValidator<H> for T {
fn as_header_validator<'a>(self: Arc<Self>) -> Arc<dyn HeaderValidator<H> + 'a>
where
Self: 'a,
{
self
}
}
/// Consensus Errors
#[derive(Debug, PartialEq, Eq, Clone, derive_more::Display, derive_more::Error)]
pub enum ConsensusError {