Skip to content

Commit

Permalink
refactor: relax bound on NodeTypesWithDB (#10720)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Sep 5, 2024
1 parent 665bfd7 commit a996eea
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
13 changes: 9 additions & 4 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_network_p2p::{
sync::{NetworkSyncUpdater, SyncState},
BlockClient,
};
use reth_node_types::NodeTypesWithDB;
use reth_node_types::NodeTypesWithEngine;
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::{PayloadAttributes, PayloadBuilderAttributes};
use reth_payload_validator::ExecutionPayloadValidator;
Expand Down Expand Up @@ -87,6 +87,11 @@ const MAX_INVALID_HEADERS: u32 = 512u32;
/// If the distance exceeds this threshold, the pipeline will be used for sync.
pub const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS;

/// Helper trait expressing requirements for node types to be used in engine.
pub trait EngineNodeTypes: ProviderNodeTypes + NodeTypesWithEngine {}

impl<T> EngineNodeTypes for T where T: ProviderNodeTypes + NodeTypesWithEngine {}

/// Represents a pending forkchoice update.
///
/// This type encapsulates the necessary components for a pending forkchoice update
Expand Down Expand Up @@ -169,7 +174,7 @@ type PendingForkchoiceUpdate<PayloadAttributes> =
#[allow(missing_debug_implementations)]
pub struct BeaconConsensusEngine<N, BT, Client>
where
N: NodeTypesWithDB,
N: EngineNodeTypes,
Client: BlockClient,
BT: BlockchainTreeEngine
+ BlockReader
Expand Down Expand Up @@ -225,7 +230,7 @@ where

impl<N, BT, Client> BeaconConsensusEngine<N, BT, Client>
where
N: ProviderNodeTypes,
N: EngineNodeTypes,
BT: BlockchainTreeEngine
+ BlockReader
+ BlockIdReader
Expand Down Expand Up @@ -1789,7 +1794,7 @@ where
/// receiver and forwarding them to the blockchain tree.
impl<N, BT, Client> Future for BeaconConsensusEngine<N, BT, Client>
where
N: ProviderNodeTypes,
N: EngineNodeTypes,
Client: BlockClient + 'static,
BT: BlockchainTreeEngine
+ BlockReader
Expand Down
13 changes: 5 additions & 8 deletions crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::{Stream, StreamExt};
use pin_project::pin_project;
use reth_beacon_consensus::{BeaconConsensusEngineEvent, BeaconEngineMessage};
use reth_beacon_consensus::{BeaconConsensusEngineEvent, BeaconEngineMessage, EngineNodeTypes};
use reth_consensus::Consensus;
use reth_engine_tree::{
backfill::PipelineSync,
Expand All @@ -18,10 +18,7 @@ use reth_network_p2p::BlockClient;
use reth_node_types::NodeTypesWithEngine;
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_validator::ExecutionPayloadValidator;
use reth_provider::{
providers::{BlockchainProvider2, ProviderNodeTypes},
ProviderFactory,
};
use reth_provider::{providers::BlockchainProvider2, ProviderFactory};
use reth_prune::Pruner;
use reth_stages_api::Pipeline;
use reth_tasks::TaskSpawner;
Expand Down Expand Up @@ -50,7 +47,7 @@ type EngineServiceType<N, Client> = ChainOrchestrator<
#[allow(missing_debug_implementations)]
pub struct EngineService<N, Client, E>
where
N: ProviderNodeTypes,
N: EngineNodeTypes,
Client: BlockClient + 'static,
E: BlockExecutorProvider + 'static,
{
Expand All @@ -60,7 +57,7 @@ where

impl<N, Client, E> EngineService<N, Client, E>
where
N: ProviderNodeTypes,
N: EngineNodeTypes,
Client: BlockClient + 'static,
E: BlockExecutorProvider + 'static,
{
Expand Down Expand Up @@ -119,7 +116,7 @@ where

impl<N, Client, E> Stream for EngineService<N, Client, E>
where
N: ProviderNodeTypes,
N: EngineNodeTypes,
Client: BlockClient + 'static,
E: BlockExecutorProvider + 'static,
{
Expand Down
4 changes: 2 additions & 2 deletions crates/node/api/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::ConfigureEvm;
/// 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;
type Types: NodeTypesWithDB + NodeTypesWithEngine;
/// The provider type used to interact with the node.
type Provider: FullProvider<Self::Types>;
}
Expand All @@ -35,7 +35,7 @@ pub struct FullNodeTypesAdapter<Types, Provider> {

impl<Types, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, Provider>
where
Types: NodeTypesWithDB,
Types: NodeTypesWithDB + NodeTypesWithEngine,
Provider: FullProvider<Types>,
{
type Types = Types;
Expand Down
2 changes: 1 addition & 1 deletion crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl EngineNodeLauncher {

impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for EngineNodeLauncher
where
Types: NodeTypesWithDB<ChainSpec = ChainSpec>,
Types: NodeTypesWithDB<ChainSpec = ChainSpec> + NodeTypesWithEngine,
T: FullNodeTypes<Types = Types, Provider = BlockchainProvider2<Types>>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<
Expand Down
6 changes: 4 additions & 2 deletions crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider,
use reth_engine_util::EngineMessageStreamExt;
use reth_exex::ExExManagerHandle;
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider};
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypesWithDB};
use reth_node_api::{
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypesWithDB, NodeTypesWithEngine,
};
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
Expand Down Expand Up @@ -102,7 +104,7 @@ impl DefaultNodeLauncher {

impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for DefaultNodeLauncher
where
Types: NodeTypesWithDB<ChainSpec = ChainSpec>,
Types: NodeTypesWithDB<ChainSpec = ChainSpec> + NodeTypesWithEngine,
T: FullNodeTypes<Provider = BlockchainProvider<Types>, Types = Types>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<
Expand Down
4 changes: 2 additions & 2 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait NodeTypesWithEngine: NodeTypes {
/// node.
///
/// Its types are configured by node internally and are not intended to be user configurable.
pub trait NodeTypesWithDB: NodeTypesWithEngine {
pub trait NodeTypesWithDB: NodeTypes {
/// Underlying database type used by the node to store and retrieve data.
type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ where

impl<Types, DB> NodeTypesWithDB for NodeTypesWithDBAdapter<Types, DB>
where
Types: NodeTypesWithEngine,
Types: NodeTypes,
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
{
type DB = DB;
Expand Down

0 comments on commit a996eea

Please sign in to comment.