Skip to content

Commit

Permalink
feat: Add OP cli flag to opt-in into discv4 discovery (#9938)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Cline <[email protected]>
  • Loading branch information
nkysg and Rjected authored Aug 1, 2024
1 parent 41d5c07 commit 321032f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions book/run/optimism.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The `optimism` feature flag in `op-reth` adds several new CLI flags to the `reth
1. `--rollup.sequencer-http <uri>` - The sequencer endpoint to connect to. Transactions sent to the `op-reth` EL are also forwarded to this sequencer endpoint for inclusion, as the sequencer is the entity that builds blocks on OP Stack chains.
1. `--rollup.disable-tx-pool-gossip` - Disables gossiping of transactions in the mempool to peers. This can be omitted for personal nodes, though providers should always opt to enable this flag.
1. `--rollup.enable-genesis-walkback` - Disables setting the forkchoice status to tip on startup, making the `op-node` walk back to genesis and verify the integrity of the chain before starting to sync. This can be omitted unless a corruption of local chainstate is suspected.
1. `--rollup.discovery.v4` - Enables the discovery v4 protocol for peer discovery.

First, ensure that your L1 archival node is running and synced to tip. Also make sure that the beacon node / consensus layer client is running and has http APIs enabled. Then, start `op-reth` with the `--rollup.sequencer-http` flag set to the `Base Mainnet` sequencer endpoint:
```sh
Expand Down
4 changes: 4 additions & 0 deletions crates/optimism/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct RollupArgs {
/// that this flag is not yet functional.
#[arg(long = "rollup.compute-pending-block")]
pub compute_pending_block: bool,

/// enables discovery v4 if provided
#[arg(long = "rollup.discovery.v4", default_value = "false")]
pub discovery_v4: bool,
}

#[cfg(test)]
Expand Down
16 changes: 11 additions & 5 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ impl OptimismNode {
where
Node: FullNodeTypes<Engine = OptimismEngineTypes>,
{
let RollupArgs { disable_txpool_gossip, compute_pending_block, .. } = args;
let RollupArgs { disable_txpool_gossip, compute_pending_block, discovery_v4, .. } = args;
ComponentsBuilder::default()
.node_types::<Node>()
.pool(OptimismPoolBuilder::default())
.payload(OptimismPayloadBuilder::new(
compute_pending_block,
OptimismEvmConfig::default(),
))
.network(OptimismNetworkBuilder { disable_txpool_gossip })
.network(OptimismNetworkBuilder {
disable_txpool_gossip,
disable_discovery_v4: !discovery_v4,
})
.executor(OptimismExecutorBuilder::default())
.consensus(OptimismConsensusBuilder::default())
}
Expand Down Expand Up @@ -274,6 +277,8 @@ where
pub struct OptimismNetworkBuilder {
/// Disable transaction pool gossip
pub disable_txpool_gossip: bool,
/// Disable discovery v4
pub disable_discovery_v4: bool,
}

impl<Node, Pool> NetworkBuilder<Node, Pool> for OptimismNetworkBuilder
Expand All @@ -286,16 +291,17 @@ where
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<NetworkHandle> {
let Self { disable_txpool_gossip } = self;
let Self { disable_txpool_gossip, disable_discovery_v4 } = self;

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(
Expand Down

0 comments on commit 321032f

Please sign in to comment.