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

@ -1,6 +1,6 @@
use crate::BeaconSidecarConfig;
use alloy_consensus::{
transaction::PooledTransaction, Signed, Transaction as _, TxEip4844WithSidecar,
transaction::PooledTransaction, BlockHeader, Signed, Transaction as _, TxEip4844WithSidecar,
};
use alloy_primitives::B256;
use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, SidecarIterator};
@ -8,7 +8,7 @@ use eyre::Result;
use futures_util::{stream::FuturesUnordered, Future, Stream, StreamExt};
use reqwest::{Error, StatusCode};
use reth::{
primitives::SealedBlockWithSenders,
primitives::RecoveredBlock,
providers::CanonStateNotification,
transaction_pool::{BlobStoreError, TransactionPoolExt},
};
@ -97,10 +97,10 @@ where
St: Stream<Item = CanonStateNotification> + Send + Unpin + 'static,
P: TransactionPoolExt + Unpin + 'static,
{
fn process_block(&mut self, block: &SealedBlockWithSenders) {
fn process_block(&mut self, block: &RecoveredBlock<reth::primitives::Block>) {
let txs: Vec<_> = block
.body()
.transactions()
.iter()
.filter(|tx| tx.is_eip4844())
.map(|tx| (tx.clone(), tx.blob_versioned_hashes().unwrap().len()))
.collect();
@ -195,17 +195,15 @@ where
// handle reorged blocks
for (_, block) in old.blocks().iter() {
let txs: Vec<BlobTransactionEvent> = block
.body()
.transactions()
.iter()
.filter(|tx: &&reth::primitives::TransactionSigned| {
tx.is_eip4844()
})
.filter(|tx| tx.is_eip4844())
.map(|tx| {
let transaction_hash = tx.hash();
let block_metadata = BlockMetadata {
block_hash: new.tip().block.hash(),
block_number: new.tip().block.number,
gas_used: new.tip().block.gas_used,
block_hash: new.tip().hash(),
block_number: new.tip().number(),
gas_used: new.tip().gas_used(),
};
BlobTransactionEvent::Reorged(ReorgedBlob {
transaction_hash,
@ -231,7 +229,7 @@ where
async fn fetch_blobs_for_block(
client: reqwest::Client,
url: String,
block: SealedBlockWithSenders,
block: RecoveredBlock<reth::primitives::Block>,
txs: Vec<(reth::primitives::TransactionSigned, usize)>,
) -> Result<Vec<BlobTransactionEvent>, SideCarError> {
let response = match client.get(url).header("Accept", "application/json").send().await {

View File

@ -3,6 +3,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
use alloy_consensus::BlockHeader;
use alloy_eips::{eip4895::Withdrawal, eip7685::Requests};
use alloy_sol_macro::sol;
use alloy_sol_types::SolCall;
@ -26,7 +27,7 @@ use reth_evm::execute::{
};
use reth_evm_ethereum::EthEvmConfig;
use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode};
use reth_primitives::{BlockWithSenders, EthPrimitives, Receipt};
use reth_primitives::{EthPrimitives, Receipt, RecoveredBlock};
use std::{fmt::Display, sync::Arc};
pub const SYSTEM_ADDRESS: Address = address!("fffffffffffffffffffffffffffffffffffffffe");
@ -125,10 +126,13 @@ where
type Primitives = EthPrimitives;
type Error = BlockExecutionError;
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);
Ok(())
@ -136,19 +140,19 @@ where
fn execute_transactions(
&mut self,
_block: &BlockWithSenders,
_block: &RecoveredBlock<reth_primitives::Block>,
) -> Result<ExecuteOutput<Receipt>, Self::Error> {
Ok(ExecuteOutput { receipts: vec![], gas_used: 0 })
}
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());
if let Some(withdrawals) = block.body.withdrawals.as_ref() {
if let Some(withdrawals) = block.body().withdrawals.as_ref() {
apply_withdrawals_contract_call(withdrawals, &mut evm)?;
}

View File

@ -50,7 +50,7 @@ async fn main() -> eyre::Result<()> {
let head = notifications.next().await.unwrap();
let tx = &head.tip().transactions()[0];
let tx = &head.tip().body().transactions().next().unwrap();
assert_eq!(tx.hash(), hash);
println!("mined transaction: {hash}");
Ok(())

View File

@ -38,7 +38,7 @@ use reth::{
},
network::NetworkHandle,
payload::ExecutionPayloadValidator,
primitives::{Block, EthPrimitives, SealedBlockFor, TransactionSigned},
primitives::{Block, EthPrimitives, SealedBlock, TransactionSigned},
providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory},
rpc::{
compat::engine::payload::block_to_payload,
@ -177,7 +177,7 @@ impl EngineTypes for CustomEngineTypes {
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
fn block_to_payload(
block: SealedBlockFor<
block: SealedBlock<
<<Self::BuiltPayload as reth_node_api::BuiltPayload>::Primitives as reth_node_api::NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
@ -211,7 +211,7 @@ impl PayloadValidator for CustomEngineValidator {
&self,
payload: ExecutionPayload,
sidecar: ExecutionPayloadSidecar,
) -> Result<SealedBlockFor<Self::Block>, PayloadError> {
) -> Result<SealedBlock<Self::Block>, PayloadError> {
self.inner.ensure_well_formed_payload(payload, sidecar)
}
}

View File

@ -1,6 +1,7 @@
use crate::job::EmptyBlockPayloadJob;
use alloy_eips::BlockNumberOrTag;
use reth::{
api::Block,
providers::{BlockReaderIdExt, BlockSource, StateProviderFactory},
tasks::TaskSpawner,
transaction_pool::TransactionPool,
@ -8,7 +9,7 @@ use reth::{
use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadBuilder, PayloadConfig};
use reth_node_api::PayloadBuilderAttributes;
use reth_payload_builder::{PayloadBuilderError, PayloadJobGenerator};
use reth_primitives::{BlockExt, SealedHeader};
use reth_primitives::SealedHeader;
use std::sync::Arc;
/// The generator type that creates new jobs that builds empty blocks.

View File

@ -5,7 +5,7 @@ use reth_chainspec::ChainSpecBuilder;
use reth_db::{open_db_read_only, DatabaseEnv};
use reth_node_ethereum::EthereumNode;
use reth_node_types::NodeTypesWithDBAdapter;
use reth_primitives::{BlockExt, SealedHeader, TransactionSigned};
use reth_primitives::{SealedBlock, SealedHeader, TransactionSigned};
use reth_provider::{
providers::StaticFileProvider, AccountReader, BlockReader, BlockSource, HeaderProvider,
ProviderFactory, ReceiptProvider, StateProvider, TransactionsProvider,
@ -64,7 +64,7 @@ fn header_provider_example<T: HeaderProvider>(provider: T, number: u64) -> eyre:
// We can convert a header to a sealed header which contains the hash w/o needing to re-compute
// it every time.
let sealed_header = SealedHeader::seal(header);
let sealed_header = SealedHeader::seal_slow(header);
// Can also query the header by hash!
let header_by_hash =
@ -134,7 +134,7 @@ fn block_provider_example<T: BlockReader<Block = reth_primitives::Block>>(
let block = provider.block(number.into())?.ok_or(eyre::eyre!("block num not found"))?;
// Can seal the block to cache the hash, like the Header above.
let sealed_block = block.clone().seal_slow();
let sealed_block = SealedBlock::seal_slow(block.clone());
// Can also query the block by hash directly
let block_by_hash = provider