reth::consensus

Trait HeaderValidator

pub trait HeaderValidator<H = Header>:
    Debug
    + Send
    + Sync {
    // Required methods
    fn validate_header(
        &self,
        header: &SealedHeader<H>,
    ) -> Result<(), ConsensusError>;
    fn validate_header_against_parent(
        &self,
        header: &SealedHeader<H>,
        parent: &SealedHeader<H>,
    ) -> Result<(), ConsensusError>;
    fn validate_header_with_total_difficulty(
        &self,
        header: &H,
        total_difficulty: Uint<256, 4>,
    ) -> Result<(), ConsensusError>;

    // Provided method
    fn validate_header_range(
        &self,
        headers: &[SealedHeader<H>],
    ) -> Result<(), HeaderConsensusError<H>>
       where H: Clone { ... }
}
Expand description

HeaderValidator is a protocol that validates headers and their relationships.

Required Methods§

fn validate_header( &self, header: &SealedHeader<H>, ) -> Result<(), ConsensusError>

Validate if header is correct and follows consensus specification.

This is called on standalone header to check if all hashes are correct.

fn validate_header_against_parent( &self, header: &SealedHeader<H>, parent: &SealedHeader<H>, ) -> Result<(), ConsensusError>

Validate that the header information regarding parent are correct. This checks the block number, timestamp, basefee and gas limit increment.

This is called before properties that are not in the header itself (like total difficulty) have been computed.

This should not be called for the genesis block.

Note: Validating header against its parent does not include other HeaderValidator validations.

fn validate_header_with_total_difficulty( &self, header: &H, total_difficulty: Uint<256, 4>, ) -> Result<(), ConsensusError>

Validate if the header is correct and follows the consensus specification, including computed properties (like total difficulty).

Some consensus engines may want to do additional checks here.

Note: validating headers with TD does not include other HeaderValidator validation.

Provided Methods§

fn validate_header_range( &self, headers: &[SealedHeader<H>], ) -> Result<(), HeaderConsensusError<H>>
where H: Clone,

Validates the given headers

This ensures that the first header is valid on its own and all subsequent headers are valid on its own and valid against its parent.

Note: this expects that the headers are in natural order (ascending block number)

Implementations on Foreign Types§

§

impl<'a, H, T> HeaderValidator<H> for &'a T
where T: 'a + HeaderValidator<H> + ?Sized, &'a T: Debug + Send + Sync,

§

fn validate_header( &self, header: &SealedHeader<H>, ) -> Result<(), ConsensusError>

§

fn validate_header_against_parent( &self, header: &SealedHeader<H>, parent: &SealedHeader<H>, ) -> Result<(), ConsensusError>

§

fn validate_header_range( &self, headers: &[SealedHeader<H>], ) -> Result<(), HeaderConsensusError<H>>
where H: Clone,

§

fn validate_header_with_total_difficulty( &self, header: &H, total_difficulty: Uint<256, 4>, ) -> Result<(), ConsensusError>

§

impl<H, T> HeaderValidator<H> for Arc<T>
where T: HeaderValidator<H> + ?Sized, Arc<T>: Debug + Send + Sync,

§

fn validate_header( &self, header: &SealedHeader<H>, ) -> Result<(), ConsensusError>

§

fn validate_header_against_parent( &self, header: &SealedHeader<H>, parent: &SealedHeader<H>, ) -> Result<(), ConsensusError>

§

fn validate_header_range( &self, headers: &[SealedHeader<H>], ) -> Result<(), HeaderConsensusError<H>>
where H: Clone,

§

fn validate_header_with_total_difficulty( &self, header: &H, total_difficulty: Uint<256, 4>, ) -> Result<(), ConsensusError>

Implementors§

§

impl<H> HeaderValidator<H> for NoopConsensus

§

impl<H> HeaderValidator<H> for TestConsensus

Source§

impl<H, ChainSpec> HeaderValidator<H> for EthBeaconConsensus<ChainSpec>
where ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug, H: BlockHeader,