mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: resolve domains in enode strings (#8188)
Co-authored-by: Serge Radinovich <47865535+sergerad@users.noreply.github.com>
This commit is contained in:
@ -58,6 +58,7 @@ eyre.workspace = true
|
||||
fdlimit.workspace = true
|
||||
confy.workspace = true
|
||||
rayon.workspace = true
|
||||
backon.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
//! Helper types that can be used by launchers.
|
||||
|
||||
use backon::{ConstantBuilder, Retryable};
|
||||
use eyre::Context;
|
||||
use rayon::ThreadPoolBuilder;
|
||||
use reth_auto_seal_consensus::MiningMode;
|
||||
@ -56,17 +57,19 @@ impl LaunchContext {
|
||||
/// `config`.
|
||||
///
|
||||
/// Attaches both the `NodeConfig` and the loaded `reth.toml` config to the launch context.
|
||||
pub fn with_loaded_toml_config(
|
||||
pub async fn with_loaded_toml_config(
|
||||
self,
|
||||
config: NodeConfig,
|
||||
) -> eyre::Result<LaunchContextWith<WithConfigs>> {
|
||||
let toml_config = self.load_toml_config(&config)?;
|
||||
let toml_config = self.load_toml_config(&config).await?;
|
||||
Ok(self.with(WithConfigs { config, toml_config }))
|
||||
}
|
||||
|
||||
/// Loads the reth config with the configured `data_dir` and overrides settings according to the
|
||||
/// `config`.
|
||||
pub fn load_toml_config(&self, config: &NodeConfig) -> eyre::Result<reth_config::Config> {
|
||||
///
|
||||
/// This is async because the trusted peers may have to be resolved.
|
||||
pub async fn load_toml_config(&self, config: &NodeConfig) -> eyre::Result<reth_config::Config> {
|
||||
let config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config());
|
||||
|
||||
let mut toml_config = confy::load_path::<reth_config::Config>(&config_path)
|
||||
@ -81,9 +84,16 @@ impl LaunchContext {
|
||||
|
||||
if !config.network.trusted_peers.is_empty() {
|
||||
info!(target: "reth::cli", "Adding trusted nodes");
|
||||
config.network.trusted_peers.iter().for_each(|peer| {
|
||||
toml_config.peers.trusted_nodes.insert(*peer);
|
||||
});
|
||||
|
||||
// resolve trusted peers if they use a domain instead of dns
|
||||
for peer in &config.network.trusted_peers {
|
||||
let backoff = ConstantBuilder::default().with_max_times(config.network.dns_retries);
|
||||
let resolved = (move || { peer.resolve() })
|
||||
.retry(&backoff)
|
||||
.notify(|err, _| warn!(target: "reth::cli", "Error resolving peer domain: {err}. Retrying..."))
|
||||
.await?;
|
||||
toml_config.peers.trusted_nodes.insert(resolved);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(toml_config)
|
||||
|
||||
@ -94,7 +94,7 @@ where
|
||||
let ctx = ctx
|
||||
.with_configured_globals()
|
||||
// load the toml config
|
||||
.with_loaded_toml_config(config)?
|
||||
.with_loaded_toml_config(config).await?
|
||||
// attach the database
|
||||
.attach(database.clone())
|
||||
// ensure certain settings take effect
|
||||
|
||||
Reference in New Issue
Block a user