mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: consensus trait generic over NodePrimitives (#13026)
This commit is contained in:
@ -4,7 +4,7 @@ use crate::ConfigureEvm;
|
||||
use alloy_consensus::Header;
|
||||
use alloy_rpc_types_engine::JwtSecret;
|
||||
use reth_beacon_consensus::BeaconConsensusEngineHandle;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network_api::FullNetwork;
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
@ -56,7 +56,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>;
|
||||
|
||||
/// The consensus type of the node.
|
||||
type Consensus: Consensus + Clone + Unpin + 'static;
|
||||
type Consensus: FullConsensus<<Self::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
@ -8,7 +8,7 @@ use crate::{
|
||||
BuilderContext, ConfigureEvm, FullNodeTypes,
|
||||
};
|
||||
use alloy_consensus::Header;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_node_api::{NodeTypes, NodeTypesWithEngine};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
@ -378,7 +378,7 @@ where
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Components = Components<Node, Pool, EVM, Executor, Cons>;
|
||||
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
//! Consensus component for the node builder.
|
||||
use reth_node_api::NodeTypes;
|
||||
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use std::future::Future;
|
||||
|
||||
/// A type that knows how to build the consensus implementation.
|
||||
pub trait ConsensusBuilder<Node: FullNodeTypes>: Send {
|
||||
/// The consensus implementation to build.
|
||||
type Consensus: reth_consensus::Consensus + Clone + Unpin + 'static;
|
||||
type Consensus: reth_consensus::FullConsensus<<Node::Types as NodeTypes>::Primitives>
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static;
|
||||
|
||||
/// Creates the consensus implementation.
|
||||
fn build_consensus(
|
||||
@ -17,7 +22,10 @@ pub trait ConsensusBuilder<Node: FullNodeTypes>: Send {
|
||||
impl<Node, F, Fut, Consensus> ConsensusBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Consensus: reth_consensus::Consensus + Clone + Unpin + 'static,
|
||||
Consensus: reth_consensus::FullConsensus<<Node::Types as NodeTypes>::Primitives>
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Consensus>> + Send,
|
||||
{
|
||||
|
||||
@ -23,7 +23,7 @@ pub use pool::*;
|
||||
|
||||
use crate::{ConfigureEvm, FullNodeTypes};
|
||||
use alloy_consensus::Header;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_network_api::FullNetwork;
|
||||
@ -47,7 +47,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
|
||||
type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>;
|
||||
|
||||
/// The consensus type of the node.
|
||||
type Consensus: Consensus + Clone + Unpin + 'static;
|
||||
type Consensus: FullConsensus<<T::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
@ -100,7 +100,7 @@ where
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
type Evm = EVM;
|
||||
@ -140,7 +140,7 @@ where
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone,
|
||||
Cons: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
|
||||
@ -13,7 +13,6 @@ use rayon::ThreadPoolBuilder;
|
||||
use reth_beacon_consensus::EthBeaconConsensus;
|
||||
use reth_chainspec::{Chain, EthChainSpec, EthereumHardforks};
|
||||
use reth_config::{config::EtlConfig, PruneConfig};
|
||||
use reth_consensus::Consensus;
|
||||
use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
|
||||
use reth_db_common::init::{init_genesis, InitDatabaseError};
|
||||
use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader};
|
||||
@ -681,7 +680,6 @@ where
|
||||
let components = components_builder.build_components(&builder_ctx).await?;
|
||||
|
||||
let blockchain_db = self.blockchain_db().clone();
|
||||
let consensus = Arc::new(components.consensus().clone());
|
||||
|
||||
let node_adapter = NodeAdapter {
|
||||
components,
|
||||
@ -699,7 +697,6 @@ where
|
||||
},
|
||||
node_adapter,
|
||||
head,
|
||||
consensus,
|
||||
};
|
||||
|
||||
let ctx = LaunchContextWith {
|
||||
@ -855,11 +852,6 @@ where
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Returns the configured `Consensus`.
|
||||
pub fn consensus(&self) -> Arc<dyn Consensus> {
|
||||
self.right().consensus.clone()
|
||||
}
|
||||
|
||||
/// Returns the metrics sender.
|
||||
pub fn sync_metrics_tx(&self) -> UnboundedSender<MetricEvent> {
|
||||
self.right().db_provider_container.metrics_sender.clone()
|
||||
@ -1029,7 +1021,6 @@ where
|
||||
db_provider_container: WithMeteredProvider<T::Types>,
|
||||
node_adapter: NodeAdapter<T, CB::Components>,
|
||||
head: Head,
|
||||
consensus: Arc<dyn Consensus>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -175,13 +175,15 @@ where
|
||||
));
|
||||
info!(target: "reth::cli", "StaticFileProducer initialized");
|
||||
|
||||
let consensus = Arc::new(ctx.components().consensus().clone());
|
||||
|
||||
// Configure the pipeline
|
||||
let pipeline_exex_handle =
|
||||
exex_manager_handle.clone().unwrap_or_else(ExExManagerHandle::empty);
|
||||
let pipeline = build_networked_pipeline(
|
||||
&ctx.toml_config().stages,
|
||||
network_client.clone(),
|
||||
ctx.consensus(),
|
||||
consensus.clone(),
|
||||
ctx.provider_factory().clone(),
|
||||
ctx.task_executor(),
|
||||
ctx.sync_metrics_tx(),
|
||||
@ -223,7 +225,7 @@ where
|
||||
|
||||
let mut engine_service = if ctx.is_dev() {
|
||||
let eth_service = LocalEngineService::new(
|
||||
ctx.consensus(),
|
||||
consensus.clone(),
|
||||
ctx.components().block_executor().clone(),
|
||||
ctx.provider_factory().clone(),
|
||||
ctx.blockchain_db().clone(),
|
||||
@ -242,7 +244,7 @@ where
|
||||
Either::Left(eth_service)
|
||||
} else {
|
||||
let eth_service = EngineService::new(
|
||||
ctx.consensus(),
|
||||
consensus.clone(),
|
||||
ctx.components().block_executor().clone(),
|
||||
ctx.chain_spec(),
|
||||
network_client.clone(),
|
||||
|
||||
@ -236,7 +236,7 @@ where
|
||||
let pipeline = crate::setup::build_networked_pipeline(
|
||||
&ctx.toml_config().stages,
|
||||
network_client.clone(),
|
||||
ctx.consensus(),
|
||||
consensus.clone(),
|
||||
ctx.provider_factory().clone(),
|
||||
ctx.task_executor(),
|
||||
ctx.sync_metrics_tx(),
|
||||
|
||||
Reference in New Issue
Block a user