From dea518a0aa879f6716ad28e00c341f938b2a6495 Mon Sep 17 00:00:00 2001 From: Bo QIU <35757521+boqiu@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:14:20 +0800 Subject: [PATCH] Supports discv5 related configurations (#84) * Supports discv5 related configurations * fix fmt --- node/src/config/convert.rs | 8 +++++++- node/src/config/mod.rs | 7 +++++++ run/config.toml | 26 ++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/node/src/config/convert.rs b/node/src/config/convert.rs index 78c6698..0f13113 100644 --- a/node/src/config/convert.rs +++ b/node/src/config/convert.rs @@ -46,8 +46,14 @@ impl ZgsConfig { .map_err(|e| format!("Unable to parse network_libp2p_nodes: {:?}", e))?; network_config.discv5_config.table_filter = |_| true; + network_config.discv5_config.request_timeout = + Duration::from_secs(self.discv5_request_timeout_secs); + network_config.discv5_config.query_peer_timeout = + Duration::from_secs(self.discv5_query_peer_timeout_secs); + network_config.discv5_config.request_retries = self.discv5_request_retries; + network_config.discv5_config.query_parallelism = self.discv5_query_parallelism; + network_config.discv5_config.report_discovered_peers = self.discv5_report_discovered_peers; - // TODO network_config.target_peers = self.network_target_peers; network_config.private = self.network_private; diff --git a/node/src/config/mod.rs b/node/src/config/mod.rs index c4d467c..38a5cb7 100644 --- a/node/src/config/mod.rs +++ b/node/src/config/mod.rs @@ -20,6 +20,13 @@ build_config! { (network_private, (bool), false) (network_disable_discovery, (bool), false) + // discv5 + (discv5_request_timeout_secs, (u64), 5) + (discv5_query_peer_timeout_secs, (u64), 2) + (discv5_request_retries, (u8), 1) + (discv5_query_parallelism, (usize), 5) + (discv5_report_discovered_peers, (bool), false) + // log sync (blockchain_rpc_endpoint, (String), "http://127.0.0.1:8545".to_string()) (log_contract_address, (String), "".to_string()) diff --git a/run/config.toml b/run/config.toml index cbe90e3..1bf4ad3 100644 --- a/run/config.toml +++ b/run/config.toml @@ -12,7 +12,8 @@ # network_listen_address = "0.0.0.0" # The address to broadcast to peers about which address we are listening on. Empty indicates -# that no discovery address has been set. +# that no discovery address has been set. Generally, configure public IP address along with +# `network_enr_tcp_port` and `network_enr_udp_port` with default values to enable UDP discovery. # network_enr_address = "" # The tcp port to broadcast to peers in order to reach back for libp2p services. @@ -30,7 +31,8 @@ # Target number of connected peers. # network_target_peers = 50 -# List of nodes to initially connect to +# List of nodes to bootstrap UDP discovery. Note, `network_enr_address`, `network_enr_tcp_port` +# and `network_enr_udp_port` should be configured as well to enable UDP discovery. network_boot_nodes = ["/ip4/54.219.26.22/udp/1234/p2p/16Uiu2HAmPxGNWu9eVAQPJww79J32pTJLKGcpjRMb4Qb8xxKkyuG1","/ip4/52.52.127.117/udp/1234/p2p/16Uiu2HAm93Hd5azfhkGBbkx1zero3nYHvfjQYM2NtiW4R3r5bE2g"] # List of libp2p nodes to initially connect to. @@ -43,6 +45,26 @@ network_boot_nodes = ["/ip4/54.219.26.22/udp/1234/p2p/16Uiu2HAmPxGNWu9eVAQPJww79 # Disables the discovery protocol from starting. # network_disable_discovery = false +####################################################################### +### UDP Discovery Config Options ### +####################################################################### +# The request timeout for each UDP request. +# discv5_request_timeout_secs = 5 + +# The timeout after which a `QueryPeer` in an ongoing query is marked unresponsive. +# Unresponsive peers don't count towards the parallelism limits for a query. +# Hence, we may potentially end up making more requests to good peers. +# discv5_query_peer_timeout_secs = 2 + +# The number of retries for each UDP request. +# discv5_request_retries = 1 + +# The number of peers to request in parallel in a single query. +# discv5_query_parallelism = 5 + +# Reports all discovered ENR's when traversing the DHT to the event stream. +# discv5_report_discovered_peers = false + ####################################################################### ### Log Sync Config Options ### #######################################################################