peers: fix config edit and load, default mainnet dnsseed

This commit is contained in:
ardocrat 2024-08-13 02:31:38 +03:00
parent 09cfb84b94
commit 68bd2b81ec
4 changed files with 41 additions and 15 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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<Server, Error> {
// 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;

View file

@ -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();