reth::consensus

Trait Consensus

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: Uint<256, 4>,
    ) -> 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§

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.

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.

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

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

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§

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§

§

impl Consensus for OptimismBeaconConsensus

§

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

source§

impl<ChainSpec> Consensus for AutoSealConsensus<ChainSpec>
where ChainSpec: Send + Sync + Debug,

§

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

Implementors§

§

impl Consensus for NoopConsensus

§

impl Consensus for TestConsensus

§

impl<ChainSpec> Consensus for EthBeaconConsensus<ChainSpec>
where ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug,