Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use OptimismBeaconConsensus in the OptimismNode #8487

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/ethereum/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,4 +41,3 @@ futures.workspace = true
tokio.workspace = true
futures-util.workspace = true
serde_json.workspace = true

30 changes: 29 additions & 1 deletion crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)]
Expand All @@ -32,6 +36,7 @@ impl EthereumNode {
EthereumPayloadBuilder,
EthereumNetworkBuilder,
EthereumExecutorBuilder,
EthereumConsensusBuilder,
>
where
Node: FullNodeTypes<Engine = EthEngineTypes>,
Expand All @@ -42,6 +47,7 @@ impl EthereumNode {
.payload(EthereumPayloadBuilder::default())
.network(EthereumNetworkBuilder::default())
.executor(EthereumExecutorBuilder::default())
.consensus(EthereumConsensusBuilder::default())
}
}

Expand All @@ -60,6 +66,7 @@ where
EthereumPayloadBuilder,
EthereumNetworkBuilder,
EthereumExecutorBuilder,
EthereumConsensusBuilder,
>;

fn components_builder(self) -> Self::ComponentsBuilder {
Expand Down Expand Up @@ -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())))
}
}
}
1 change: 1 addition & 0 deletions crates/exex/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
32 changes: 30 additions & 2 deletions crates/exex/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
Expand Down Expand Up @@ -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]
Expand All @@ -103,6 +121,7 @@ where
EthereumPayloadBuilder,
EthereumNetworkBuilder,
TestExecutorBuilder,
TestConsensusBuilder,
>;

fn components_builder(self) -> Self::ComponentsBuilder {
Expand All @@ -112,6 +131,7 @@ where
.payload(EthereumPayloadBuilder::default())
.network(EthereumNetworkBuilder::default())
.executor(TestExecutorBuilder::default())
.consensus(TestConsensusBuilder::default())
}
}

Expand Down Expand Up @@ -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())?;
Expand All @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/node/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ tokio = { workspace = true, features = [
] }
tokio-stream.workspace = true

# ethereum
## ethereum
discv5.workspace = true

# crypto
## crypto
secp256k1 = { workspace = true, features = [
"global-context",
"rand-std",
Expand Down
5 changes: 5 additions & 0 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,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()
Expand Down
Loading
Loading