diff --git a/Cargo.lock b/Cargo.lock index 6dbc8a706e9a..106c9ebed9c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8126,6 +8126,7 @@ dependencies = [ "eyre", "reth-beacon-consensus", "reth-consensus", + "reth-db-api", "reth-engine-primitives", "reth-evm", "reth-network-api", diff --git a/crates/e2e-test-utils/src/lib.rs b/crates/e2e-test-utils/src/lib.rs index 72d912d6b54f..ae87fde48969 100644 --- a/crates/e2e-test-utils/src/lib.rs +++ b/crates/e2e-test-utils/src/lib.rs @@ -209,7 +209,7 @@ where /// Testing database pub type TmpDB = Arc>; type TmpNodeAdapter>> = - FullNodeTypesAdapter, Provider>; + FullNodeTypesAdapter; /// Type alias for a `NodeAdapter` pub type Adapter>> = NodeAdapter< diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index d2eb59a4ae4c..492d1cfac7cf 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -10,9 +10,7 @@ use reth_ethereum_payload_builder::EthereumBuilderConfig; use reth_evm::execute::BasicBlockExecutorProvider; use reth_evm_ethereum::execute::EthExecutionStrategyFactory; use reth_network::{EthNetworkPrimitives, NetworkHandle, PeersInfo}; -use reth_node_api::{ - AddOnsContext, ConfigureEvm, FullNodeComponents, HeaderTy, NodeTypesWithDB, TxTy, -}; +use reth_node_api::{AddOnsContext, ConfigureEvm, FullNodeComponents, HeaderTy, TxTy}; use reth_node_builder::{ components::{ ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, @@ -94,16 +92,9 @@ pub type EthereumAddOns = RpcAddOns< EthereumEngineValidatorBuilder, >; -impl Node for EthereumNode +impl Node for EthereumNode where - Types: NodeTypesWithDB - + NodeTypesWithEngine< - Engine = EthEngineTypes, - ChainSpec = ChainSpec, - Primitives = EthPrimitives, - Storage = EthStorage, - >, - N: FullNodeTypes, + N: FullNodeTypes, { type ComponentsBuilder = ComponentsBuilder< N, diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index 939bf21c0223..be15828681c2 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -175,7 +175,8 @@ pub type Adapter = NodeAdapter< RethFullAdapter, <, + TestNode, + TmpDB, BlockchainProvider>, >, >>::ComponentsBuilder as NodeComponentsBuilder>>::Components, @@ -290,7 +291,7 @@ pub async fn test_exex_context_with_chain_spec( let (_, payload_builder) = NoopPayloadBuilderService::::new(); - let components = NodeAdapter::, _> { + let components = NodeAdapter::, _> { components: Components { transaction_pool, evm_config, diff --git a/crates/node/api/Cargo.toml b/crates/node/api/Cargo.toml index 7d209a90fcad..d952a8abfaae 100644 --- a/crates/node/api/Cargo.toml +++ b/crates/node/api/Cargo.toml @@ -12,6 +12,7 @@ workspace = true [dependencies] # reth +reth-db-api.workspace = true reth-beacon-consensus.workspace = true reth-consensus.workspace = true reth-evm.workspace = true diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index edb68a6589b0..8db75480d11a 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -4,10 +4,14 @@ use crate::ConfigureEvm; use alloy_rpc_types_engine::JwtSecret; use reth_beacon_consensus::BeaconConsensusEngineHandle; use reth_consensus::FullConsensus; +use reth_db_api::{ + database_metrics::{DatabaseMetadata, DatabaseMetrics}, + Database, +}; use reth_evm::execute::BlockExecutorProvider; use reth_network_api::FullNetwork; use reth_node_core::node_config::NodeConfig; -use reth_node_types::{HeaderTy, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, TxTy}; +use reth_node_types::{HeaderTy, NodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine, TxTy}; use reth_payload_builder_primitives::PayloadBuilder; use reth_provider::FullProvider; use reth_tasks::TaskExecutor; @@ -20,26 +24,25 @@ use std::{future::Future, marker::PhantomData}; /// Its types are configured by node internally and are not intended to be user configurable. pub trait FullNodeTypes: Send + Sync + Unpin + 'static { /// Node's types with the database. - type Types: NodeTypesWithDB + NodeTypesWithEngine; + type Types: NodeTypesWithEngine; + /// Underlying database type used by the node to store and retrieve data. + type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static; /// The provider type used to interact with the node. - type Provider: FullProvider; + type Provider: FullProvider>; } /// An adapter type that adds the builtin provider type to the user configured node types. #[derive(Debug)] -pub struct FullNodeTypesAdapter { - /// An instance of the user configured node types. - pub types: PhantomData, - /// The provider type used by the node. - pub provider: PhantomData, -} +pub struct FullNodeTypesAdapter(PhantomData<(Types, DB, Provider)>); -impl FullNodeTypes for FullNodeTypesAdapter +impl FullNodeTypes for FullNodeTypesAdapter where - Types: NodeTypesWithDB + NodeTypesWithEngine, - Provider: FullProvider, + Types: NodeTypesWithEngine, + DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, + Provider: FullProvider>, { type Types = Types; + type DB = DB; type Provider = Provider; } diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 44311f34e3c4..fe36d4b7ec55 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -50,10 +50,8 @@ pub use states::*; /// The adapter type for a reth node with the builtin provider type // Note: we need to hardcode this because custom components might depend on it in associated types. -pub type RethFullAdapter = FullNodeTypesAdapter< - NodeTypesWithDBAdapter, - BlockchainProvider>, ->; +pub type RethFullAdapter = + FullNodeTypesAdapter>>; #[allow(clippy::doc_markdown)] #[cfg_attr(doc, aquamarine::aquamarine)] @@ -252,7 +250,7 @@ where /// Configures the types of the node and the provider type that will be used by the node. pub fn with_types_and_provider( self, - ) -> NodeBuilderWithTypes, P>> + ) -> NodeBuilderWithTypes> where T: NodeTypesWithEngine + NodeTypesForProvider, P: FullProvider>, @@ -313,9 +311,7 @@ where /// Configures the types of the node and the provider type that will be used by the node. pub fn with_types_and_provider( self, - ) -> WithLaunchContext< - NodeBuilderWithTypes, P>>, - > + ) -> WithLaunchContext>> where T: NodeTypesWithEngine + NodeTypesForProvider, P: FullProvider>, diff --git a/crates/node/builder/src/builder/states.rs b/crates/node/builder/src/builder/states.rs index fa12cc78b615..0587003480c9 100644 --- a/crates/node/builder/src/builder/states.rs +++ b/crates/node/builder/src/builder/states.rs @@ -13,7 +13,7 @@ use crate::{ AddOns, FullNode, }; use reth_exex::ExExContext; -use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB}; +use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes}; use reth_node_core::node_config::NodeConfig; use reth_tasks::TaskExecutor; use std::{fmt, future::Future}; @@ -30,7 +30,7 @@ impl NodeBuilderWithTypes { /// Creates a new instance of the node builder with the given configuration and types. pub const fn new( config: NodeConfig<::ChainSpec>, - database: ::DB, + database: T::DB, ) -> Self { Self { config, adapter: NodeTypesAdapter::new(database) } } @@ -54,12 +54,12 @@ impl NodeBuilderWithTypes { /// Container for the node's types and the database the node uses. pub struct NodeTypesAdapter { /// The database type used by the node. - pub database: ::DB, + pub database: T::DB, } impl NodeTypesAdapter { /// Create a new adapter from the given node types. - pub(crate) const fn new(database: ::DB) -> Self { + pub(crate) const fn new(database: T::DB) -> Self { Self { database } } } @@ -83,6 +83,7 @@ pub struct NodeAdapter> { impl> FullNodeTypes for NodeAdapter { type Types = T::Types; + type DB = T::DB; type Provider = T::Provider; } diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index c5275647aa43..a80a80466d54 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -13,7 +13,10 @@ use rayon::ThreadPoolBuilder; use reth_chainspec::{Chain, EthChainSpec, EthereumHardforks}; use reth_config::{config::EtlConfig, PruneConfig}; use reth_consensus::noop::NoopConsensus; -use reth_db_api::{database::Database, database_metrics::DatabaseMetrics}; +use reth_db_api::{ + database::Database, + database_metrics::{DatabaseMetadata, DatabaseMetrics}, +}; use reth_db_common::init::{init_genesis, InitStorageError}; use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader}; use reth_engine_local::MiningMode; @@ -24,6 +27,7 @@ use reth_invalid_block_hooks::InvalidBlockWitnessHook; use reth_network_p2p::headers::client::HeadersClient; use reth_node_api::{ FullNodePrimitives, FullNodeTypes, NodePrimitives, NodeTypes, NodeTypesWithDB, + NodeTypesWithDBAdapter, }; use reth_node_core::{ args::InvalidBlockHookType, @@ -44,7 +48,7 @@ use reth_node_metrics::{ }; use reth_primitives::{Head, TransactionSigned}; use reth_provider::{ - providers::{ProviderNodeTypes, StaticFileProvider}, + providers::{NodeTypesForProvider, ProviderNodeTypes, StaticFileProvider}, BlockHashReader, BlockNumReader, ChainSpecProvider, ProviderError, ProviderFactory, ProviderResult, StageCheckpointReader, StateProviderFactory, StaticFileProviderFactory, }; @@ -567,12 +571,16 @@ where } } -impl LaunchContextWith, WithMeteredProvider>> +impl + LaunchContextWith< + Attached, WithMeteredProvider>>, + > where - N: NodeTypesWithDB, + N: NodeTypes, + DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, { /// Returns the configured `ProviderFactory`. - const fn provider_factory(&self) -> &ProviderFactory { + const fn provider_factory(&self) -> &ProviderFactory> { &self.right().provider_factory } @@ -588,8 +596,8 @@ where create_blockchain_provider: F, ) -> eyre::Result, WithMeteredProviders>>> where - T: FullNodeTypes, - F: FnOnce(ProviderFactory) -> eyre::Result, + T: FullNodeTypes, + F: FnOnce(ProviderFactory>) -> eyre::Result, { let blockchain_db = create_blockchain_provider(self.provider_factory().clone())?; @@ -615,15 +623,17 @@ impl Attached::ChainSpec>, WithMeteredProviders>, > where - T: FullNodeTypes, + T: FullNodeTypes, { /// Returns access to the underlying database. - pub const fn database(&self) -> &::DB { + pub const fn database(&self) -> &T::DB { self.provider_factory().db_ref() } /// Returns the configured `ProviderFactory`. - pub const fn provider_factory(&self) -> &ProviderFactory { + pub const fn provider_factory( + &self, + ) -> &ProviderFactory> { &self.right().db_provider_container.provider_factory } @@ -708,11 +718,13 @@ impl Attached::ChainSpec>, WithComponents>, > where - T: FullNodeTypes, + T: FullNodeTypes, CB: NodeComponentsBuilder, { /// Returns the configured `ProviderFactory`. - pub const fn provider_factory(&self) -> &ProviderFactory { + pub const fn provider_factory( + &self, + ) -> &ProviderFactory> { &self.right().db_provider_container.provider_factory } @@ -731,7 +743,9 @@ where } /// Creates a new [`StaticFileProducer`] with the attached database. - pub fn static_file_producer(&self) -> StaticFileProducer> { + pub fn static_file_producer( + &self, + ) -> StaticFileProducer>> { StaticFileProducer::new(self.provider_factory().clone(), self.prune_modes()) } @@ -865,7 +879,7 @@ impl where T: FullNodeTypes< Provider: StateProviderFactory + ChainSpecProvider, - Types: ProviderNodeTypes>, + Types: NodeTypesForProvider>, >, CB: NodeComponentsBuilder, { @@ -1008,7 +1022,7 @@ pub struct WithMeteredProviders where T: FullNodeTypes, { - db_provider_container: WithMeteredProvider, + db_provider_container: WithMeteredProvider>, blockchain_db: T::Provider, } @@ -1019,7 +1033,7 @@ where T: FullNodeTypes, CB: NodeComponentsBuilder, { - db_provider_container: WithMeteredProvider, + db_provider_container: WithMeteredProvider>, node_adapter: NodeAdapter, head: Head, } diff --git a/crates/node/builder/src/launch/engine.rs b/crates/node/builder/src/launch/engine.rs index 9a7e83b66fca..e398224a1bb1 100644 --- a/crates/node/builder/src/launch/engine.rs +++ b/crates/node/builder/src/launch/engine.rs @@ -3,10 +3,14 @@ use futures::{future::Either, stream, stream_select, StreamExt}; use reth_beacon_consensus::{ hooks::{EngineHooks, StaticFileHook}, - BeaconConsensusEngineHandle, EngineNodeTypes, + BeaconConsensusEngineHandle, }; use reth_chainspec::EthChainSpec; use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider}; +use reth_db_api::{ + database_metrics::{DatabaseMetadata, DatabaseMetrics}, + Database, +}; use reth_engine_local::{LocalEngineService, LocalPayloadAttributesBuilder}; use reth_engine_service::service::{ChainEvent, EngineService}; use reth_engine_tree::{ @@ -18,8 +22,8 @@ use reth_exex::ExExManagerHandle; use reth_network::{NetworkSyncUpdater, SyncState}; use reth_network_api::BlockDownloaderProvider; use reth_node_api::{ - BlockTy, BuiltPayload, EngineValidator, FullNodeTypes, NodeTypesWithEngine, - PayloadAttributesBuilder, PayloadBuilder, PayloadTypes, + BlockTy, BuiltPayload, EngineValidator, FullNodeTypes, NodeTypesWithDBAdapter, + NodeTypesWithEngine, PayloadAttributesBuilder, PayloadBuilder, PayloadTypes, }; use reth_node_core::{ dirs::{ChainPath, DataDirPath}, @@ -28,7 +32,7 @@ use reth_node_core::{ }; use reth_node_events::{cl::ConsensusLayerHealthEvents, node}; use reth_primitives::{EthPrimitives, EthereumHardforks}; -use reth_provider::providers::BlockchainProvider2; +use reth_provider::providers::{BlockchainProvider2, NodeTypesForProvider}; use reth_tasks::TaskExecutor; use reth_tokio_util::EventSender; use reth_tracing::tracing::{debug, error, info}; @@ -67,10 +71,15 @@ impl EngineNodeLauncher { } } -impl LaunchNode> for EngineNodeLauncher +impl LaunchNode> for EngineNodeLauncher where - Types: EngineNodeTypes, - T: FullNodeTypes>, + Types: NodeTypesForProvider + NodeTypesWithEngine, + DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, + T: FullNodeTypes< + Types = Types, + DB = DB, + Provider = BlockchainProvider2>, + >, CB: NodeComponentsBuilder, AO: RethRpcAddOns> + EngineValidatorAddOn< diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index e23ce38da75b..87d026873697 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -8,6 +8,10 @@ pub(crate) mod engine; pub use common::LaunchContext; use common::{Attached, LaunchContextWith, WithConfigs}; pub use exex::ExExLauncher; +use reth_db_api::{ + database_metrics::{DatabaseMetadata, DatabaseMetrics}, + Database, +}; use std::{future::Future, sync::Arc}; @@ -17,21 +21,21 @@ use reth_beacon_consensus::{ BeaconConsensusEngine, }; use reth_blockchain_tree::{ - externals::TreeNodeTypes, noop::NoopBlockchainTree, BlockchainTree, BlockchainTreeConfig, - ShareableBlockchainTree, TreeExternals, + noop::NoopBlockchainTree, BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, + TreeExternals, }; use reth_chainspec::EthChainSpec; use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider}; use reth_engine_util::EngineMessageStreamExt; use reth_exex::ExExManagerHandle; use reth_network::BlockDownloaderProvider; -use reth_node_api::{AddOnsContext, FullNodeTypes, NodeTypesWithEngine}; +use reth_node_api::{AddOnsContext, FullNodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine}; use reth_node_core::{ dirs::{ChainPath, DataDirPath}, exit::NodeExitFuture, }; use reth_node_events::{cl::ConsensusLayerHealthEvents, node}; -use reth_provider::providers::{BlockchainProvider, ProviderNodeTypes}; +use reth_provider::providers::{BlockchainProvider, NodeTypesForTree}; use reth_rpc::eth::RpcNodeCore; use reth_tasks::TaskExecutor; use reth_tracing::tracing::{debug, info}; @@ -99,10 +103,15 @@ impl DefaultNodeLauncher { } } -impl LaunchNode> for DefaultNodeLauncher +impl LaunchNode> for DefaultNodeLauncher where - Types: ProviderNodeTypes + NodeTypesWithEngine + TreeNodeTypes, - T: FullNodeTypes, Types = Types>, + Types: NodeTypesWithEngine + NodeTypesForTree, + DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, + T: FullNodeTypes< + Provider = BlockchainProvider>, + Types = Types, + DB = DB, + >, CB: NodeComponentsBuilder, AO: RethRpcAddOns>, { diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index aa280a908b39..5497052dfffa 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -19,7 +19,7 @@ use reth_node_core::{ }; use reth_payload_builder::PayloadStore; use reth_primitives::{EthPrimitives, PooledTransaction}; -use reth_provider::providers::ProviderNodeTypes; +use reth_provider::providers::NodeTypesForProvider; use reth_rpc::{ eth::{EthApiTypes, FullEthApiServer}, EthApi, @@ -535,7 +535,7 @@ where impl NodeAddOns for RpcAddOns where N: FullNodeComponents< - Types: ProviderNodeTypes, + Types: NodeTypesForProvider, Pool: TransactionPool>, >, EthApi: EthApiTypes