debt(discv5): discv5 integration into network (#8065)

This commit is contained in:
Emilia Hane
2024-05-03 14:38:26 +02:00
committed by GitHub
parent 90f3161256
commit f20e4cbad8
7 changed files with 28 additions and 42 deletions

View File

@ -94,16 +94,6 @@ pub const DEFAULT_DISCOVERY_ADDR: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
/// Note: the default TCP port is the same.
pub const DEFAULT_DISCOVERY_PORT: u16 = 30303;
/// The default address for discv5 via UDP.
///
/// Note: the default TCP address is the same.
pub const DEFAULT_DISCOVERY_V5_ADDR: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
/// The default port for discv5 via UDP.
///
/// Default is port 9000.
pub const DEFAULT_DISCOVERY_V5_PORT: u16 = 9000;
/// The default address for discv4 via UDP: "0.0.0.0:30303"
///
/// Note: The default TCP address is the same.

View File

@ -3,7 +3,7 @@
use std::{
collections::HashSet,
fmt::Debug,
net::{IpAddr, SocketAddr},
net::{IpAddr, Ipv4Addr, SocketAddr},
};
use derive_more::Display;
@ -13,6 +13,16 @@ use reth_primitives::{Bytes, EnrForkIdEntry, ForkId, NodeRecord};
use crate::{enr::discv4_id_to_multiaddr_id, filter::MustNotIncludeKeys, NetworkStackId};
/// The default address for discv5 via UDP.
///
/// Default is 0.0.0.0, all interfaces. See [`discv5::ListenConfig`] default.
pub const DEFAULT_DISCOVERY_V5_ADDR: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
/// The default port for discv5 via UDP.
///
/// Default is port 9000. See [`discv5::ListenConfig`] default.
pub const DEFAULT_DISCOVERY_V5_PORT: u16 = 9000;
/// Default interval in seconds at which to run a lookup up query.
///
/// Default is 60 seconds.

View File

@ -38,8 +38,9 @@ pub mod network_stack_id;
pub use discv5::{self, IpMode};
pub use config::{
BootNode, Config, ConfigBuilder, DEFAULT_COUNT_BOOTSTRAP_LOOKUPS,
DEFAULT_SECONDS_BOOTSTRAP_LOOKUP_INTERVAL, DEFAULT_SECONDS_LOOKUP_INTERVAL,
BootNode, Config, ConfigBuilder, DEFAULT_COUNT_BOOTSTRAP_LOOKUPS, DEFAULT_DISCOVERY_V5_ADDR,
DEFAULT_DISCOVERY_V5_PORT, DEFAULT_SECONDS_BOOTSTRAP_LOOKUP_INTERVAL,
DEFAULT_SECONDS_LOOKUP_INTERVAL,
};
pub use enr::enr_to_discv4_id;
pub use error::Error;

View File

@ -176,8 +176,6 @@ pub struct NetworkConfigBuilder {
dns_discovery_config: Option<DnsDiscoveryConfig>,
/// How to set up discovery version 4.
discovery_v4_builder: Option<Discv4ConfigBuilder>,
/// Whether to enable discovery version 5. Disabled by default.
enable_discovery_v5: bool,
/// All boot nodes to start network discovery with.
boot_nodes: HashSet<NodeRecord>,
/// Address to use for discovery
@ -220,7 +218,6 @@ impl NetworkConfigBuilder {
secret_key,
dns_discovery_config: Some(Default::default()),
discovery_v4_builder: Some(Default::default()),
enable_discovery_v5: false,
boot_nodes: Default::default(),
discovery_addr: None,
listener_addr: None,
@ -353,12 +350,6 @@ impl NetworkConfigBuilder {
self
}
/// Allows discv5 discovery.
pub fn discovery_v5(mut self) -> Self {
self.enable_discovery_v5 = true;
self
}
/// Sets the dns discovery config to use.
pub fn dns_discovery(mut self, config: DnsDiscoveryConfig) -> Self {
self.dns_discovery_config = Some(config);
@ -407,12 +398,6 @@ impl NetworkConfigBuilder {
self
}
/// Enable the Discv5 discovery.
pub fn enable_discv5_discovery(mut self) -> Self {
self.enable_discovery_v5 = true;
self
}
/// Disable the DNS discovery if the given condition is true.
pub fn disable_dns_discovery_if(self, disable: bool) -> Self {
if disable {
@ -469,7 +454,6 @@ impl NetworkConfigBuilder {
secret_key,
mut dns_discovery_config,
discovery_v4_builder,
enable_discovery_v5: _,
boot_nodes,
discovery_addr,
listener_addr,

View File

@ -3,13 +3,10 @@
use crate::version::P2P_CLIENT_VERSION;
use clap::Args;
use reth_config::Config;
use reth_discv4::{
DEFAULT_DISCOVERY_ADDR, DEFAULT_DISCOVERY_PORT, DEFAULT_DISCOVERY_V5_ADDR,
DEFAULT_DISCOVERY_V5_PORT,
};
use reth_discv4::{DEFAULT_DISCOVERY_ADDR, DEFAULT_DISCOVERY_PORT};
use reth_discv5::{
DEFAULT_COUNT_BOOTSTRAP_LOOKUPS, DEFAULT_SECONDS_BOOTSTRAP_LOOKUP_INTERVAL,
DEFAULT_SECONDS_LOOKUP_INTERVAL,
DEFAULT_COUNT_BOOTSTRAP_LOOKUPS, DEFAULT_DISCOVERY_V5_ADDR, DEFAULT_DISCOVERY_V5_PORT,
DEFAULT_SECONDS_BOOTSTRAP_LOOKUP_INTERVAL, DEFAULT_SECONDS_LOOKUP_INTERVAL,
};
use reth_net_nat::NatResolver;
use reth_network::{
@ -272,11 +269,6 @@ impl DiscoveryArgs {
network_config_builder = network_config_builder.disable_discv4_discovery();
}
if !self.disable_discovery && (self.enable_discv5_discovery || cfg!(feature = "optimism")) {
network_config_builder = network_config_builder.disable_discv4_discovery();
network_config_builder = network_config_builder.enable_discv5_discovery();
}
network_config_builder
}

View File

@ -462,6 +462,7 @@ impl NodeConfig {
// set discovery port based on instance number
self.network.port + self.instance - 1,
))
.disable_discv4_discovery_if(self.chain.chain.is_optimism())
.discovery_addr(SocketAddr::new(
self.network.discovery.addr,
// set discovery port based on instance number
@ -470,9 +471,13 @@ impl NodeConfig {
let config = cfg_builder.build(client);
if !self.network.discovery.enable_discv5_discovery {
if self.network.discovery.disable_discovery ||
!self.network.discovery.enable_discv5_discovery &&
!config.chain_spec.chain.is_optimism()
{
return config
}
// work around since discv5 config builder can't be integrated into network config builder
// due to unsatisfied trait bounds
config.discovery_v5_with_config_builder(|builder| {