mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
refactor: extract trusted peer resolve into separate function (#8660)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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<T> LaunchContextWith<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl LaunchContextWith<WithConfigs> {
|
||||
/// Resolves the trusted peers and adds them to the toml config.
|
||||
pub async fn with_resolved_peers(mut self) -> eyre::Result<Self> {
|
||||
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<L, R> LaunchContextWith<Attached<L, R>> {
|
||||
/// Get a reference to the left value.
|
||||
pub const fn left(&self) -> &L {
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user