Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: resolve trusted peers #9301

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bin/reth/src/commands/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ impl Command {

let mut config: Config = confy::load_path(&config_path).unwrap_or_default();

for peer in &self.network.trusted_peers {
config.peers.trusted_nodes.insert(peer.resolve().await?);
}
config.peers.trusted_nodes.extend(self.network.resolve_trusted_peers().await?);

if config.peers.trusted_nodes.is_empty() && self.network.trusted_only {
eyre::bail!("No trusted nodes. Set trusted peer with `--trusted-peer <enode record>` or set `--trusted-only` to `false`")
Expand Down
7 changes: 1 addition & 6 deletions bin/reth/src/commands/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ impl Command {

let mut config = config;
config.peers.trusted_nodes_only = self.network.trusted_only;
if !self.network.trusted_peers.is_empty() {
for peer in &self.network.trusted_peers {
let peer = peer.resolve().await?;
config.peers.trusted_nodes.insert(peer);
}
}
config.peers.trusted_nodes.extend(self.network.resolve_trusted_peers().await?);

let network_secret_path = self
.network
Expand Down
8 changes: 8 additions & 0 deletions crates/node/core/src/args/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ impl NetworkArgs {
self.port += instance - 1;
self.discovery.adjust_instance_ports(instance);
}

/// Resolve all trusted peers at once
pub async fn resolve_trusted_peers(&self) -> Result<Vec<NodeRecord>, std::io::Error> {
futures::future::try_join_all(
self.trusted_peers.iter().map(|peer| async move { peer.resolve().await }),
)
.await
}
}

impl Default for NetworkArgs {
Expand Down
Loading