reth_consensus

Trait Consensus

source
pub trait Consensus:
    Debug
    + Send
    + Sync {
    // Required methods
    fn validate_header(
        &self,
        header: &SealedHeader,
    ) -> Result<(), ConsensusError>;
    fn validate_header_against_parent(
        &self,
        header: &SealedHeader,
        parent: &SealedHeader,
    ) -> Result<(), ConsensusError>;
    fn validate_header_with_total_difficulty(
        &self,
        header: &Header,
        total_difficulty: U256,
    ) -> Result<(), ConsensusError>;
    fn validate_block_pre_execution(
        &self,
        block: &SealedBlock,
    ) -> Result<(), ConsensusError>;
    fn validate_block_post_execution(
        &self,
        block: &BlockWithSenders,
        input: PostExecutionInput<'_>,
    ) -> Result<(), ConsensusError>;

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

Consensus is a protocol that chooses canonical chain.

Required Methods§

source

fn validate_header(&self, header: &SealedHeader) -> 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, parent: &SealedHeader, ) -> 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 Consensus validations.

source

fn validate_header_with_total_difficulty( &self, header: &Header, 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 Consensus validation.

source

fn validate_block_pre_execution( &self, block: &SealedBlock, ) -> Result<(), ConsensusError>

Validate a block disregarding world state, i.e. things that can be checked before sender recovery and execution.

See the Yellow Paper sections 4.3.2 “Holistic Validity”, 4.3.4 “Block Header Validity”, and 11.1 “Ommer Validation”.

This should not be called for the genesis block.

Note: validating blocks does not include other validations of the Consensus

source

fn validate_block_post_execution( &self, block: &BlockWithSenders, input: PostExecutionInput<'_>, ) -> Result<(), ConsensusError>

Validate a block considering world state, i.e. things that can not be checked before execution.

See the Yellow Paper sections 4.3.2 “Holistic Validity”.

Note: validating blocks does not include other validations of the Consensus

Provided Methods§

source

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

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, T: 'a + Consensus + ?Sized> Consensus for &'a T
where &'a T: Debug + Send + Sync,

source§

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

source§

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

source§

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

source§

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

source§

fn validate_block_pre_execution( &self, block: &SealedBlock, ) -> Result<(), ConsensusError>

source§

fn validate_block_post_execution( &self, block: &BlockWithSenders, input: PostExecutionInput<'_>, ) -> Result<(), ConsensusError>

source§

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

source§

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

source§

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

source§

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

source§

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

source§

fn validate_block_pre_execution( &self, block: &SealedBlock, ) -> Result<(), ConsensusError>

source§

fn validate_block_post_execution( &self, block: &BlockWithSenders, input: PostExecutionInput<'_>, ) -> Result<(), ConsensusError>

Implementors§

source§

impl Consensus for NoopConsensus

source§

impl Consensus for TestConsensus

Available on crate feature test-utils only.