From 53c8567833a098c55c9ddcc5cdb61a572d813156 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Wed, 31 Jul 2024 22:26:20 +0800 Subject: [PATCH 1/3] feat: Add OP cli flag to opt-in into discv4 discovery --- book/run/optimism.md | 1 + crates/optimism/node/src/args.rs | 4 ++++ crates/optimism/node/src/node.rs | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/book/run/optimism.md b/book/run/optimism.md index 2ae5cabbbfb0..9eab6e16d009 100644 --- a/book/run/optimism.md +++ b/book/run/optimism.md @@ -62,6 +62,7 @@ The `optimism` feature flag in `op-reth` adds several new CLI flags to the `reth 1. `--rollup.sequencer-http ` - 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 diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index 8a3dddc810a4..ec03b8fb2e59 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -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)] diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 5932381452b7..9c5ebe6badff 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -59,7 +59,7 @@ impl OptimismNode { where Node: FullNodeTypes, { - let RollupArgs { disable_txpool_gossip, compute_pending_block, .. } = args; + let RollupArgs { disable_txpool_gossip, compute_pending_block, discovery_v4, .. } = args; ComponentsBuilder::default() .node_types::() .pool(OptimismPoolBuilder::default()) @@ -67,7 +67,10 @@ impl OptimismNode { 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()) } @@ -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 NetworkBuilder for OptimismNetworkBuilder @@ -286,12 +291,15 @@ where ctx: &BuilderContext, pool: Pool, ) -> eyre::Result { - 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()? + let mut network_config_builder = ctx.network_config_builder()?; + if disable_discovery_v4 { + network_config_builder = network_config_builder.disable_discv4_discovery(); + } + let network_builder = network_config_builder // apply discovery settings .apply(|mut builder| { let rlpx_socket = (args.addr, args.port).into(); From 7d2c342f439fe6e8b8763220ee0026db896fe46f Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Wed, 31 Jul 2024 23:09:41 +0800 Subject: [PATCH 2/3] Update crates/optimism/node/src/node.rs Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- crates/optimism/node/src/node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 9c5ebe6badff..6a229409fb3c 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -296,7 +296,7 @@ where let args = &ctx.config().network; let mut network_config_builder = ctx.network_config_builder()?; - if disable_discovery_v4 { + if disable_discovery_v4 || args.discovery.disable_discovery { network_config_builder = network_config_builder.disable_discv4_discovery(); } let network_builder = network_config_builder From 175a06b917b9271f1d705aed3b00afe440fcdcbd Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Thu, 1 Aug 2024 10:34:50 +0800 Subject: [PATCH 3/3] fix style --- crates/optimism/node/src/node.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 6a229409fb3c..9fc1f9b85a03 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -294,16 +294,14 @@ where let Self { disable_txpool_gossip, disable_discovery_v4 } = self; let args = &ctx.config().network; - - let mut network_config_builder = ctx.network_config_builder()?; - if disable_discovery_v4 || args.discovery.disable_discovery { - network_config_builder = network_config_builder.disable_discv4_discovery(); - } - let network_builder = network_config_builder + 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(