mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: add SealedBlock in reth-primitives-traits (#13735)
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
use alloy_consensus::{BlockHeader, EMPTY_OMMER_ROOT_HASH};
|
||||
use alloy_consensus::EMPTY_OMMER_ROOT_HASH;
|
||||
use alloy_eips::{eip7840::BlobParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS};
|
||||
use alloy_primitives::U256;
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
@ -21,10 +21,10 @@ 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::{BlockWithSenders, NodePrimitives, Receipt, SealedBlock, SealedHeader};
|
||||
use reth_primitives::{NodePrimitives, Receipt, RecoveredBlock, SealedBlock, SealedHeader};
|
||||
use reth_primitives_traits::{
|
||||
constants::{GAS_LIMIT_BOUND_DIVISOR, MINIMUM_GAS_LIMIT},
|
||||
BlockBody,
|
||||
Block, BlockHeader,
|
||||
};
|
||||
use std::{fmt::Debug, sync::Arc, time::SystemTime};
|
||||
|
||||
@ -103,30 +103,29 @@ where
|
||||
{
|
||||
fn validate_block_post_execution(
|
||||
&self,
|
||||
block: &BlockWithSenders<N::Block>,
|
||||
block: &RecoveredBlock<N::Block>,
|
||||
input: PostExecutionInput<'_>,
|
||||
) -> Result<(), ConsensusError> {
|
||||
validate_block_post_execution(block, &self.chain_spec, input.receipts, input.requests)
|
||||
}
|
||||
}
|
||||
|
||||
impl<H, B, ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug> Consensus<H, B>
|
||||
impl<B, ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug> Consensus<B>
|
||||
for EthBeaconConsensus<ChainSpec>
|
||||
where
|
||||
H: BlockHeader,
|
||||
B: BlockBody,
|
||||
B: Block,
|
||||
{
|
||||
type Error = ConsensusError;
|
||||
|
||||
fn validate_body_against_header(
|
||||
&self,
|
||||
body: &B,
|
||||
header: &SealedHeader<H>,
|
||||
body: &B::Body,
|
||||
header: &SealedHeader<B::Header>,
|
||||
) -> Result<(), Self::Error> {
|
||||
validate_body_against_header(body, header.header())
|
||||
}
|
||||
|
||||
fn validate_block_pre_execution(&self, block: &SealedBlock<H, B>) -> Result<(), Self::Error> {
|
||||
fn validate_block_pre_execution(&self, block: &SealedBlock<B>) -> Result<(), Self::Error> {
|
||||
validate_block_pre_execution(block, &self.chain_spec)
|
||||
}
|
||||
}
|
||||
@ -361,7 +360,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
EthBeaconConsensus::new(chain_spec).validate_header(&SealedHeader::seal(header,)),
|
||||
EthBeaconConsensus::new(chain_spec).validate_header(&SealedHeader::seal_slow(header,)),
|
||||
Ok(())
|
||||
);
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ 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, BlockWithSenders, GotExpected, Receipt};
|
||||
use reth_primitives::{gas_spent_by_transactions, GotExpected, Receipt, RecoveredBlock};
|
||||
use reth_primitives_traits::Block;
|
||||
|
||||
/// Validate a block with regard to execution results:
|
||||
@ -11,7 +11,7 @@ use reth_primitives_traits::Block;
|
||||
/// - 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>(
|
||||
block: &BlockWithSenders<B>,
|
||||
block: &RecoveredBlock<B>,
|
||||
chain_spec: &ChainSpec,
|
||||
receipts: &[Receipt],
|
||||
requests: &Requests,
|
||||
|
||||
@ -22,7 +22,7 @@ use reth_payload_primitives::{
|
||||
PayloadOrAttributes, PayloadTypes,
|
||||
};
|
||||
use reth_payload_validator::ExecutionPayloadValidator;
|
||||
use reth_primitives::{Block, NodePrimitives, SealedBlock, SealedBlockFor};
|
||||
use reth_primitives::{Block, NodePrimitives, SealedBlock};
|
||||
use reth_rpc_types_compat::engine::payload::block_to_payload;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -54,7 +54,7 @@ where
|
||||
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
|
||||
|
||||
fn block_to_payload(
|
||||
block: SealedBlockFor<
|
||||
block: SealedBlock<
|
||||
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
|
||||
>,
|
||||
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
|
||||
|
||||
@ -5,7 +5,7 @@ use crate::{
|
||||
EthEvmConfig,
|
||||
};
|
||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
use alloy_consensus::Transaction;
|
||||
use alloy_consensus::{BlockHeader, Transaction};
|
||||
use alloy_eips::{eip6110, eip7685::Requests};
|
||||
use core::fmt::Display;
|
||||
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
|
||||
@ -21,7 +21,8 @@ use reth_evm::{
|
||||
system_calls::{OnStateHook, SystemCaller},
|
||||
ConfigureEvm, TxEnvOverrides,
|
||||
};
|
||||
use reth_primitives::{BlockWithSenders, EthPrimitives, Receipt};
|
||||
use reth_primitives::{EthPrimitives, Receipt, RecoveredBlock};
|
||||
use reth_primitives_traits::BlockBody;
|
||||
use reth_revm::db::State;
|
||||
use revm_primitives::{
|
||||
db::{Database, DatabaseCommit},
|
||||
@ -129,31 +130,34 @@ where
|
||||
self.tx_env_overrides = Some(tx_env_overrides);
|
||||
}
|
||||
|
||||
fn apply_pre_execution_changes(&mut self, block: &BlockWithSenders) -> Result<(), Self::Error> {
|
||||
fn apply_pre_execution_changes(
|
||||
&mut self,
|
||||
block: &RecoveredBlock<reth_primitives::Block>,
|
||||
) -> Result<(), Self::Error> {
|
||||
// Set state clear flag if the block is after the Spurious Dragon hardfork.
|
||||
let state_clear_flag =
|
||||
(*self.chain_spec).is_spurious_dragon_active_at_block(block.header.number);
|
||||
(*self.chain_spec).is_spurious_dragon_active_at_block(block.number());
|
||||
self.state.set_state_clear_flag(state_clear_flag);
|
||||
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, &block.header);
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header());
|
||||
|
||||
self.system_caller.apply_pre_execution_changes(&block.header, &mut evm)?;
|
||||
self.system_caller.apply_pre_execution_changes(block.header(), &mut evm)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn execute_transactions(
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
block: &RecoveredBlock<reth_primitives::Block>,
|
||||
) -> Result<ExecuteOutput<Receipt>, Self::Error> {
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, &block.header);
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header());
|
||||
|
||||
let mut cumulative_gas_used = 0;
|
||||
let mut receipts = Vec::with_capacity(block.body.transactions.len());
|
||||
let mut receipts = Vec::with_capacity(block.body().transaction_count());
|
||||
for (sender, transaction) in block.transactions_with_sender() {
|
||||
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
|
||||
// must be no greater than the block’s gasLimit.
|
||||
let block_available_gas = block.header.gas_limit - cumulative_gas_used;
|
||||
let block_available_gas = block.gas_limit() - cumulative_gas_used;
|
||||
if transaction.gas_limit() > block_available_gas {
|
||||
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||
transaction_gas_limit: transaction.gas_limit(),
|
||||
@ -204,10 +208,10 @@ where
|
||||
|
||||
fn apply_post_execution_changes(
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
block: &RecoveredBlock<reth_primitives::Block>,
|
||||
receipts: &[Receipt],
|
||||
) -> Result<Requests, Self::Error> {
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, &block.header);
|
||||
let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header());
|
||||
|
||||
let requests = if self.chain_spec.is_prague_active_at_timestamp(block.timestamp) {
|
||||
// Collect all EIP-6110 deposits
|
||||
@ -227,10 +231,10 @@ where
|
||||
};
|
||||
drop(evm);
|
||||
|
||||
let mut balance_increments = post_block_balance_increments(&self.chain_spec, &block.block);
|
||||
let mut balance_increments = post_block_balance_increments(&self.chain_spec, block);
|
||||
|
||||
// Irregular state change at Ethereum DAO hardfork
|
||||
if self.chain_spec.fork(EthereumHardfork::Dao).transitions_at_block(block.number) {
|
||||
if self.chain_spec.fork(EthereumHardfork::Dao).transitions_at_block(block.number()) {
|
||||
// drain balances from hardcoded addresses.
|
||||
let drained_balance: u128 = self
|
||||
.state
|
||||
@ -267,7 +271,7 @@ where
|
||||
|
||||
fn validate_block_post_execution(
|
||||
&self,
|
||||
block: &BlockWithSenders,
|
||||
block: &RecoveredBlock<reth_primitives::Block>,
|
||||
receipts: &[Receipt],
|
||||
requests: &Requests,
|
||||
) -> Result<(), ConsensusError> {
|
||||
@ -311,8 +315,8 @@ mod tests {
|
||||
BasicBlockExecutorProvider, BatchExecutor, BlockExecutorProvider, Executor,
|
||||
};
|
||||
use reth_execution_types::BlockExecutionOutput;
|
||||
use reth_primitives::{Account, Block, BlockBody, BlockExt, Transaction};
|
||||
use reth_primitives_traits::crypto::secp256k1::public_key_to_address;
|
||||
use reth_primitives::{Account, Block, BlockBody, Transaction};
|
||||
use reth_primitives_traits::{crypto::secp256k1::public_key_to_address, Block as _};
|
||||
use reth_revm::{
|
||||
database::StateProviderDatabase, test_utils::StateProviderTest, TransitionState,
|
||||
};
|
||||
@ -388,7 +392,7 @@ mod tests {
|
||||
|
||||
// attempt to execute a block without parent beacon block root, expect err
|
||||
let err = executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block {
|
||||
header: header.clone(),
|
||||
body: BlockBody { transactions: vec![], ommers: vec![], withdrawals: None },
|
||||
@ -409,7 +413,7 @@ mod tests {
|
||||
|
||||
// Now execute a block with the fixed header, ensure that it does not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block {
|
||||
header: header.clone(),
|
||||
body: BlockBody { transactions: vec![], ommers: vec![], withdrawals: None },
|
||||
@ -469,7 +473,7 @@ mod tests {
|
||||
// attempt to execute an empty block with parent beacon block root, this should not fail
|
||||
provider
|
||||
.batch_executor(StateProviderDatabase::new(&db))
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block {
|
||||
header,
|
||||
body: BlockBody { transactions: vec![], ommers: vec![], withdrawals: None },
|
||||
@ -513,7 +517,7 @@ mod tests {
|
||||
|
||||
// attempt to execute an empty block with parent beacon block root, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block {
|
||||
header,
|
||||
body: BlockBody { transactions: vec![], ommers: vec![], withdrawals: None },
|
||||
@ -549,7 +553,7 @@ mod tests {
|
||||
// attempt to execute the genesis block with non-zero parent beacon block root, expect err
|
||||
header.parent_beacon_block_root = Some(B256::with_last_byte(0x69));
|
||||
let _err = executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header: header.clone(), body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -564,7 +568,7 @@ mod tests {
|
||||
// now try to process the genesis block again, this time ensuring that a system contract
|
||||
// call does not occur
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -612,7 +616,7 @@ mod tests {
|
||||
|
||||
// Now execute a block with the fixed header, ensure that it does not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header: header.clone(), body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -682,7 +686,7 @@ mod tests {
|
||||
|
||||
// attempt to execute an empty block, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -719,7 +723,7 @@ mod tests {
|
||||
|
||||
// attempt to execute genesis block, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -763,7 +767,7 @@ mod tests {
|
||||
|
||||
// attempt to execute the fork activation block, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -814,7 +818,7 @@ mod tests {
|
||||
|
||||
// attempt to execute the fork activation block, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -847,7 +851,7 @@ mod tests {
|
||||
|
||||
// attempt to execute the genesis block, this should not fail
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -876,7 +880,7 @@ mod tests {
|
||||
let header_hash = header.hash_slow();
|
||||
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -908,7 +912,7 @@ mod tests {
|
||||
};
|
||||
|
||||
executor
|
||||
.execute_and_verify_one(&BlockWithSenders::new_unchecked(
|
||||
.execute_and_verify_one(&RecoveredBlock::new_unhashed(
|
||||
Block { header, body: Default::default() },
|
||||
vec![],
|
||||
))
|
||||
@ -1111,7 +1115,7 @@ mod tests {
|
||||
|
||||
let header = Header { timestamp: 1, number: 1, ..Header::default() };
|
||||
|
||||
let block = &BlockWithSenders::new_unchecked(
|
||||
let block = &RecoveredBlock::new_unhashed(
|
||||
Block {
|
||||
header,
|
||||
body: BlockBody {
|
||||
|
||||
@ -3,7 +3,7 @@ use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{b256, hex};
|
||||
use futures::StreamExt;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_node_api::{FullNodeComponents, FullNodePrimitives, NodeTypes};
|
||||
use reth_node_api::{BlockBody, FullNodeComponents, FullNodePrimitives, NodeTypes};
|
||||
use reth_node_builder::{
|
||||
rpc::RethRpcAddOns, EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle,
|
||||
};
|
||||
@ -65,7 +65,7 @@ where
|
||||
|
||||
let head = notifications.next().await.unwrap();
|
||||
|
||||
let tx = &head.tip().transactions()[0];
|
||||
let tx = &head.tip().body().transactions()[0];
|
||||
assert_eq!(tx.trie_hash(), hash);
|
||||
println!("mined transaction: {hash}");
|
||||
}
|
||||
|
||||
@ -30,10 +30,11 @@ use reth_payload_builder_primitives::PayloadBuilderError;
|
||||
use reth_payload_primitives::PayloadBuilderAttributes;
|
||||
use reth_primitives::{
|
||||
proofs::{self},
|
||||
Block, BlockBody, BlockExt, EthereumHardforks, InvalidTransactionError, Receipt,
|
||||
TransactionSigned,
|
||||
Block, BlockBody, EthereumHardforks, InvalidTransactionError, Receipt, TransactionSigned,
|
||||
};
|
||||
use reth_primitives_traits::Block as _;
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_storage_api::StateProviderFactory;
|
||||
use reth_transaction_pool::{
|
||||
error::InvalidPoolTransactionError, noop::NoopTransactionPool, BestTransactions,
|
||||
BestTransactionsAttributes, PoolTransaction, TransactionPool, ValidPoolTransaction,
|
||||
@ -51,7 +52,6 @@ use tracing::{debug, trace, warn};
|
||||
|
||||
mod config;
|
||||
pub use config::*;
|
||||
use reth_storage_api::StateProviderFactory;
|
||||
|
||||
type BestTransactionsIter<Pool> = Box<
|
||||
dyn BestTransactions<Item = Arc<ValidPoolTransaction<<Pool as TransactionPool>::Transaction>>>,
|
||||
|
||||
Reference in New Issue
Block a user