Skip to content

Commit dcaa06a

Browse files
authored
feat: make more block types generic (paradigmxyz#12812)
1 parent 02824da commit dcaa06a

File tree

62 files changed

+490
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+490
-289
lines changed

bin/reth-bench/src/bench/new_payload_fcu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use clap::Parser;
1818
use csv::Writer;
1919
use reth_cli_runner::CliContext;
2020
use reth_node_core::args::BenchmarkArgs;
21-
use reth_primitives::Block;
21+
use reth_primitives::{Block, BlockExt};
2222
use reth_rpc_types_compat::engine::payload::block_to_payload;
2323
use std::time::Instant;
2424
use tracing::{debug, info};
@@ -75,11 +75,11 @@ impl Command {
7575

7676
while let Some((block, head, safe, finalized)) = receiver.recv().await {
7777
// just put gas used here
78-
let gas_used = block.header.gas_used;
78+
let gas_used = block.gas_used;
7979
let block_number = block.header.number;
8080

8181
let versioned_hashes: Vec<B256> =
82-
block.blob_versioned_hashes().into_iter().copied().collect();
82+
block.body.blob_versioned_hashes().into_iter().copied().collect();
8383
let parent_beacon_block_root = block.parent_beacon_block_root;
8484
let payload = block_to_payload(block);
8585

bin/reth-bench/src/bench/new_payload_only.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use clap::Parser;
1616
use csv::Writer;
1717
use reth_cli_runner::CliContext;
1818
use reth_node_core::args::BenchmarkArgs;
19-
use reth_primitives::Block;
19+
use reth_primitives::{Block, BlockExt};
2020
use reth_rpc_types_compat::engine::payload::block_to_payload;
2121
use std::time::Instant;
2222
use tracing::{debug, info};
@@ -60,10 +60,10 @@ impl Command {
6060

6161
while let Some(block) = receiver.recv().await {
6262
// just put gas used here
63-
let gas_used = block.header.gas_used;
63+
let gas_used = block.gas_used;
6464

6565
let versioned_hashes: Vec<B256> =
66-
block.blob_versioned_hashes().into_iter().copied().collect();
66+
block.body.blob_versioned_hashes().into_iter().copied().collect();
6767
let parent_beacon_block_root = block.parent_beacon_block_root;
6868
let payload = block_to_payload(block);
6969

bin/reth/src/commands/debug_cmd/build_block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use reth_errors::RethResult;
2222
use reth_evm::execute::{BlockExecutorProvider, Executor};
2323
use reth_execution_types::ExecutionOutcome;
2424
use reth_fs_util as fs;
25-
use reth_node_api::{EngineApiMessageVersion, PayloadBuilderAttributes};
25+
use reth_node_api::{BlockTy, EngineApiMessageVersion, PayloadBuilderAttributes};
2626
use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider};
2727
use reth_primitives::{
28-
BlobTransaction, PooledTransactionsElement, SealedBlock, SealedBlockWithSenders, SealedHeader,
29-
Transaction, TransactionSigned,
28+
BlobTransaction, BlockExt, PooledTransactionsElement, SealedBlock, SealedBlockWithSenders,
29+
SealedHeader, Transaction, TransactionSigned,
3030
};
3131
use reth_provider::{
3232
providers::{BlockchainProvider, ProviderNodeTypes},
@@ -259,7 +259,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
259259

260260
let senders = block.senders().expect("sender recovery failed");
261261
let block_with_senders =
262-
SealedBlockWithSenders::new(block.clone(), senders).unwrap();
262+
SealedBlockWithSenders::<BlockTy<N>>::new(block.clone(), senders).unwrap();
263263

264264
let db = StateProviderDatabase::new(blockchain_db.latest()?);
265265
let executor =

bin/reth/src/commands/debug_cmd/in_memory_merkle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use reth_execution_types::ExecutionOutcome;
2020
use reth_network::{BlockDownloaderProvider, NetworkHandle};
2121
use reth_network_api::NetworkInfo;
2222
use reth_node_ethereum::EthExecutorProvider;
23+
use reth_primitives::BlockExt;
2324
use reth_provider::{
2425
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, AccountExtReader,
2526
ChainSpecProvider, HashingWriter, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown,

bin/reth/src/commands/debug_cmd/merkle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
1717
use reth_network::{BlockDownloaderProvider, NetworkHandle};
1818
use reth_network_api::NetworkInfo;
1919
use reth_network_p2p::full_block::FullBlockClient;
20+
use reth_node_api::BlockTy;
2021
use reth_node_ethereum::EthExecutorProvider;
2122
use reth_provider::{
2223
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, BlockNumReader, BlockWriter,
@@ -144,7 +145,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
144145
for block in blocks.into_iter().rev() {
145146
let block_number = block.number;
146147
let sealed_block = block
147-
.try_seal_with_senders()
148+
.try_seal_with_senders::<BlockTy<N>>()
148149
.map_err(|block| eyre::eyre!("Error sealing block with senders: {block:?}"))?;
149150
trace!(target: "reth::cli", block_number, "Executing block");
150151

crates/blockchain-tree/src/blockchain_tree.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,9 @@ mod tests {
15891589
body: Vec<TransactionSignedEcRecovered>,
15901590
num_of_signer_txs: u64|
15911591
-> SealedBlockWithSenders {
1592-
let transactions_root = calculate_transaction_root(&body);
1592+
let signed_body =
1593+
body.clone().into_iter().map(|tx| tx.into_signed()).collect::<Vec<_>>();
1594+
let transactions_root = calculate_transaction_root(&signed_body);
15931595
let receipts = body
15941596
.iter()
15951597
.enumerate()
@@ -1635,7 +1637,7 @@ mod tests {
16351637
SealedBlock {
16361638
header: SealedHeader::seal(header),
16371639
body: BlockBody {
1638-
transactions: body.clone().into_iter().map(|tx| tx.into_signed()).collect(),
1640+
transactions: signed_body,
16391641
ommers: Vec::new(),
16401642
withdrawals: Some(Withdrawals::default()),
16411643
},

crates/blockchain-tree/src/externals.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,40 @@ use reth_consensus::Consensus;
55
use reth_db::{static_file::BlockHashMask, tables};
66
use reth_db_api::{cursor::DbCursorRO, transaction::DbTx};
77
use reth_node_types::{FullNodePrimitives, NodeTypesWithDB};
8-
use reth_primitives::{BlockBody, StaticFileSegment};
8+
use reth_primitives::StaticFileSegment;
99
use reth_provider::{
10-
providers::ProviderNodeTypes, ChainStateBlockReader, ChainStateBlockWriter, ProviderFactory,
11-
StaticFileProviderFactory, StatsReader,
10+
providers::{NodeTypesForProvider, ProviderNodeTypes},
11+
ChainStateBlockReader, ChainStateBlockWriter, ProviderFactory, StaticFileProviderFactory,
12+
StatsReader,
1213
};
1314
use reth_storage_errors::provider::ProviderResult;
1415
use std::{collections::BTreeMap, sync::Arc};
1516

1617
/// A helper trait with requirements for [`ProviderNodeTypes`] to be used within [`TreeExternals`].
17-
pub trait TreeNodeTypes:
18-
ProviderNodeTypes<Primitives: FullNodePrimitives<BlockBody = BlockBody>>
18+
pub trait NodeTypesForTree:
19+
NodeTypesForProvider<
20+
Primitives: FullNodePrimitives<
21+
Block = reth_primitives::Block,
22+
BlockBody = reth_primitives::BlockBody,
23+
>,
24+
>
1925
{
2026
}
21-
impl<T> TreeNodeTypes for T where
22-
T: ProviderNodeTypes<Primitives: FullNodePrimitives<BlockBody = BlockBody>>
27+
28+
impl<T> NodeTypesForTree for T where
29+
T: NodeTypesForProvider<
30+
Primitives: FullNodePrimitives<
31+
Block = reth_primitives::Block,
32+
BlockBody = reth_primitives::BlockBody,
33+
>,
34+
>
2335
{
2436
}
2537

38+
/// A helper trait with requirements for [`ProviderNodeTypes`] to be used within [`TreeExternals`].
39+
pub trait TreeNodeTypes: ProviderNodeTypes + NodeTypesForTree {}
40+
impl<T> TreeNodeTypes for T where T: ProviderNodeTypes + NodeTypesForTree {}
41+
2642
/// A container for external components.
2743
///
2844
/// This is a simple container for external components used throughout the blockchain tree

crates/chain-state/src/test_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ impl TestBlockBuilder {
139139
gas_limit: self.chain_spec.max_gas_limit,
140140
mix_hash: B256::random(),
141141
base_fee_per_gas: Some(INITIAL_BASE_FEE),
142-
transactions_root: calculate_transaction_root(&transactions),
142+
transactions_root: calculate_transaction_root(
143+
&transactions.clone().into_iter().map(|tx| tx.into_signed()).collect::<Vec<_>>(),
144+
),
143145
receipts_root: calculate_receipt_root(&receipts),
144146
beneficiary: Address::random(),
145147
state_root: state_root_unhashed(HashMap::from([(

crates/cli/commands/src/common.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,21 @@ impl AccessRights {
197197
/// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI.
198198
pub trait CliNodeTypes:
199199
NodeTypesWithEngine
200-
+ NodeTypesForProvider<Primitives: FullNodePrimitives<BlockBody = reth_primitives::BlockBody>>
200+
+ NodeTypesForProvider<
201+
Primitives: FullNodePrimitives<
202+
Block = reth_primitives::Block,
203+
BlockBody = reth_primitives::BlockBody,
204+
>,
205+
>
201206
{
202207
}
203208
impl<N> CliNodeTypes for N where
204209
N: NodeTypesWithEngine
205-
+ NodeTypesForProvider<Primitives: FullNodePrimitives<BlockBody = reth_primitives::BlockBody>>
210+
+ NodeTypesForProvider<
211+
Primitives: FullNodePrimitives<
212+
Block = reth_primitives::Block,
213+
BlockBody = reth_primitives::BlockBody,
214+
>,
215+
>
206216
{
207217
}

crates/cli/commands/src/init_state/without_evm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn setup_without_evm<Provider>(
3333
where
3434
Provider: StaticFileProviderFactory
3535
+ StageCheckpointWriter
36-
+ BlockWriter<Body: reth_node_api::BlockBody>,
36+
+ BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>>,
3737
{
3838
info!(target: "reth::cli", "Setting up dummy EVM chain before importing state.");
3939

@@ -64,7 +64,8 @@ fn append_first_block<Provider>(
6464
total_difficulty: U256,
6565
) -> Result<(), eyre::Error>
6666
where
67-
Provider: BlockWriter<Body: reth_node_api::BlockBody> + StaticFileProviderFactory,
67+
Provider: BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>>
68+
+ StaticFileProviderFactory,
6869
{
6970
provider_rw.insert_block(
7071
SealedBlockWithSenders::new(SealedBlock::new(header.clone(), Default::default()), vec![])

0 commit comments

Comments
 (0)