feat: consensus trait generic over NodePrimitives (#13026)

This commit is contained in:
Arsenii Kulikov
2024-11-30 02:26:36 +04:00
committed by GitHub
parent 55ddaab1e4
commit 5d71150355
26 changed files with 166 additions and 113 deletions

View File

@ -11,14 +11,18 @@
use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
use alloy_primitives::U256;
use reth_chainspec::{EthChainSpec, EthereumHardfork, EthereumHardforks};
use reth_consensus::{Consensus, ConsensusError, HeaderValidator, PostExecutionInput};
use reth_consensus::{
Consensus, ConsensusError, FullConsensus, HeaderValidator, PostExecutionInput,
};
use reth_consensus_common::validation::{
validate_4844_header_standalone, validate_against_parent_4844,
validate_against_parent_eip1559_base_fee, validate_against_parent_hash_number,
validate_against_parent_timestamp, validate_block_pre_execution, validate_body_against_header,
validate_header_base_fee, validate_header_extradata, validate_header_gas,
};
use reth_primitives::{BlockBody, BlockWithSenders, SealedBlock, SealedHeader};
use reth_primitives::{
Block, BlockBody, BlockWithSenders, NodePrimitives, Receipt, SealedBlock, SealedHeader,
};
use reth_primitives_traits::constants::MINIMUM_GAS_LIMIT;
use std::{fmt::Debug, sync::Arc, time::SystemTime};
@ -90,6 +94,25 @@ impl<ChainSpec: EthChainSpec + EthereumHardforks> EthBeaconConsensus<ChainSpec>
}
}
impl<ChainSpec, N> FullConsensus<N> for EthBeaconConsensus<ChainSpec>
where
ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug,
N: NodePrimitives<
BlockHeader = Header,
BlockBody = BlockBody,
Block = Block,
Receipt = Receipt,
>,
{
fn validate_block_post_execution(
&self,
block: &BlockWithSenders,
input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError> {
validate_block_post_execution(block, &self.chain_spec, input.receipts, input.requests)
}
}
impl<ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug> Consensus
for EthBeaconConsensus<ChainSpec>
{
@ -104,14 +127,6 @@ impl<ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug> Consensu
fn validate_block_pre_execution(&self, block: &SealedBlock) -> Result<(), ConsensusError> {
validate_block_pre_execution(block, &self.chain_spec)
}
fn validate_block_post_execution(
&self,
block: &BlockWithSenders,
input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError> {
validate_block_post_execution(block, &self.chain_spec, input.receipts, input.requests)
}
}
impl<ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug> HeaderValidator