feat: add SealedBlock in reth-primitives-traits (#13735)

This commit is contained in:
Matthias Seitz
2025-01-15 02:12:43 +01:00
committed by GitHub
parent 1267718c7e
commit 83b2fb9b41
171 changed files with 3231 additions and 2866 deletions

View File

@ -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 transactions gas limit, Tg, and the gas utilized in this block prior,
// must be no greater than the blocks 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 {