Skip to content

Commit

Permalink
feat: expose Op node network_config helper (#11506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 5, 2024
1 parent 51db656 commit 41455df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
8 changes: 8 additions & 0 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ impl<C> NetworkConfig<C> {
NetworkConfig::builder(secret_key).build(client)
}

/// Apply a function to the config.
pub fn apply<F>(self, f: F) -> Self
where
F: FnOnce(Self) -> Self,
{
f(self)
}

/// Sets the config to use for the discovery v4 protocol.
pub fn set_discovery_v4(mut self, discovery_config: Discv4Config) -> Self {
self.discovery_v4_config = Some(discovery_config);
Expand Down
41 changes: 28 additions & 13 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
use std::sync::Arc;

use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_chainspec::{EthChainSpec, Hardforks};
use reth_evm::ConfigureEvm;
use reth_network::{NetworkHandle, NetworkManager};
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager};
use reth_node_api::{EngineValidator, FullNodeComponents, NodeAddOns};
use reth_node_builder::{
components::{
Expand Down Expand Up @@ -330,18 +331,18 @@ pub struct OptimismNetworkBuilder {
pub disable_discovery_v4: bool,
}

impl<Node, Pool> NetworkBuilder<Node, Pool> for OptimismNetworkBuilder
where
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = OpChainSpec>>,
Pool: TransactionPool + Unpin + 'static,
{
async fn build_network(
self,
impl OptimismNetworkBuilder {
/// Returns the [`NetworkConfig`] that contains the settings to launch the p2p network.
///
/// This applies the configured [`OptimismNetworkBuilder`] settings.
pub fn network_config<Node>(
&self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<NetworkHandle> {
let Self { disable_txpool_gossip, disable_discovery_v4 } = self;

) -> eyre::Result<NetworkConfig<<Node as FullNodeTypes>::Provider>>
where
Node: FullNodeTypes<Types: NodeTypes<ChainSpec: Hardforks>>,
{
let Self { disable_txpool_gossip, disable_discovery_v4 } = self.clone();
let args = &ctx.config().network;
let network_builder = ctx
.network_config_builder()?
Expand Down Expand Up @@ -374,8 +375,22 @@ where
// gossip to prevent other parties in the network from learning about them.
network_config.tx_gossip_disabled = disable_txpool_gossip;

let network = NetworkManager::builder(network_config).await?;
Ok(network_config)
}
}

impl<Node, Pool> NetworkBuilder<Node, Pool> for OptimismNetworkBuilder
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.network_config(ctx)?;
let network = NetworkManager::builder(network_config).await?;
let handle = ctx.start_network(network, pool);

Ok(handle)
Expand Down

0 comments on commit 41455df

Please sign in to comment.