mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: Use OptimismBeaconConsensus in the OptimismNode (#8487)
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -7024,6 +7024,7 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"reth-blockchain-tree",
|
||||
"reth-config",
|
||||
"reth-consensus",
|
||||
"reth-db",
|
||||
"reth-db-common",
|
||||
"reth-evm",
|
||||
@ -7413,7 +7414,10 @@ dependencies = [
|
||||
"futures",
|
||||
"futures-util",
|
||||
"reth",
|
||||
"reth-auto-seal-consensus",
|
||||
"reth-basic-payload-builder",
|
||||
"reth-beacon-consensus",
|
||||
"reth-consensus",
|
||||
"reth-db",
|
||||
"reth-e2e-test-utils",
|
||||
"reth-ethereum-engine-primitives",
|
||||
@ -7476,6 +7480,7 @@ dependencies = [
|
||||
"reth-network",
|
||||
"reth-node-api",
|
||||
"reth-node-builder",
|
||||
"reth-optimism-consensus",
|
||||
"reth-optimism-payload-builder",
|
||||
"reth-payload-builder",
|
||||
"reth-primitives",
|
||||
|
||||
@ -22,6 +22,9 @@ reth-provider.workspace = true
|
||||
reth-transaction-pool.workspace = true
|
||||
reth-network.workspace = true
|
||||
reth-evm-ethereum.workspace = true
|
||||
reth-consensus.workspace = true
|
||||
reth-auto-seal-consensus.workspace = true
|
||||
reth-beacon-consensus.workspace = true
|
||||
|
||||
# misc
|
||||
eyre.workspace = true
|
||||
@ -38,4 +41,3 @@ futures.workspace = true
|
||||
tokio.workspace = true
|
||||
futures-util.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
//! Ethereum Node types config.
|
||||
|
||||
use crate::{EthEngineTypes, EthEvmConfig};
|
||||
use reth_auto_seal_consensus::AutoSealConsensus;
|
||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||
use reth_beacon_consensus::EthBeaconConsensus;
|
||||
use reth_evm_ethereum::execute::EthExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ExecutorBuilder, NetworkBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
|
||||
PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes},
|
||||
BuilderContext, Node, PayloadBuilderConfig,
|
||||
@ -18,6 +21,7 @@ use reth_transaction_pool::{
|
||||
blobstore::DiskFileBlobStore, EthTransactionPool, TransactionPool,
|
||||
TransactionValidationTaskExecutor,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Type configuration for a regular Ethereum node.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
@ -32,6 +36,7 @@ impl EthereumNode {
|
||||
EthereumPayloadBuilder,
|
||||
EthereumNetworkBuilder,
|
||||
EthereumExecutorBuilder,
|
||||
EthereumConsensusBuilder,
|
||||
>
|
||||
where
|
||||
Node: FullNodeTypes<Engine = EthEngineTypes>,
|
||||
@ -42,6 +47,7 @@ impl EthereumNode {
|
||||
.payload(EthereumPayloadBuilder::default())
|
||||
.network(EthereumNetworkBuilder::default())
|
||||
.executor(EthereumExecutorBuilder::default())
|
||||
.consensus(EthereumConsensusBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +66,7 @@ where
|
||||
EthereumPayloadBuilder,
|
||||
EthereumNetworkBuilder,
|
||||
EthereumExecutorBuilder,
|
||||
EthereumConsensusBuilder,
|
||||
>;
|
||||
|
||||
fn components_builder(self) -> Self::ComponentsBuilder {
|
||||
@ -227,3 +234,24 @@ where
|
||||
Ok(handle)
|
||||
}
|
||||
}
|
||||
|
||||
/// A basic ethereum consensus builder.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct EthereumConsensusBuilder {
|
||||
// TODO add closure to modify consensus
|
||||
}
|
||||
|
||||
impl<Node> ConsensusBuilder<Node> for EthereumConsensusBuilder
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
{
|
||||
type Consensus = Arc<dyn reth_consensus::Consensus>;
|
||||
|
||||
async fn build_consensus(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> {
|
||||
if ctx.is_dev() {
|
||||
Ok(Arc::new(AutoSealConsensus::new(ctx.chain_spec())))
|
||||
} else {
|
||||
Ok(Arc::new(EthBeaconConsensus::new(ctx.chain_spec())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ workspace = true
|
||||
## reth
|
||||
reth-blockchain-tree.workspace = true
|
||||
reth-config.workspace = true
|
||||
reth-consensus = { workspace = true, features = ["test-utils"] }
|
||||
reth-db = { workspace = true, features = ["test-utils"] }
|
||||
reth-db-common.workspace = true
|
||||
reth-evm = { workspace = true, features = ["test-utils"] }
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
use futures_util::FutureExt;
|
||||
use reth_blockchain_tree::noop::NoopBlockchainTree;
|
||||
use reth_consensus::test_utils::TestConsensus;
|
||||
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
|
||||
use reth_db_common::init::init_genesis;
|
||||
use reth_evm::test_utils::MockExecutorProvider;
|
||||
@ -18,7 +19,8 @@ use reth_network::{config::SecretKey, NetworkConfigBuilder, NetworkManager};
|
||||
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
Components, ComponentsBuilder, ExecutorBuilder, NodeComponentsBuilder, PoolBuilder,
|
||||
Components, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NodeComponentsBuilder,
|
||||
PoolBuilder,
|
||||
},
|
||||
BuilderContext, Node, NodeAdapter, RethFullAdapter,
|
||||
};
|
||||
@ -83,6 +85,22 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// A test [`ConsensusBuilder`] that builds a [`TestConsensus`].
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
pub struct TestConsensusBuilder;
|
||||
|
||||
impl<Node> ConsensusBuilder<Node> for TestConsensusBuilder
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
{
|
||||
type Consensus = Arc<TestConsensus>;
|
||||
|
||||
async fn build_consensus(self, _ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> {
|
||||
Ok(Arc::new(TestConsensus::default()))
|
||||
}
|
||||
}
|
||||
|
||||
/// A test [`Node`].
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
@ -103,6 +121,7 @@ where
|
||||
EthereumPayloadBuilder,
|
||||
EthereumNetworkBuilder,
|
||||
TestExecutorBuilder,
|
||||
TestConsensusBuilder,
|
||||
>;
|
||||
|
||||
fn components_builder(self) -> Self::ComponentsBuilder {
|
||||
@ -112,6 +131,7 @@ where
|
||||
.payload(EthereumPayloadBuilder::default())
|
||||
.network(EthereumNetworkBuilder::default())
|
||||
.executor(TestExecutorBuilder::default())
|
||||
.consensus(TestConsensusBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +218,7 @@ pub async fn test_exex_context_with_chain_spec(
|
||||
let transaction_pool = testing_pool();
|
||||
let evm_config = EthEvmConfig::default();
|
||||
let executor = MockExecutorProvider::default();
|
||||
let consensus = Arc::new(TestConsensus::default());
|
||||
|
||||
let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
|
||||
let genesis_hash = init_genesis(provider_factory.clone())?;
|
||||
@ -217,7 +238,14 @@ pub async fn test_exex_context_with_chain_spec(
|
||||
let task_executor = tasks.executor();
|
||||
|
||||
let components = NodeAdapter::<FullNodeTypesAdapter<TestNode, _, _>, _> {
|
||||
components: Components { transaction_pool, evm_config, executor, network, payload_builder },
|
||||
components: Components {
|
||||
transaction_pool,
|
||||
evm_config,
|
||||
executor,
|
||||
consensus,
|
||||
network,
|
||||
payload_builder,
|
||||
},
|
||||
task_executor,
|
||||
provider,
|
||||
};
|
||||
|
||||
@ -55,10 +55,10 @@ tokio = { workspace = true, features = [
|
||||
] }
|
||||
tokio-stream.workspace = true
|
||||
|
||||
# ethereum
|
||||
## ethereum
|
||||
discv5.workspace = true
|
||||
|
||||
# crypto
|
||||
## crypto
|
||||
secp256k1 = { workspace = true, features = [
|
||||
"global-context",
|
||||
"rand-std",
|
||||
|
||||
@ -458,6 +458,11 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
self.provider().chain_spec()
|
||||
}
|
||||
|
||||
/// Returns true if the node is configured as --dev
|
||||
pub const fn is_dev(&self) -> bool {
|
||||
self.config().dev.dev
|
||||
}
|
||||
|
||||
/// Returns the transaction pool config of the node.
|
||||
pub fn pool_config(&self) -> PoolConfig {
|
||||
self.config().txpool.pool_config()
|
||||
|
||||
@ -2,11 +2,12 @@
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
Components, ExecutorBuilder, NetworkBuilder, NodeComponents, PayloadServiceBuilder,
|
||||
PoolBuilder,
|
||||
Components, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, NodeComponents,
|
||||
PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
BuilderContext, ConfigureEvm, FullNodeTypes,
|
||||
};
|
||||
use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
@ -31,19 +32,22 @@ use std::{future::Future, marker::PhantomData};
|
||||
/// All component builders are captured in the builder state and will be consumed once the node is
|
||||
/// launched.
|
||||
#[derive(Debug)]
|
||||
pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB> {
|
||||
pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> {
|
||||
pool_builder: PoolB,
|
||||
payload_builder: PayloadB,
|
||||
network_builder: NetworkB,
|
||||
executor_builder: ExecB,
|
||||
consensus_builder: ConsB,
|
||||
_marker: PhantomData<Node>,
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
{
|
||||
/// Configures the node types.
|
||||
pub fn node_types<Types>(self) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB>
|
||||
pub fn node_types<Types>(
|
||||
self,
|
||||
) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Types: FullNodeTypes,
|
||||
{
|
||||
@ -52,6 +56,7 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -59,6 +64,7 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
consensus_builder,
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -70,6 +76,7 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
payload_builder: self.payload_builder,
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -81,6 +88,7 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
payload_builder: f(self.payload_builder),
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -92,6 +100,7 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
payload_builder: self.payload_builder,
|
||||
network_builder: f(self.network_builder),
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -103,13 +112,26 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
payload_builder: self.payload_builder,
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: f(self.executor_builder),
|
||||
consensus_builder: self.consensus_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a function to the consensus builder.
|
||||
pub fn map_consensus(self, f: impl FnOnce(ConsB) -> ConsB) -> Self {
|
||||
Self {
|
||||
pool_builder: self.pool_builder,
|
||||
payload_builder: self.payload_builder,
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: f(self.consensus_builder),
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
{
|
||||
@ -120,7 +142,7 @@ where
|
||||
pub fn pool<PB>(
|
||||
self,
|
||||
pool_builder: PB,
|
||||
) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB>
|
||||
) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
PB: PoolBuilder<Node>,
|
||||
{
|
||||
@ -129,6 +151,7 @@ where
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -136,13 +159,14 @@ where
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<Node>,
|
||||
@ -154,7 +178,7 @@ where
|
||||
pub fn network<NB>(
|
||||
self,
|
||||
network_builder: NB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB, ConsB>
|
||||
where
|
||||
NB: NetworkBuilder<Node, PoolB::Pool>,
|
||||
{
|
||||
@ -163,6 +187,7 @@ where
|
||||
payload_builder,
|
||||
network_builder: _,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -170,6 +195,7 @@ where
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
@ -181,7 +207,7 @@ where
|
||||
pub fn payload<PB>(
|
||||
self,
|
||||
payload_builder: PB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
PB: PayloadServiceBuilder<Node, PoolB::Pool>,
|
||||
{
|
||||
@ -190,6 +216,7 @@ where
|
||||
payload_builder: _,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -197,6 +224,7 @@ where
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
@ -208,32 +236,69 @@ where
|
||||
pub fn executor<EB>(
|
||||
self,
|
||||
executor_builder: EB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB, ConsB>
|
||||
where
|
||||
EB: ExecutorBuilder<Node>,
|
||||
{
|
||||
let Self { pool_builder, payload_builder, network_builder, executor_builder: _, _marker } =
|
||||
self;
|
||||
let Self {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: _,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
|
||||
/// Configures the consensus builder.
|
||||
///
|
||||
/// This accepts a [`ConsensusBuilder`] instance that will be used to create the node's
|
||||
/// components for consensus.
|
||||
pub fn consensus<CB>(
|
||||
self,
|
||||
consensus_builder: CB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, CB>
|
||||
where
|
||||
CB: ConsensusBuilder<Node>,
|
||||
{
|
||||
let Self {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder: _,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<Node>,
|
||||
NetworkB: NetworkBuilder<Node, PoolB::Pool>,
|
||||
PayloadB: PayloadServiceBuilder<Node, PoolB::Pool>,
|
||||
ExecB: ExecutorBuilder<Node>,
|
||||
ConsB: ConsensusBuilder<Node>,
|
||||
{
|
||||
type Components = Components<Node, PoolB::Pool, ExecB::EVM, ExecB::Executor>;
|
||||
type Components = Components<Node, PoolB::Pool, ExecB::EVM, ExecB::Executor, ConsB::Consensus>;
|
||||
|
||||
async fn build_components(
|
||||
self,
|
||||
@ -244,6 +309,7 @@ where
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
|
||||
@ -251,18 +317,27 @@ where
|
||||
let pool = pool_builder.build_pool(context).await?;
|
||||
let network = network_builder.build_network(context, pool.clone()).await?;
|
||||
let payload_builder = payload_builder.spawn_payload_service(context, pool.clone()).await?;
|
||||
let consensus = consensus_builder.build_consensus(context).await?;
|
||||
|
||||
Ok(Components { transaction_pool: pool, evm_config, network, payload_builder, executor })
|
||||
Ok(Components {
|
||||
transaction_pool: pool,
|
||||
evm_config,
|
||||
network,
|
||||
payload_builder,
|
||||
executor,
|
||||
consensus,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ComponentsBuilder<(), (), (), (), ()> {
|
||||
impl Default for ComponentsBuilder<(), (), (), (), (), ()> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pool_builder: (),
|
||||
payload_builder: (),
|
||||
network_builder: (),
|
||||
executor_builder: (),
|
||||
consensus_builder: (),
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -288,16 +363,17 @@ pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
|
||||
) -> impl Future<Output = eyre::Result<Self::Components>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Pool, EVM, Executor> NodeComponentsBuilder<Node> for F
|
||||
impl<Node, F, Fut, Pool, EVM, Executor, Cons> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor>>> + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons>>> + Send,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
{
|
||||
type Components = Components<Node, Pool, EVM, Executor>;
|
||||
type Components = Components<Node, Pool, EVM, Executor, Cons>;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
|
||||
32
crates/node/builder/src/components/consensus.rs
Normal file
32
crates/node/builder/src/components/consensus.rs
Normal file
@ -0,0 +1,32 @@
|
||||
//! Consensus component for the node builder.
|
||||
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;
|
||||
|
||||
/// Creates the consensus implementation.
|
||||
fn build_consensus(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Consensus>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Consensus> ConsensusBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Consensus: reth_consensus::Consensus + Clone + Unpin + 'static,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Consensus>> + Send,
|
||||
{
|
||||
type Consensus = Consensus;
|
||||
|
||||
fn build_consensus(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Consensus>> {
|
||||
self(ctx)
|
||||
}
|
||||
}
|
||||
@ -9,16 +9,19 @@
|
||||
|
||||
use crate::{ConfigureEvm, FullNodeTypes};
|
||||
pub use builder::*;
|
||||
pub use consensus::*;
|
||||
pub use execute::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
pub use pool::*;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
mod builder;
|
||||
mod consensus;
|
||||
mod execute;
|
||||
mod network;
|
||||
mod payload;
|
||||
@ -39,6 +42,9 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
|
||||
/// The type that knows how to execute blocks.
|
||||
type Executor: BlockExecutorProvider;
|
||||
|
||||
/// The consensus type of the node.
|
||||
type Consensus: Consensus + Clone + Unpin + 'static;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -48,6 +54,9 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
|
||||
/// Returns the node's executor type.
|
||||
fn block_executor(&self) -> &Self::Executor;
|
||||
|
||||
/// Returns the node's consensus type.
|
||||
fn consensus(&self) -> &Self::Consensus;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &NetworkHandle;
|
||||
|
||||
@ -59,29 +68,34 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
|
||||
///
|
||||
/// This provides access to all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor> {
|
||||
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus> {
|
||||
/// The transaction pool of the node.
|
||||
pub transaction_pool: Pool,
|
||||
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
|
||||
pub evm_config: EVM,
|
||||
/// The node's executor type used to execute individual blocks and batches of blocks.
|
||||
pub executor: Executor,
|
||||
/// The consensus implementation of the node.
|
||||
pub consensus: Consensus,
|
||||
/// The network implementation of the node.
|
||||
pub network: NetworkHandle,
|
||||
/// The handle to the payload builder service.
|
||||
pub payload_builder: PayloadBuilderHandle<Node::Engine>,
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor> NodeComponents<Node> for Components<Node, Pool, EVM, Executor>
|
||||
impl<Node, Pool, EVM, Executor, Cons> NodeComponents<Node>
|
||||
for Components<Node, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
type Evm = EVM;
|
||||
type Executor = Executor;
|
||||
type Consensus = Cons;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.transaction_pool
|
||||
@ -95,6 +109,10 @@ where
|
||||
&self.executor
|
||||
}
|
||||
|
||||
fn consensus(&self) -> &Self::Consensus {
|
||||
&self.consensus
|
||||
}
|
||||
|
||||
fn network(&self) -> &NetworkHandle {
|
||||
&self.network
|
||||
}
|
||||
@ -104,18 +122,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor> Clone for Components<Node, Pool, EVM, Executor>
|
||||
impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
transaction_pool: self.transaction_pool.clone(),
|
||||
evm_config: self.evm_config.clone(),
|
||||
executor: self.executor.clone(),
|
||||
consensus: self.consensus.clone(),
|
||||
network: self.network.clone(),
|
||||
payload_builder: self.payload_builder.clone(),
|
||||
}
|
||||
|
||||
@ -8,10 +8,9 @@ use crate::{
|
||||
BuilderContext, NodeBuilderWithComponents, NodeHandle,
|
||||
};
|
||||
use futures::{future::Either, stream, stream_select, StreamExt};
|
||||
use reth_auto_seal_consensus::AutoSealConsensus;
|
||||
use reth_beacon_consensus::{
|
||||
hooks::{EngineHooks, PruneHook, StaticFileHook},
|
||||
BeaconConsensusEngine, EthBeaconConsensus,
|
||||
BeaconConsensusEngine,
|
||||
};
|
||||
use reth_blockchain_tree::{
|
||||
noop::NoopBlockchainTree, BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree,
|
||||
@ -29,6 +28,7 @@ use reth_node_core::{
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
||||
|
||||
use reth_primitives::format_ether;
|
||||
use reth_provider::providers::BlockchainProvider;
|
||||
use reth_rpc_engine_api::EngineApi;
|
||||
@ -130,13 +130,6 @@ where
|
||||
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
||||
});
|
||||
|
||||
// setup the consensus instance
|
||||
let consensus: Arc<dyn Consensus> = if ctx.is_dev() {
|
||||
Arc::new(AutoSealConsensus::new(ctx.chain_spec()))
|
||||
} else {
|
||||
Arc::new(EthBeaconConsensus::new(ctx.chain_spec()))
|
||||
};
|
||||
|
||||
debug!(target: "reth::cli", "Spawning stages metrics listener task");
|
||||
let (sync_metrics_tx, sync_metrics_rx) = unbounded_channel();
|
||||
let sync_metrics_listener = reth_stages::MetricsListener::new(sync_metrics_rx);
|
||||
@ -169,6 +162,8 @@ where
|
||||
debug!(target: "reth::cli", "creating components");
|
||||
let components = components_builder.build_components(&builder_ctx).await?;
|
||||
|
||||
let consensus: Arc<dyn Consensus> = Arc::new(components.consensus().clone());
|
||||
|
||||
let tree_externals = TreeExternals::new(
|
||||
ctx.provider_factory().clone(),
|
||||
consensus.clone(),
|
||||
@ -258,7 +253,7 @@ where
|
||||
ctx.node_config(),
|
||||
&ctx.toml_config().stages,
|
||||
client.clone(),
|
||||
Arc::clone(&consensus),
|
||||
consensus.clone(),
|
||||
ctx.provider_factory().clone(),
|
||||
ctx.task_executor(),
|
||||
sync_metrics_tx,
|
||||
@ -281,7 +276,7 @@ where
|
||||
ctx.node_config(),
|
||||
&ctx.toml_config().stages,
|
||||
network_client.clone(),
|
||||
Arc::clone(&consensus),
|
||||
consensus.clone(),
|
||||
ctx.provider_factory().clone(),
|
||||
ctx.task_executor(),
|
||||
sync_metrics_tx,
|
||||
|
||||
@ -29,6 +29,7 @@ reth-evm.workspace = true
|
||||
reth-revm.workspace = true
|
||||
reth-evm-optimism.workspace = true
|
||||
reth-beacon-consensus.workspace = true
|
||||
reth-optimism-consensus.workspace = true
|
||||
revm-primitives.workspace = true
|
||||
reth-discv5.workspace = true
|
||||
|
||||
|
||||
@ -11,11 +11,13 @@ use reth_evm_optimism::{OpExecutorProvider, OptimismEvmConfig};
|
||||
use reth_network::{NetworkHandle, NetworkManager};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ExecutorBuilder, NetworkBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
|
||||
PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes},
|
||||
BuilderContext, Node, PayloadBuilderConfig,
|
||||
};
|
||||
use reth_optimism_consensus::OptimismBeaconConsensus;
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_provider::CanonStateSubscriptions;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
@ -47,6 +49,7 @@ impl OptimismNode {
|
||||
OptimismPayloadBuilder,
|
||||
OptimismNetworkBuilder,
|
||||
OptimismExecutorBuilder,
|
||||
OptimismConsensusBuilder,
|
||||
>
|
||||
where
|
||||
Node: FullNodeTypes<Engine = OptimismEngineTypes>,
|
||||
@ -61,6 +64,7 @@ impl OptimismNode {
|
||||
))
|
||||
.network(OptimismNetworkBuilder { disable_txpool_gossip })
|
||||
.executor(OptimismExecutorBuilder::default())
|
||||
.consensus(OptimismConsensusBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +78,7 @@ where
|
||||
OptimismPayloadBuilder,
|
||||
OptimismNetworkBuilder,
|
||||
OptimismExecutorBuilder,
|
||||
OptimismConsensusBuilder,
|
||||
>;
|
||||
|
||||
fn components_builder(self) -> Self::ComponentsBuilder {
|
||||
@ -302,3 +307,19 @@ where
|
||||
Ok(handle)
|
||||
}
|
||||
}
|
||||
|
||||
/// A basic optimism consensus builder.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct OptimismConsensusBuilder;
|
||||
|
||||
impl<Node> ConsensusBuilder<Node> for OptimismConsensusBuilder
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
{
|
||||
type Consensus = OptimismBeaconConsensus;
|
||||
|
||||
async fn build_consensus(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> {
|
||||
Ok(OptimismBeaconConsensus::new(ctx.chain_spec()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ use reth_node_api::{
|
||||
};
|
||||
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
|
||||
use reth_node_ethereum::node::{
|
||||
EthereumExecutorBuilder, EthereumNetworkBuilder, EthereumPoolBuilder,
|
||||
EthereumConsensusBuilder, EthereumExecutorBuilder, EthereumNetworkBuilder, EthereumPoolBuilder,
|
||||
};
|
||||
use reth_payload_builder::{
|
||||
error::PayloadBuilderError, EthBuiltPayload, EthPayloadBuilderAttributes, PayloadBuilderHandle,
|
||||
@ -204,6 +204,7 @@ where
|
||||
CustomPayloadServiceBuilder,
|
||||
EthereumNetworkBuilder,
|
||||
EthereumExecutorBuilder,
|
||||
EthereumConsensusBuilder,
|
||||
>;
|
||||
|
||||
fn components_builder(self) -> Self::ComponentsBuilder {
|
||||
@ -213,6 +214,7 @@ where
|
||||
.payload(CustomPayloadServiceBuilder::default())
|
||||
.network(EthereumNetworkBuilder::default())
|
||||
.executor(EthereumExecutorBuilder::default())
|
||||
.consensus(EthereumConsensusBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user