Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

chore: introdcue network builder #146

Merged
merged 2 commits into from
Oct 9, 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "8ba7bc0",
reth-storage-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "8ba7bc0" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "8ba7bc0" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "8ba7bc0" }
reth-network = { git = "https://github.com/paradigmxyz/reth.git", rev = "8ba7bc0" }

# rpc
jsonrpsee = "0.24"
Expand Down
1 change: 1 addition & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ reth-payload-builder.workspace = true
reth-primitives.workspace = true
reth-revm.workspace = true
reth-transaction-pool.workspace = true
reth-network.workspace = true

alloy-primitives.workspace = true

Expand Down
43 changes: 38 additions & 5 deletions crates/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//! required for the optimism engine API.

use crate::evm::AlphaNetEvmConfig;
use reth_network::{NetworkHandle, NetworkManager};
use reth_node_api::{FullNodeTypes, NodeTypesWithEngine};
use reth_node_builder::{
components::{
ComponentsBuilder, ExecutorBuilder, PayloadServiceBuilder, PoolBuilderConfigOverrides,
ComponentsBuilder, ExecutorBuilder, NetworkBuilder, PayloadServiceBuilder,
PoolBuilderConfigOverrides,
},
BuilderContext, Node, NodeTypes,
};
Expand Down Expand Up @@ -43,7 +45,7 @@ impl AlphaNetNode {
Node,
OptimismPoolBuilder,
AlphaNetPayloadBuilder,
OptimismNetworkBuilder,
AlphanetNetworkBuilder,
AlphaNetExecutorBuilder,
OptimismConsensusBuilder,
OptimismEngineValidatorBuilder,
Expand All @@ -66,10 +68,10 @@ impl AlphaNetNode {
},
})
.payload(AlphaNetPayloadBuilder::new(compute_pending_block))
.network(OptimismNetworkBuilder {
.network(AlphanetNetworkBuilder::new(OptimismNetworkBuilder {
disable_txpool_gossip,
disable_discovery_v4: !discovery_v4,
})
}))
.executor(AlphaNetExecutorBuilder::default())
.consensus(OptimismConsensusBuilder::default())
.engine_validator(OptimismEngineValidatorBuilder::default())
Expand All @@ -96,7 +98,7 @@ where
N,
OptimismPoolBuilder,
AlphaNetPayloadBuilder,
OptimismNetworkBuilder,
AlphanetNetworkBuilder,
AlphaNetExecutorBuilder,
OptimismConsensusBuilder,
OptimismEngineValidatorBuilder,
Expand Down Expand Up @@ -170,3 +172,34 @@ where
self.inner.spawn(AlphaNetEvmConfig::new(ctx.chain_spec().clone()), ctx, pool)
}
}

/// The default alphanet network builder.
#[derive(Debug, Default, Clone)]
pub struct AlphanetNetworkBuilder {
inner: OptimismNetworkBuilder,
}

impl AlphanetNetworkBuilder {
/// Create a new instance based on the given op builder
pub const fn new(network: OptimismNetworkBuilder) -> Self {
Self { inner: network }
}
}

impl<Node, Pool> NetworkBuilder<Node, Pool> for AlphanetNetworkBuilder
where
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = OpChainSpec>>,
Pool: TransactionPool + Unpin + 'static,
{
async fn build_network(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<NetworkHandle> {
let network_config = self.inner.network_config(ctx)?;
let network = NetworkManager::builder(network_config).await?;
let handle = ctx.start_network(network, pool);

Ok(handle)
}
}