Trait Consensus
pub trait Consensus<H = Header, B = BlockBody>:
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>;
fn validate_body_against_header(
&self,
body: &B,
header: &SealedHeader<H>,
) -> Result<(), ConsensusError>;
fn validate_block_pre_execution(
&self,
block: &SealedBlock<H, B>,
) -> Result<(), ConsensusError>;
fn validate_block_post_execution(
&self,
block: &BlockWithSenders,
input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError>;
// Provided method
fn validate_header_range(
&self,
headers: &[SealedHeader<H>],
) -> Result<(), HeaderConsensusError<H>>
where H: Clone { ... }
}
Expand description
Consensus is a protocol that chooses canonical chain.
Required Methods§
fn validate_header(
&self,
header: &SealedHeader<H>,
) -> Result<(), ConsensusError>
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>
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 Consensus validations.
fn validate_header_with_total_difficulty(
&self,
header: &H,
total_difficulty: Uint<256, 4>,
) -> Result<(), ConsensusError>
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 Consensus validation.
fn validate_body_against_header(
&self,
body: &B,
header: &SealedHeader<H>,
) -> Result<(), ConsensusError>
fn validate_body_against_header( &self, body: &B, header: &SealedHeader<H>, ) -> Result<(), ConsensusError>
Ensures that body field values match the header.
fn validate_block_pre_execution(
&self,
block: &SealedBlock<H, B>,
) -> Result<(), ConsensusError>
fn validate_block_pre_execution( &self, block: &SealedBlock<H, B>, ) -> 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>
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<H>],
) -> Result<(), HeaderConsensusError<H>>where
H: Clone,
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)