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

P2P Network Implementation - NetworkBuilder #61

Open
Tracked by #92
frisitano opened this issue Dec 4, 2024 · 0 comments
Open
Tracked by #92

P2P Network Implementation - NetworkBuilder #61

frisitano opened this issue Dec 4, 2024 · 0 comments
Milestone

Comments

@frisitano
Copy link
Collaborator

frisitano commented Dec 4, 2024

Overview

We must implement a P2P network such that data can be gossiped with network participants. This includes transactions, blocks, header etc.

Considerations

  • When considering the design of the rollup node, as described in Rollup Node #49, we need to determine if it the responsibility of the rollup node or the execution node to propagate blocks on the network.
  • Should transactions be gossiped to all network participants or should they be sent directly to the centralized sequencer? If transactions are sent directly to the sequencer it may prevent MEV attacks yielding superior UX.

Optimism Example implementation

/// A basic optimism network builder.
#[derive(Debug, Default, Clone)]
pub struct OpNetworkBuilder {
/// Disable transaction pool gossip
pub disable_txpool_gossip: bool,
/// Disable discovery v4
pub disable_discovery_v4: bool,
}
impl OpNetworkBuilder {
/// Returns the [`NetworkConfig`] that contains the settings to launch the p2p network.
///
/// This applies the configured [`OpNetworkBuilder`] settings.
pub fn network_config<Node>(
&self,
ctx: &BuilderContext<Node>,
) -> 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()?
// apply discovery settings
.apply(|mut builder| {
let rlpx_socket = (args.addr, args.port).into();
if disable_discovery_v4 || args.discovery.disable_discovery {
builder = builder.disable_discv4_discovery();
}
if !args.discovery.disable_discovery {
builder = builder.discovery_v5(
args.discovery.discovery_v5_builder(
rlpx_socket,
ctx.config()
.network
.resolved_bootnodes()
.or_else(|| ctx.chain_spec().bootnodes())
.unwrap_or_default(),
),
);
}
builder
});
let mut network_config = ctx.build_network_config(network_builder);
// When `sequencer_endpoint` is configured, the node will forward all transactions to a
// Sequencer node for execution and inclusion on L1, and disable its own txpool
// gossip to prevent other parties in the network from learning about them.
network_config.tx_gossip_disabled = disable_txpool_gossip;
Ok(network_config)
}
}
impl<Node, Pool> NetworkBuilder<Node, Pool> for OpNetworkBuilder
where
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives>>,
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);
info!(target: "reth::cli", enode=%handle.local_node_record(), "P2P networking initialized");
Ok(handle)
}
}

@frisitano frisitano added this to the Milestone 3 milestone Dec 4, 2024
@frisitano frisitano added this to Reth Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant