reth_consensus

Trait HeaderValidator

Source
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: U256,
    ) -> 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§

Source

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.

Source

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.

Source

fn validate_header_with_total_difficulty( &self, header: &H, total_difficulty: U256, ) -> 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§

Source

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§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl<H> HeaderValidator<H> for NoopConsensus

Source§

impl<H> HeaderValidator<H> for TestConsensus

Available on crate feature test-utils only.