From 880759ac57232ce23414914392726ca0912cac77 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Wed, 15 Mar 2023 06:49:15 +0530 Subject: [PATCH] Add p2p listener port options for reth node (#1753) Co-authored-by: Georgios Konstantopoulos --- bin/reth/src/args/network_args.rs | 4 ++++ bin/reth/src/node/mod.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/reth/src/args/network_args.rs b/bin/reth/src/args/network_args.rs index a0af02ef98..ff99f419ca 100644 --- a/bin/reth/src/args/network_args.rs +++ b/bin/reth/src/args/network_args.rs @@ -91,6 +91,10 @@ pub struct DiscoveryArgs { /// Disable Discv4 discovery. #[arg(long, conflicts_with = "disable_discovery")] disable_discv4_discovery: bool, + + /// The UDP port to use for P2P discovery/networking. + #[arg(long = "discovery.port")] + pub port: Option, } impl DiscoveryArgs { diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 6c8a325a98..bb99109720 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -20,6 +20,7 @@ use reth_db::{ tables, transaction::DbTx, }; +use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, @@ -52,7 +53,11 @@ use reth_stages::{ stages::{ExecutionStage, SenderRecoveryStage, TotalDifficultyStage, FINISH}, }; use reth_tasks::TaskExecutor; -use std::{net::SocketAddr, path::PathBuf, sync::Arc}; +use std::{ + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, + path::PathBuf, + sync::Arc, +}; use tokio::sync::{mpsc::unbounded_channel, watch}; use tracing::*; @@ -417,6 +422,10 @@ impl Command { .network_config(config, self.chain.clone()) .with_task_executor(Box::new(executor)) .set_head(head) + .listener_addr(SocketAddr::V4(SocketAddrV4::new( + Ipv4Addr::UNSPECIFIED, + self.network.discovery.port.unwrap_or(DEFAULT_DISCOVERY_PORT), + ))) .build(ShareableDatabase::new(db, self.chain.clone())) }