From 68bd2b81ec04bbab6b8448635641b3433bda4184 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Tue, 13 Aug 2024 02:31:38 +0300 Subject: [PATCH] peers: fix config edit and load, default mainnet dnsseed --- src/gui/views/network/setup/p2p.rs | 4 +++- src/node/config.rs | 11 ++++------ src/node/node.rs | 35 ++++++++++++++++++++++++++++-- src/settings/config.rs | 6 +---- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/gui/views/network/setup/p2p.rs b/src/gui/views/network/setup/p2p.rs index 06bd3e6..0c31f8c 100644 --- a/src/gui/views/network/setup/p2p.rs +++ b/src/gui/views/network/setup/p2p.rs @@ -91,7 +91,7 @@ impl Default for P2PSetup { fn default() -> Self { let port = NodeConfig::get_p2p_port(); let is_port_available = NodeConfig::is_p2p_port_available(&port); - let default_main_seeds = grin_servers::MAINNET_DNS_SEEDS + let default_main_seeds = Node::MAINNET_DNS_SEEDS .iter() .map(|s| s.to_string()) .collect(); @@ -370,6 +370,8 @@ impl P2PSetup { ui.label(RichText::new(desc) .size(16.0) .color(Colors::inactive_text())); + } + if !peers.is_empty() { ui.add_space(12.0); } diff --git a/src/node/config.rs b/src/node/config.rs index b329dfa..71a3af3 100644 --- a/src/node/config.rs +++ b/src/node/config.rs @@ -49,8 +49,6 @@ impl PeersConfig { let chain_type = AppConfig::chain_type(); let config_path = Settings::config_path(Self::FILE_NAME, Some(chain_type.shortname())); Settings::write_to_file(self, config_path); - // Load changes to node server config. - Self::load_to_server_config(); } /// Convert string to [`PeerAddr`] if address is in correct format (`host:port`) and available. @@ -71,7 +69,7 @@ impl PeersConfig { } /// Load saved peers to node server [`ConfigMembers`] config. - pub(crate) fn load_to_server_config() { + pub fn load_to_server_config() { let mut w_config = Settings::node_config_to_update(); // Load seeds. for seed in w_config.peers.seeds.clone() { @@ -683,10 +681,9 @@ impl NodeConfig { /// Toggle seeding type to use default or custom seed list. pub fn toggle_seeding_type() { - let seeding_type = if Self::is_default_seeding_type() { - Seeding::List - } else { - Seeding::DNSSeed + let seeding_type = match Self::is_default_seeding_type() { + true => Seeding::List, + false => Seeding::DNSSeed }; let mut w_config = Settings::node_config_to_update(); w_config.node.server.p2p_config.seeding_type = seeding_type; diff --git a/src/node/node.rs b/src/node/node.rs index 48f10b2..6f36003 100644 --- a/src/node/node.rs +++ b/src/node/node.rs @@ -24,10 +24,12 @@ use futures::channel::oneshot; use grin_chain::SyncStatus; use grin_core::global; use grin_core::global::ChainTypes; +use grin_p2p::msg::PeerAddrs; +use grin_p2p::Seeding; use grin_servers::{Server, ServerStats, StratumServerConfig, StratumStats}; use grin_servers::common::types::Error; -use crate::node::{NodeConfig, NodeError}; +use crate::node::{NodeConfig, NodeError, PeersConfig}; use crate::node::stratum::{StratumStopState, StratumServer}; lazy_static! { @@ -83,6 +85,16 @@ impl Node { /// Delay for thread to update the stats. pub const STATS_UPDATE_DELAY: Duration = Duration::from_millis(1000); + /// Default Mainnet DNS Seeds + pub const MAINNET_DNS_SEEDS: &'static[&'static str] = &[ + "mainnet.seed.grin.lesceller.com", + "grinseed.revcore.net", + "mainnet-seed.grinnode.live", + "mainnet.grin.punksec.de", + "grinnode.30-r.com", + "grincoin.org" + ]; + /// Stop the [`Server`] and setup exit flag after if needed. pub fn stop(exit_after_stop: bool) { NODE_STATE.stop_needed.store(true, Ordering::Relaxed); @@ -516,10 +528,29 @@ impl Node { /// Start the node [`Server`]. fn start_node_server() -> Result { - // Get saved server config. + // Setup server config. + PeersConfig::load_to_server_config(); let config = NodeConfig::node_server_config(); let mut server_config = config.server.clone(); + // Setup Mainnet DNSSeed + if server_config.chain_type == ChainTypes::Mainnet && NodeConfig::is_default_seeding_type() { + server_config.p2p_config.seeding_type = Seeding::List; + server_config.p2p_config.seeds = Some(PeerAddrs::default()); + for seed in Node::MAINNET_DNS_SEEDS { + let addr = format!("{}:3414", seed); + if let Some(p) = PeersConfig::peer_to_addr(addr) { + let mut seeds = server_config + .p2p_config + .seeds + .clone() + .unwrap_or(PeerAddrs::default()); + seeds.peers.insert(seeds.peers.len(), p); + server_config.p2p_config.seeds = Some(seeds); + } + } + } + // Fix to avoid too many opened files. server_config.p2p_config.peer_min_preferred_outbound_count = server_config.p2p_config.peer_max_outbound_count; diff --git a/src/settings/config.rs b/src/settings/config.rs index 445fc23..e764ab3 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -16,7 +16,7 @@ use grin_core::global::ChainTypes; use serde_derive::{Deserialize, Serialize}; use crate::gui::views::Content; -use crate::node::{NodeConfig, PeersConfig}; +use crate::node::NodeConfig; use crate::Settings; use crate::wallet::ConnectionsConfig; @@ -113,10 +113,6 @@ impl AppConfig { w_node_config.node = node_config.node; w_node_config.peers = node_config.peers; } - // Load saved peers to node config. - { - PeersConfig::load_to_server_config(); - } // Load connections configuration { let mut w_conn_config = Settings::conn_config_to_update();