mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add Consensus to ExecutionStage (#14447)
This commit is contained in:
@ -21,7 +21,7 @@ use reth_consensus_common::validation::{
|
||||
validate_against_parent_timestamp, validate_block_pre_execution, validate_body_against_header,
|
||||
validate_header_base_fee, validate_header_extra_data, validate_header_gas,
|
||||
};
|
||||
use reth_primitives::{NodePrimitives, Receipt, RecoveredBlock, SealedBlock, SealedHeader};
|
||||
use reth_primitives::{NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
|
||||
use reth_primitives_traits::{
|
||||
constants::{GAS_LIMIT_BOUND_DIVISOR, MINIMUM_GAS_LIMIT},
|
||||
Block, BlockHeader,
|
||||
@ -99,7 +99,7 @@ impl<ChainSpec: EthChainSpec + EthereumHardforks> EthBeaconConsensus<ChainSpec>
|
||||
impl<ChainSpec, N> FullConsensus<N> for EthBeaconConsensus<ChainSpec>
|
||||
where
|
||||
ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug,
|
||||
N: NodePrimitives<Receipt = Receipt>,
|
||||
N: NodePrimitives,
|
||||
{
|
||||
fn validate_block_post_execution(
|
||||
&self,
|
||||
|
||||
@ -3,26 +3,27 @@ use alloy_eips::eip7685::Requests;
|
||||
use alloy_primitives::{Bloom, B256};
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_consensus::ConsensusError;
|
||||
use reth_primitives::{gas_spent_by_transactions, GotExpected, Receipt, RecoveredBlock};
|
||||
use reth_primitives_traits::Block;
|
||||
use reth_primitives::{gas_spent_by_transactions, GotExpected, RecoveredBlock};
|
||||
use reth_primitives_traits::{Block, Receipt};
|
||||
|
||||
/// Validate a block with regard to execution results:
|
||||
///
|
||||
/// - Compares the receipts root in the block header to the block body
|
||||
/// - Compares the gas used in the block header to the actual gas usage after execution
|
||||
pub fn validate_block_post_execution<B, ChainSpec>(
|
||||
pub fn validate_block_post_execution<B, R, ChainSpec>(
|
||||
block: &RecoveredBlock<B>,
|
||||
chain_spec: &ChainSpec,
|
||||
receipts: &[Receipt],
|
||||
receipts: &[R],
|
||||
requests: &Requests,
|
||||
) -> Result<(), ConsensusError>
|
||||
where
|
||||
B: Block,
|
||||
R: Receipt,
|
||||
ChainSpec: EthereumHardforks,
|
||||
{
|
||||
// Check if gas used matches the value set in header.
|
||||
let cumulative_gas_used =
|
||||
receipts.last().map(|receipt| receipt.cumulative_gas_used).unwrap_or(0);
|
||||
receipts.last().map(|receipt| receipt.cumulative_gas_used()).unwrap_or(0);
|
||||
if block.header().gas_used() != cumulative_gas_used {
|
||||
return Err(ConsensusError::BlockGasUsed {
|
||||
gas: GotExpected { got: cumulative_gas_used, expected: block.header().gas_used() },
|
||||
@ -61,13 +62,13 @@ where
|
||||
|
||||
/// Calculate the receipts root, and compare it against against the expected receipts root and logs
|
||||
/// bloom.
|
||||
fn verify_receipts(
|
||||
fn verify_receipts<R: Receipt>(
|
||||
expected_receipts_root: B256,
|
||||
expected_logs_bloom: Bloom,
|
||||
receipts: &[Receipt],
|
||||
receipts: &[R],
|
||||
) -> Result<(), ConsensusError> {
|
||||
// Calculate receipts root.
|
||||
let receipts_with_bloom = receipts.iter().map(Receipt::with_bloom_ref).collect::<Vec<_>>();
|
||||
let receipts_with_bloom = receipts.iter().map(TxReceipt::with_bloom_ref).collect::<Vec<_>>();
|
||||
let receipts_root = calculate_receipt_root(&receipts_with_bloom);
|
||||
|
||||
// Calculate header logs bloom.
|
||||
@ -109,6 +110,7 @@ fn compare_receipts_root_and_logs_bloom(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloy_primitives::hex;
|
||||
use reth_primitives::Receipt;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user