From bbfb81bbda8a03f46246b119d754937db2642507 Mon Sep 17 00:00:00 2001 From: caglarkaya Date: Fri, 7 Jun 2024 14:04:08 +0300 Subject: [PATCH] refactor: extract trusted peer resolve into separate function (#8660) Co-authored-by: Matthias Seitz --- crates/node/builder/src/launch/common.rs | 35 ++++++++++++++---------- crates/node/builder/src/launch/mod.rs | 2 ++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index c58b1b6f12..abc632db9c 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -82,20 +82,6 @@ impl LaunchContext { // Update the config with the command line arguments toml_config.peers.trusted_nodes_only = config.network.trusted_only; - if !config.network.trusted_peers.is_empty() { - info!(target: "reth::cli", "Adding trusted nodes"); - - // 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) } @@ -202,6 +188,27 @@ impl LaunchContextWith { } } +impl LaunchContextWith { + /// Resolves the trusted peers and adds them to the toml config. + pub async fn with_resolved_peers(mut self) -> eyre::Result { + if !self.attachment.config.network.trusted_peers.is_empty() { + info!(target: "reth::cli", "Adding trusted nodes"); + + // resolve trusted peers if they use a domain instead of dns + for peer in &self.attachment.config.network.trusted_peers { + let backoff = ConstantBuilder::default() + .with_max_times(self.attachment.config.network.dns_retries); + let resolved = (move || { peer.resolve() }) + .retry(&backoff) + .notify(|err, _| warn!(target: "reth::cli", "Error resolving peer domain: {err}. Retrying...")) + .await?; + self.attachment.toml_config.peers.trusted_nodes.insert(resolved); + } + } + Ok(self) + } +} + impl LaunchContextWith> { /// Get a reference to the left value. pub const fn left(&self) -> &L { diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index a383f52c69..bba021cefd 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -96,6 +96,8 @@ where .with_configured_globals() // load the toml config .with_loaded_toml_config(config).await? + // add resolved peers + .with_resolved_peers().await? // attach the database .attach(database.clone()) // ensure certain settings take effect