diff --git a/Cargo.lock b/Cargo.lock index eabde10a0..e4a6687de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6456,6 +6456,7 @@ dependencies = [ "reth-blockchain-tree", "reth-blockchain-tree-api", "reth-chainspec", + "reth-codecs", "reth-config", "reth-consensus", "reth-db", @@ -9159,8 +9160,10 @@ dependencies = [ "assert_matches", "parking_lot", "rayon", + "reth-codecs", "reth-db", "reth-db-api", + "reth-primitives-traits", "reth-provider", "reth-prune-types", "reth-stages", diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 67b200e64..d2ff0f5c8 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1424,7 +1424,7 @@ mod tests { } fn setup_genesis< - N: ProviderNodeTypes>, + N: ProviderNodeTypes>, >( factory: &ProviderFactory, mut genesis: SealedBlock, diff --git a/crates/blockchain-tree/src/externals.rs b/crates/blockchain-tree/src/externals.rs index 76b658248..bf5a243a5 100644 --- a/crates/blockchain-tree/src/externals.rs +++ b/crates/blockchain-tree/src/externals.rs @@ -4,7 +4,7 @@ use alloy_primitives::{BlockHash, BlockNumber}; use reth_consensus::Consensus; use reth_db::{static_file::HeaderMask, tables}; use reth_db_api::{cursor::DbCursorRO, transaction::DbTx}; -use reth_node_types::{Block, FullNodePrimitives, NodeTypesWithDB}; +use reth_node_types::{FullNodePrimitives, NodeTypesWithDB}; use reth_primitives::{BlockBody, StaticFileSegment}; use reth_provider::{ providers::ProviderNodeTypes, ChainStateBlockReader, ChainStateBlockWriter, ProviderFactory, @@ -15,11 +15,11 @@ use std::{collections::BTreeMap, sync::Arc}; /// A helper trait with requirements for [`ProviderNodeTypes`] to be used within [`TreeExternals`]. pub trait TreeNodeTypes: - ProviderNodeTypes>> + ProviderNodeTypes> { } impl TreeNodeTypes for T where - T: ProviderNodeTypes>> + T: ProviderNodeTypes> { } diff --git a/crates/cli/commands/src/common.rs b/crates/cli/commands/src/common.rs index e557f15da..251e01a10 100644 --- a/crates/cli/commands/src/common.rs +++ b/crates/cli/commands/src/common.rs @@ -197,19 +197,11 @@ impl AccessRights { /// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI. pub trait CliNodeTypes: NodeTypesWithEngine - + NodeTypesForProvider< - Primitives: FullNodePrimitives< - Block: reth_node_api::Block, - >, - > + + NodeTypesForProvider> { } impl CliNodeTypes for N where N: NodeTypesWithEngine - + NodeTypesForProvider< - Primitives: FullNodePrimitives< - Block: reth_node_api::Block, - >, - > + + NodeTypesForProvider> { } diff --git a/crates/consensus/beacon/Cargo.toml b/crates/consensus/beacon/Cargo.toml index 245ebe854..65994557c 100644 --- a/crates/consensus/beacon/Cargo.toml +++ b/crates/consensus/beacon/Cargo.toml @@ -14,6 +14,8 @@ workspace = true # reth reth-ethereum-consensus.workspace = true reth-blockchain-tree-api.workspace = true +reth-codecs.workspace = true +reth-db-api.workspace = true reth-primitives.workspace = true reth-stages-api.workspace = true reth-errors.workspace = true @@ -80,6 +82,7 @@ assert_matches.workspace = true [features] optimism = [ "reth-blockchain-tree/optimism", + "reth-codecs/optimism", "reth-chainspec", "reth-db-api/optimism", "reth-db/optimism", diff --git a/crates/consensus/beacon/src/engine/hooks/static_file.rs b/crates/consensus/beacon/src/engine/hooks/static_file.rs index 99854209c..7cd286f65 100644 --- a/crates/consensus/beacon/src/engine/hooks/static_file.rs +++ b/crates/consensus/beacon/src/engine/hooks/static_file.rs @@ -6,8 +6,10 @@ use crate::{ }; use alloy_primitives::BlockNumber; use futures::FutureExt; +use reth_codecs::Compact; +use reth_db_api::table::Value; use reth_errors::RethResult; -use reth_primitives::static_file::HighestStaticFiles; +use reth_primitives::{static_file::HighestStaticFiles, NodePrimitives}; use reth_provider::{ BlockReader, ChainStateBlockReader, DatabaseProviderFactory, StageCheckpointReader, StaticFileProviderFactory, @@ -33,8 +35,9 @@ impl StaticFileHook where Provider: StaticFileProviderFactory + DatabaseProviderFactory< - Provider: StaticFileProviderFactory - + StageCheckpointReader + Provider: StaticFileProviderFactory< + Primitives: NodePrimitives, + > + StageCheckpointReader + BlockReader + ChainStateBlockReader, > + 'static, @@ -148,8 +151,9 @@ impl EngineHook for StaticFileHook where Provider: StaticFileProviderFactory + DatabaseProviderFactory< - Provider: StaticFileProviderFactory - + StageCheckpointReader + Provider: StaticFileProviderFactory< + Primitives: NodePrimitives, + > + StageCheckpointReader + BlockReader + ChainStateBlockReader, > + 'static, diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 2ad06e68b..0fedbdd45 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -2172,7 +2172,7 @@ mod tests { fn insert_blocks< 'a, - N: ProviderNodeTypes>, + N: ProviderNodeTypes>, >( provider_factory: ProviderFactory, mut blocks: impl Iterator, diff --git a/crates/engine/tree/src/persistence.rs b/crates/engine/tree/src/persistence.rs index 0199ae3f4..86d18ceb4 100644 --- a/crates/engine/tree/src/persistence.rs +++ b/crates/engine/tree/src/persistence.rs @@ -3,7 +3,7 @@ use alloy_eips::BlockNumHash; use reth_chain_state::ExecutedBlock; use reth_errors::ProviderError; use reth_primitives::BlockBody; -use reth_primitives_traits::{Block, FullNodePrimitives}; +use reth_primitives_traits::FullNodePrimitives; use reth_provider::{ providers::ProviderNodeTypes, writer::UnifiedStorageWriter, BlockHashReader, ChainStateBlockWriter, DatabaseProviderFactory, ProviderFactory, StaticFileProviderFactory, @@ -21,11 +21,11 @@ use tracing::{debug, error}; /// A helper trait with requirements for [`ProviderNodeTypes`] to be used within /// [`PersistenceService`]. pub trait PersistenceNodeTypes: - ProviderNodeTypes>> + ProviderNodeTypes> { } impl PersistenceNodeTypes for T where - T: ProviderNodeTypes>> + T: ProviderNodeTypes> { } /// Writes parts of reth's in memory tree state to the database and static files. diff --git a/crates/exex/exex/src/backfill/test_utils.rs b/crates/exex/exex/src/backfill/test_utils.rs index 5d0f88f51..169d2d758 100644 --- a/crates/exex/exex/src/backfill/test_utils.rs +++ b/crates/exex/exex/src/backfill/test_utils.rs @@ -58,7 +58,7 @@ pub(crate) fn execute_block_and_commit_to_database( block: &BlockWithSenders, ) -> eyre::Result> where - N: ProviderNodeTypes>, + N: ProviderNodeTypes>, { let provider = provider_factory.provider()?; @@ -162,7 +162,7 @@ pub(crate) fn blocks_and_execution_outputs( key_pair: Keypair, ) -> eyre::Result)>> where - N: ProviderNodeTypes>, + N: ProviderNodeTypes>, { let (block1, block2) = blocks(chain_spec.clone(), key_pair)?; @@ -184,7 +184,7 @@ pub(crate) fn blocks_and_execution_outcome( ) -> eyre::Result<(Vec, ExecutionOutcome)> where N: ProviderNodeTypes, - N::Primitives: FullNodePrimitives, + N::Primitives: FullNodePrimitives, { let (block1, block2) = blocks(chain_spec.clone(), key_pair)?; diff --git a/crates/node/builder/src/setup.rs b/crates/node/builder/src/setup.rs index 71f0ceb56..3258ba8fe 100644 --- a/crates/node/builder/src/setup.rs +++ b/crates/node/builder/src/setup.rs @@ -14,7 +14,7 @@ use reth_exex::ExExManagerHandle; use reth_network_p2p::{ bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, EthBlockClient, }; -use reth_node_api::FullNodePrimitives; +use reth_node_api::{FullNodePrimitives, NodePrimitives}; use reth_provider::{providers::ProviderNodeTypes, ProviderFactory}; use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, StageSet}; use reth_static_file::StaticFileProducer; @@ -88,7 +88,7 @@ where N: ProviderNodeTypes, H: HeaderDownloader
+ 'static, B: BodyDownloader< - Body = <::Block as reth_node_api::Block>::Body, + Body = <::Block as reth_node_api::Block>::Body, > + 'static, Executor: BlockExecutorProvider, N::Primitives: FullNodePrimitives, diff --git a/crates/optimism/primitives/src/lib.rs b/crates/optimism/primitives/src/lib.rs index 26499bb43..334440ea1 100644 --- a/crates/optimism/primitives/src/lib.rs +++ b/crates/optimism/primitives/src/lib.rs @@ -14,14 +14,14 @@ pub mod tx_type; pub use tx_type::OpTxType; use alloy_consensus::Header; -use reth_node_types::FullNodePrimitives; +use reth_node_types::NodePrimitives; use reth_primitives::{Block, BlockBody, Receipt, TransactionSigned}; /// Optimism primitive types. #[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct OpPrimitives; -impl FullNodePrimitives for OpPrimitives { +impl NodePrimitives for OpPrimitives { type Block = Block; type BlockHeader = Header; type BlockBody = BlockBody; diff --git a/crates/primitives-traits/src/node.rs b/crates/primitives-traits/src/node.rs index 7cb321e9a..19f6bd845 100644 --- a/crates/primitives-traits/src/node.rs +++ b/crates/primitives-traits/src/node.rs @@ -77,33 +77,45 @@ impl NodePrimitives for () { } /// Helper trait that sets trait bounds on [`NodePrimitives`]. -pub trait FullNodePrimitives: - Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + 'static +pub trait FullNodePrimitives +where + Self: NodePrimitives< + Block: FullBlock
, + BlockHeader: FullBlockHeader, + BlockBody: FullBlockBody, + SignedTx: FullSignedTx, + TxType: FullTxType, + Receipt: FullReceipt, + > + Send + + Sync + + Unpin + + Clone + + Default + + fmt::Debug + + PartialEq + + Eq + + 'static, { - /// Block primitive. - type Block: FullBlock
; - /// Block header primitive. - type BlockHeader: FullBlockHeader + 'static; - /// Block body primitive. - type BlockBody: FullBlockBody + 'static; - /// Signed version of the transaction type. - type SignedTx: FullSignedTx; - /// Transaction envelope type ID. - type TxType: FullTxType; - /// A receipt. - type Receipt: FullReceipt; } -impl NodePrimitives for T -where - T: FullNodePrimitives, +impl FullNodePrimitives for T where + T: NodePrimitives< + Block: FullBlock
, + BlockHeader: FullBlockHeader, + BlockBody: FullBlockBody, + SignedTx: FullSignedTx, + TxType: FullTxType, + Receipt: FullReceipt, + > + Send + + Sync + + Unpin + + Clone + + Default + + fmt::Debug + + PartialEq + + Eq + + 'static { - type Block = T::Block; - type BlockHeader = T::BlockHeader; - type BlockBody = T::BlockBody; - type SignedTx = T::SignedTx; - type TxType = T::TxType; - type Receipt = T::Receipt; } /// Helper adapter type for accessing [`NodePrimitives`] receipt type. diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 7999588e4..203880209 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -79,7 +79,7 @@ pub mod serde_bincode_compat { #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct EthPrimitives; -impl reth_primitives_traits::FullNodePrimitives for EthPrimitives { +impl reth_primitives_traits::NodePrimitives for EthPrimitives { type Block = crate::Block; type BlockHeader = alloy_consensus::Header; type BlockBody = crate::BlockBody; diff --git a/crates/stages/stages/src/stages/hashing_account.rs b/crates/stages/stages/src/stages/hashing_account.rs index ecca1e071..e6b1e5484 100644 --- a/crates/stages/stages/src/stages/hashing_account.rs +++ b/crates/stages/stages/src/stages/hashing_account.rs @@ -63,7 +63,8 @@ impl AccountHashingStage { opts: SeedOpts, ) -> Result, StageError> where - N::Primitives: reth_primitives_traits::FullNodePrimitives, + N::Primitives: + reth_primitives_traits::FullNodePrimitives, { use alloy_primitives::U256; use reth_db_api::models::AccountBeforeTx; diff --git a/crates/static-file/static-file/Cargo.toml b/crates/static-file/static-file/Cargo.toml index d22b116cd..89f606878 100644 --- a/crates/static-file/static-file/Cargo.toml +++ b/crates/static-file/static-file/Cargo.toml @@ -13,12 +13,14 @@ workspace = true [dependencies] # reth +reth-codecs.workspace = true reth-db.workspace = true reth-db-api.workspace = true reth-provider.workspace = true reth-storage-errors.workspace = true reth-tokio-util.workspace = true reth-prune-types.workspace = true +reth-primitives-traits.workspace = true reth-static-file-types.workspace = true reth-stages-types.workspace = true diff --git a/crates/static-file/static-file/src/segments/transactions.rs b/crates/static-file/static-file/src/segments/transactions.rs index 59ec94be9..168ae9481 100644 --- a/crates/static-file/static-file/src/segments/transactions.rs +++ b/crates/static-file/static-file/src/segments/transactions.rs @@ -1,7 +1,9 @@ use crate::segments::Segment; use alloy_primitives::BlockNumber; -use reth_db::tables; +use reth_codecs::Compact; +use reth_db::{table::Value, tables}; use reth_db_api::{cursor::DbCursorRO, transaction::DbTx}; +use reth_primitives_traits::NodePrimitives; use reth_provider::{ providers::StaticFileWriter, BlockReader, DBProvider, StaticFileProviderFactory, }; @@ -13,8 +15,11 @@ use std::ops::RangeInclusive; #[derive(Debug, Default)] pub struct Transactions; -impl Segment - for Transactions +impl Segment for Transactions +where + Provider: StaticFileProviderFactory> + + DBProvider + + BlockReader, { fn segment(&self) -> StaticFileSegment { StaticFileSegment::Transactions @@ -38,8 +43,9 @@ impl Segment()?; + let mut transactions_cursor = provider.tx_ref().cursor_read::::Primitives as NodePrimitives>::SignedTx, + >>()?; let transactions_walker = transactions_cursor.walk_range(block_body_indices.tx_num_range())?; diff --git a/crates/static-file/static-file/src/static_file_producer.rs b/crates/static-file/static-file/src/static_file_producer.rs index 8959819e8..371a344d8 100644 --- a/crates/static-file/static-file/src/static_file_producer.rs +++ b/crates/static-file/static-file/src/static_file_producer.rs @@ -4,6 +4,9 @@ use crate::{segments, segments::Segment, StaticFileProducerEvent}; use alloy_primitives::BlockNumber; use parking_lot::Mutex; use rayon::prelude::*; +use reth_codecs::Compact; +use reth_db::table::Value; +use reth_primitives_traits::NodePrimitives; use reth_provider::{ providers::StaticFileWriter, BlockReader, ChainStateBlockReader, DBProvider, DatabaseProviderFactory, StageCheckpointReader, StaticFileProviderFactory, @@ -86,7 +89,10 @@ impl StaticFileProducerInner where Provider: StaticFileProviderFactory + DatabaseProviderFactory< - Provider: StaticFileProviderFactory + StageCheckpointReader + BlockReader, + Provider: StaticFileProviderFactory< + Primitives: NodePrimitives, + > + StageCheckpointReader + + BlockReader, >, { /// Listen for events on the `static_file_producer`. diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 083e7fb59..74009ffff 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -889,8 +889,7 @@ mod tests { static_file_provider.latest_writer(StaticFileSegment::Transactions)?; transactions_writer.increment_block(block.number)?; for tx in block.body.transactions() { - let tx: TransactionSignedNoHash = tx.clone().into(); - transactions_writer.append_transaction(tx_num, &tx)?; + transactions_writer.append_transaction(tx_num, tx)?; tx_num += 1; } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index ff80213fd..e6c384297 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -48,11 +48,11 @@ use reth_execution_types::{Chain, ExecutionOutcome}; use reth_network_p2p::headers::downloader::SyncTarget; use reth_node_types::NodeTypes; use reth_primitives::{ - Account, Block, BlockBody, BlockWithSenders, Bytecode, GotExpected, Receipt, SealedBlock, - SealedBlockWithSenders, SealedHeader, StaticFileSegment, StorageEntry, TransactionMeta, - TransactionSigned, TransactionSignedNoHash, + Account, Block, BlockBody, BlockWithSenders, Bytecode, GotExpected, NodePrimitives, Receipt, + SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment, StorageEntry, + TransactionMeta, TransactionSigned, TransactionSignedNoHash, }; -use reth_primitives_traits::{BlockBody as _, FullNodePrimitives, SignedTransaction}; +use reth_primitives_traits::{BlockBody as _, SignedTransaction}; use reth_prune_types::{PruneCheckpoint, PruneModes, PruneSegment}; use reth_stages_types::{StageCheckpoint, StageId}; use reth_storage_api::{StateProvider, StorageChangeSetReader, TryIntoHistoricalStateProvider}; @@ -2778,8 +2778,7 @@ impl BlockExecutio impl BlockWriter for DatabaseProvider { - type Body = - <::Block as reth_primitives_traits::Block>::Body; + type Body = <::Block as reth_primitives_traits::Block>::Body; /// Inserts the block into the database, always modifying the following tables: /// * [`CanonicalHeaders`](tables::CanonicalHeaders) diff --git a/crates/storage/provider/src/providers/static_file/mod.rs b/crates/storage/provider/src/providers/static_file/mod.rs index 30b8d0344..58a9e3bb3 100644 --- a/crates/storage/provider/src/providers/static_file/mod.rs +++ b/crates/storage/provider/src/providers/static_file/mod.rs @@ -68,7 +68,7 @@ mod tests { use reth_db_api::transaction::DbTxMut; use reth_primitives::{ static_file::{find_fixed_range, SegmentRangeInclusive, DEFAULT_BLOCKS_PER_STATIC_FILE}, - Receipt, TransactionSignedNoHash, + EthPrimitives, Receipt, TransactionSigned, }; use reth_storage_api::{ReceiptProvider, TransactionsProvider}; use reth_testing_utils::generators::{self, random_header_range}; @@ -304,20 +304,20 @@ mod tests { /// * `10..=19`: no txs/receipts /// * `20..=29`: only one tx/receipt fn setup_tx_based_scenario( - sf_rw: &StaticFileProvider<()>, + sf_rw: &StaticFileProvider, segment: StaticFileSegment, blocks_per_file: u64, ) { fn setup_block_ranges( - writer: &mut StaticFileProviderRWRefMut<'_, ()>, - sf_rw: &StaticFileProvider<()>, + writer: &mut StaticFileProviderRWRefMut<'_, EthPrimitives>, + sf_rw: &StaticFileProvider, segment: StaticFileSegment, block_range: &Range, mut tx_count: u64, next_tx_num: &mut u64, ) { let mut receipt = Receipt::default(); - let mut tx = TransactionSignedNoHash::default(); + let mut tx = TransactionSigned::default(); for block in block_range.clone() { writer.increment_block(block).unwrap(); diff --git a/crates/storage/provider/src/providers/static_file/writer.rs b/crates/storage/provider/src/providers/static_file/writer.rs index 5951dbb75..83954bde3 100644 --- a/crates/storage/provider/src/providers/static_file/writer.rs +++ b/crates/storage/provider/src/providers/static_file/writer.rs @@ -558,7 +558,10 @@ impl StaticFileProviderRW { /// empty blocks and this function wouldn't be called. /// /// Returns the current [`TxNumber`] as seen in the static file. - pub fn append_transaction(&mut self, tx_num: TxNumber, tx: impl Compact) -> ProviderResult<()> { + pub fn append_transaction(&mut self, tx_num: TxNumber, tx: &N::SignedTx) -> ProviderResult<()> + where + N::SignedTx: Compact, + { let start = Instant::now(); self.ensure_no_queued_prune()?;